Location>code7788 >text

LLM Application: Give a company abbreviation, output the full company name.

Popularity:509 ℃/2024-11-18 18:25:09
from duckduckgo_search import DDGS import json import time PROMPT = """You are an assistant and your task is to analyze and extract the full company name corresponding to the company name abbreviation based on the entered company name abbreviation and the search results. The requirements are as follows: 1. "Abbreviation" is the abbreviation of the company name, and "search result" is the resource after searching based on the Internet. You need to analyze and output the full name of the company based on "Abbreviation" and "Search Result", and if you can't confirm it, please return "None"; 2. If the search results do not contain the full name of the company, please make further judgment based on your knowledge. 3. the output only contains the full name of the company name information, and can only contain one, do not need to output the explanation of information; 4. the input company name abbreviation are all the same, please return "no" if you can not confirm. 4. The short names of the input companies are all well-known companies in the field of science and technology, please pay attention to this point; Example: Abbreviation: Jingdong Search results: 1. jingdong (China's self-owned e-commerce company founded in 1998)_Baidu Encyclopedia\n Jingdong (stock code: jd), China's self-owned e-commerce company, founder Liu Qiangdong initially served as the chairman of the board of directors and chief executive officer of the Jingdong Group, and in September 2021 Xu Lei was appointed as the group's president. Jingdong has Jingdong Mall, Jingdong Finance, PaiPai, Jingdong Intelligence, o2o and overseas business units, etc. On June 18, 1998, Liu Qiangdong founded Jingdong Company in Zhongguancun, China. 2. jingdong group - wikipedia, the free encyclopedia \n east group. Jingdong Group (NASDAQ: JD, SEHK: 9618, HKEx: 89618 (RMB settlement)), formerly known as 360buy and Jingdong Mall, was founded by Liu Qiangdong on June 18, 1998, and is a Chinese e-commerce company headquartered in Beijing that focuses on B2C model shopping websites .... In 2014, Jingdong Group was listed on the NASDAQ stock exchange ... 3. jingdong group corporation - AiEncha\n Introduction: Jingdong Group Corporation (, Inc.) was incorporated in the British Virgin Islands on November 6, 2006 as a company operating through subsidiaries and VIEs in China, and is headquartered in Beijing. ... Jingdong is a professional and comprehensive online shopping mall, the largest 3C online shopping professional platform in China's B2C market, and the most ... Output: Jingdong Group Co. Now, please complete as required: Abbreviation: {company_name} Search results: {search_results} Output: {company_name} """ def save_datas(file_path, datas, json_flag=True, all_flag=False, with_indent=False, mode='w'): """Save text file""" with open(file_path, mode, encoding='utf-8') as f: if all_flag: if json_flag: ((datas, ensure_ascii=False, indent= 4 if with_indent else None)) else: (''.join(datas)) else: for data in datas: if json_flag: ((data, ensure_ascii=False) + '\n') else: (data + '\n') def get_datas(file_path, json_flag=True, all_flag=False, mode='r'): """Reading text files""" results = [] with open(file_path, mode, encoding='utf-8') as f: for line in (): if json_flag: ((line)) else: (()) if all_flag: if json_flag: return (''.join(results)) else: return '\n'.join(results) return results def get_company_full_names(): results = [] for ele in get_datas('data/company-abbreviation-results.json'): company_name = ele['company'] search_results = ele['search_results'] if isinstance(search_results, str): (f'{company_name}\t{company_name}') continue prompt = (company_name=company_name, search_results=search_results) result = '' while result == '': try: result = DDGS().chat(prompt, model='gpt-4o-mini') if (): break except Exception as e: (2) continue (f'{company_name}\t{result}') save_datas('data/company-full-name-extraction-results.txt', results, json_flag=False) if __name__ == '__main__': get_company_full_names()