{"id":5121,"date":"2024-06-22T13:25:05","date_gmt":"2024-06-22T05:25:05","guid":{"rendered":"http:\/\/xinblog.ltd\/?p=5121"},"modified":"2024-06-24T20:38:56","modified_gmt":"2024-06-24T12:38:56","slug":"18-%e9%83%a8%e7%bd%b2%e4%b8%80%e4%b8%aa%e9%b2%9c%e8%8a%b1%e7%bd%91%e7%bb%9c%e7%94%b5%e5%95%86%e7%9a%84%e4%ba%ba%e8%84%89%e5%b7%a5%e5%85%b7","status":"publish","type":"post","link":"http:\/\/xinblog.ltd\/?p=5121","title":{"rendered":"18.\u90e8\u7f72\u4e00\u4e2a\u9c9c\u82b1\u7f51\u7edc\u7535\u5546\u7684\u4eba\u8109\u5de5\u5177"},"content":{"rendered":"<p>\u90e8\u7f72\u4e00\u4e2a\u9c9c\u82b1\u7f51\u7edc\u7535\u5546\u7684\u4eba\u8109\u5de5\u5177<\/p>\n<p>\u6211\u4eec\u6765\u505a\u4e00\u4e2a\u5c0f\u7a0b\u5e8f\uff0c\u8fd9\u4e2a\u5c0f\u7a0b\u5e8f\u9700\u8981\u628aLangChain\u4e2d\u5404\u4e2a\u7ec4\u4ef6\u7075\u6d3b\u7684\u7ec4\u5408\u8d77\u6765\uff0c\u878d\u4f1a\u8d2f\u901a\u3002\u5176\u9700\u6c42\u4e3a\uff0c\u5e0c\u671b\u5229\u7528\u5fae\u535a\u6216\u5c0f\u7ea2\u4e66\u7b49\u5e73\u53f0\u7684\u7f51\u7ea2\uff0c\u660e\u661f\u4f5c\u4e3a\u63a8\u624b\uff0c\u4ece\u800c\u63a8\u5e7f\u9c9c\u82b1\u3002<\/p>\n<p>\u90a3\u4e48\u8fd9\u5c31\u9700\u8981\u6211\u4eec\u80fd\u591f\u6839\u636e\u60f3\u8981\u63a8\u8350\u7684\u9c9c\u82b1\uff0c\u4ece\u800c\u627e\u5230\u5408\u9002\u7684\u660e\u661f\u6216\u8005\u7f51\u7ea2\uff0c\u5e76\u7ed9\u51fa\u4e00\u4e2a\u8054\u7edc\u65b9\u6848\u3002<\/p>\n<p>\u5177\u4f53\u7684\u6280\u672f\u65b9\u6848\u4e3a<\/p>\n<ol>\n<li>\u6839\u636e\u9c9c\u82b1\u79cd\u7c7b\u641c\u7d22\u5fae\u535a\u627e\u5230\u5408\u9002\u7684\u5927V<\/li>\n<li>\u6839\u636e\u5927V\u7684UID\uff0c\u83b7\u53d6\u5230\u5927V\u7684\u4fe1\u606f\uff0c\u4ee5JSON\u7684\u65b9\u5f0f\u8fd4\u56de\u5927V\u6570\u636e<\/li>\n<li>\u901a\u8fc7\u5927V\u7684JSON\u6570\u636e\uff0c\u901a\u8fc7LLM\u751f\u6210\u4e00\u4e2a\u6587\u6848\uff0c\u8981\u6c42\u6587\u6848\u7b26\u5408\u5927V\u7684\u98ce\u683c<\/li>\n<li>\u5229\u7528Flask\u521b\u5efa\u4e00\u4e2aAPP\uff0c\u90e8\u7f72\u5728\u670d\u52a1\u5668\u4f9b\u8425\u9500\u4eba\u5458\u4f7f\u7528\u3002<\/li>\n<\/ol>\n<p>\u90a3\u4e48\u6211\u4eec\u4e00\u6b65\u6b65\u7684\u6765\uff1a<\/p>\n<p>\u7b2c\u4e00\u6b65\uff0c\u627e\u5230\u5927V<\/p>\n<p>\u8fd9\u91cc\u6211\u4eec\u51c6\u5907\u4e00\u4e2apython\u6587\u4ef6\u8fdb\u884c\u641c\u7d22\uff0c\u8fd9\u91cc\u9762\u6211\u4eec\u5b9a\u4e49\u4e00\u4e2a\u65b9\u6cd5<\/p>\n<p>lookup_V(flower_type:str)<\/p>\n<p>\u6839\u636e\u4e00\u4e2a\u82b1\u7684\u7c7b\u578b\u6765\u83b7\u53d6\u5230\u5927V\u7684UID<\/p>\n<p>\u5176\u9700\u8981\u7528\u5230\u6211\u4eec\u4e4b\u524d\u8bf4\u7684ReAct\u6846\u67b6<\/p>\n<table>\n<tbody>\n<tr>\n<td># \u901a\u8fc7LangChain\u4ee3\u7406\u627e\u5230UID\u7684\u51fd\u6570<\/p>\n<p>def lookup_V(flower_type: str) :<\/p>\n<p># \u521d\u59cb\u5316\u5927\u6a21\u578b<\/p>\n<p>llm = ChatOpenAI(temperature=0, model_name=&#8221;gpt-3.5-turbo&#8221;)<\/p>\n<p># \u5bfb\u627eUID\u7684\u6a21\u677f<\/p>\n<p>template = &#8220;&#8221;&#8221;given the {flower} I want you to get a related \u5fae\u535a UID.<\/p>\n<p>Your answer should contain only a UID.<\/p>\n<p>The URL always starts with https:\/\/weibo.com\/u\/<\/p>\n<p>for example, if https:\/\/weibo.com\/u\/1669879400 is her \u5fae\u535a, then 1669879400 is her UID<\/p>\n<p>This is only the example don&#8217;t give me this, but the actual UID&#8221;&#8221;&#8221;<\/p>\n<p># \u5b8c\u6574\u7684\u63d0\u793a\u6a21\u677f<\/p>\n<p>prompt_template = PromptTemplate(<\/p>\n<p>input_variables=[&#8220;flower&#8221;], template=template<\/p>\n<p>)<\/p>\n<p># \u4ee3\u7406\u7684\u5de5\u5177<\/p>\n<p>tools = [<\/p>\n<p>Tool(<\/p>\n<p>name=&#8221;Crawl Google for \u5fae\u535a page&#8221;,<\/p>\n<p>func=get_UID,<\/p>\n<p>description=&#8221;useful for when you need get the \u5fae\u535a UID&#8221;,<\/p>\n<p>)<\/p>\n<p>]<\/p>\n<p># \u521d\u59cb\u5316\u4ee3\u7406<\/p>\n<p>agent = initialize_agent(<\/p>\n<p>tools,<\/p>\n<p>llm,<\/p>\n<p>agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,<\/p>\n<p>verbose=True<\/p>\n<p>)<\/p>\n<p># \u8fd4\u56de\u627e\u5230\u7684UID<\/p>\n<p>ID = agent.run(prompt_template.format_prompt(flower=flower_type))<\/p>\n<p>return ID<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u8fd9\u91cc\u9762\u7684\u91cd\u70b9\u5728\u4e8e\u6211\u4eec\u5728Tools\u4e2d\u4f7f\u7528\u5230\u7684get_UID<\/p>\n<p>get_UID\u662f\u6211\u4eec\u4e13\u95e8\u9488\u5bf9\u641c\u7d22\u5fae\u535a\u4e66\u5199\u7684\u4e00\u4e2a\u5de5\u5177\u51fd\u6570<\/p>\n<p>def get_UID(flower: str):<\/p>\n<p># search = SerpAPIWrapper()<\/p>\n<p>search = CustomSerpAPIWrapper()<\/p>\n<p>res = search.run(f&#8221;{flower}&#8221;)<\/p>\n<p>return res<\/p>\n<p>\u5728\u5176\u4e2d\u6211\u4eec\u58f0\u660e\u4e86\u4e00\u4e2aWrapper\uff0c\u662f\u5229\u7528\u7684\u539f\u672c\u7684SerpAPIWrapper\u8fdb\u884c\u5c01\u88c5\u7684\u3002<\/p>\n<p>\u8fd9\u4e2a\u5c01\u88c5\u7684\u539f\u56e0\u4e3b\u8981\u662f\u56e0\u4e3a\u6211\u4eec\u5728\u641c\u7d22\u5fae\u535a\u7684\u8fc7\u7a0b\u4e2d\uff0c\u5f97\u5230\u7684\u7ed3\u679c\u5f80\u5f80\u662fSnippet\uff0c\u4e5f\u5c31\u662f\u6458\u8981\uff0c\u800c\u6211\u4eec\u66f4\u9700\u8981\u4e86\u89e3\u5230\u7684\u662fURL\uff0c\u901a\u8fc7URL\u4e2d\u89e3\u6790UID<\/p>\n<p>\u6240\u4ee5\u8fdb\u884c\u4e86\u5ba2\u5236\u5316\u5904\u7406<\/p>\n<table>\n<tbody>\n<tr>\n<td>if &#8220;snippet&#8221; in first_organic_result.keys():<\/p>\n<p># snippets.append(first_organic_result[&#8220;snippet&#8221;])<\/p>\n<p>snippets.append(first_organic_result[&#8220;link&#8221;])<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u6545\u6b64\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u83b7\u53d6URL\u6765\u83b7\u53d6\u5230\u5927V\u7684UID\u4e86<\/p>\n<p><a href=\"https:\/\/static001.geekbang.org\/resource\/image\/ab\/6f\/ab67de9be2b4f26be53c0e8af713f16f.jpg?wh=819x326&quot; \\o &quot;\u6210\u529f\u5f97\u5230\u4e86\u5927 V \u7684 UID\"><img decoding=\"async\" loading=\"lazy\" width=\"819\" height=\"326\" class=\"wp-image-5122\" src=\"http:\/\/xinblog.ltd\/wp-content\/uploads\/2024\/04\/word-image.jpeg\" srcset=\"http:\/\/xinblog.ltd\/wp-content\/uploads\/2024\/04\/word-image.jpeg 819w, http:\/\/xinblog.ltd\/wp-content\/uploads\/2024\/04\/word-image-300x119.jpeg 300w, http:\/\/xinblog.ltd\/wp-content\/uploads\/2024\/04\/word-image-768x306.jpeg 768w\" sizes=\"(max-width: 819px) 100vw, 819px\" \/><\/a><\/p>\n<p><a href=\"https:\/\/static001.geekbang.org\/resource\/image\/ab\/6f\/ab67de9be2b4f26be53c0e8af713f16f.jpg?wh=819x326&quot; \\o &quot;\u6210\u529f\u5f97\u5230\u4e86\u5927 V \u7684 UID\">\u6210\u529f\u5f97\u5230\u4e86\u5927 V \u7684 UID<\/a><\/p>\n<p>\u4e4b\u540e\u5c31\u662f\u6839\u636eUID\u83b7\u53d6\u5230\u8fd9\u4e2a\u5927V\u7684\u76f8\u5173\u8d44\u6599\u4e86<\/p>\n<table>\n<tbody>\n<tr>\n<td># \u6839\u636eUID\u722c\u53d6\u5927V\u4fe1\u606f<\/p>\n<p>person_info = get_data(UID)<\/p>\n<p>print(person_info)<\/p>\n<p># \u79fb\u9664\u65e0\u7528\u7684\u4fe1\u606f<\/p>\n<p>remove_non_chinese_fields(person_info)<\/p>\n<p>print(person_info)<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u9996\u5148\u662f\u83b7\u53d6\u5230\u76f8\u5173\u6570\u636e\uff0c\u4e4b\u540e\u518d\u662f\u79fb\u9664\u989d\u5916\u7684\u4fe1\u606f<\/p>\n<p>\u8fd9\u4e24\u4e2a\u51fd\u6570\u90fd\u548cLLM\u6ca1\u6709\u5173\u7cfb\uff0c\u5c31\u662f\u7b80\u5355\u7684\u722c\u866b+python\u51fd\u6570<\/p>\n<p>\u5173\u4e8eget_data<\/p>\n<table>\n<tbody>\n<tr>\n<td>def get_data(id):<\/p>\n<p>url = &#8220;https:\/\/weibo.com\/ajax\/profile\/detail?uid={}&#8221;.format(id)<\/p>\n<p>headers = {<\/p>\n<p>&#8220;User-Agent&#8221;: &#8220;Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/89.0.4389.82 Safari\/537.36&#8221;,<\/p>\n<p>&#8220;Referer&#8221;: &#8220;https:\/\/weibo.com&#8221;<\/p>\n<p>}<\/p>\n<p>cookies = {<\/p>\n<p>&#8220;cookie&#8221;: &#8221;&#8217;your cookie&#8221;&#8217;<\/p>\n<p>}<\/p>\n<p>html = requests.get(url, headers=headers, cookies=cookies)<\/p>\n<p>time.sleep(3) # \u52a0\u4e0a3s \u7684\u5ef6\u65f6\u9632\u6b62\u88ab\u53cd\u722c<\/p>\n<p>response = json.loads(html.text)<\/p>\n<p>return response<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u672c\u8d28\u4e0a\u5c31\u662f\u83b7\u53d6response\u5e76\u8fdb\u884c\u8fd4\u56de<\/p>\n<p>\u7136\u540e\u662fremove_non_chinese_fields\uff0c\u79fb\u9664\u975e\u4e2d\u6587\u7684\u5b57\u6bb5<\/p>\n<table>\n<tbody>\n<tr>\n<td>def remove_non_chinese_fields(d):<\/p>\n<p>if isinstance(d, dict):<\/p>\n<p>to_remove = [key for key, value in d.items() if isinstance(value, (str, int, float, bool)) and (not contains_chinese(str(value)))]<\/p>\n<p>for key in to_remove:<\/p>\n<p>del d[key]<\/p>\n<p>for key, value in d.items():<\/p>\n<p>if isinstance(value, (dict, list)):<\/p>\n<p>remove_non_chinese_fields(value)<\/p>\n<p>elif isinstance(d, list):<\/p>\n<p>to_remove_indices = []<\/p>\n<p>for i, item in enumerate(d):<\/p>\n<p>if isinstance(item, (str, int, float, bool)) and (not contains_chinese(str(item))):<\/p>\n<p>to_remove_indices.append(i)<\/p>\n<p>else:<\/p>\n<p>remove_non_chinese_fields(item)<\/p>\n<p>for index in reversed(to_remove_indices):<\/p>\n<p>d.pop(index)<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u6839\u636e\u662f\u5426\u4e3a\u4e2d\u6587\u8fdb\u884c\u79fb\u9664<\/p>\n<p>\u8fd9\u6837\u5c31\u83b7\u53d6\u5230\u4e86\u8be6\u7ec6\u7684\u4fe1\u606f\u3002<\/p>\n<p>\u63a5\u4e0b\u6765\u6211\u4eec\u7ee7\u7eed<\/p>\n<p>\u5c06\u8fd9\u4e2a\u83b7\u53d6\u5230\u7684\u4fe1\u606f\uff0c\u4f20\u9012\u7ed9LLM\uff0c\u751f\u6210\u4ecb\u7ecd\u6587\u7ae0<\/p>\n<p>\u5e76\u4e14\u5229\u7528Output Parser\u8f93\u51fa\u7279\u5b9a\u683c\u5f0f\u7684\u6587\u6863<\/p>\n<p>\u5c06\u4fe1\u606f\u4f20\u9012\u7ed9LLM\u7684\u540c\u65f6\uff0c\u6211\u4eec\u8fd8\u9700\u8981\u8bbe\u8ba1\u597d\u4e00\u4e2a\u6a21\u677f<\/p>\n<p>\u8fd9\u91cc\u6211\u4eec\u5148\u660e\u786e\u9700\u8981\u8fd4\u56de\u7684\u683c\u5f0f<\/p>\n<p>\u4e5f\u5c31\u662f\u5b9a\u4e49\u4e00\u4e2aOutputParser<\/p>\n<table>\n<tbody>\n<tr>\n<td>class TextParsing(BaseModel):<\/p>\n<p>summary: str = Field(description=&#8221;\u5927V\u4e2a\u4eba\u7b80\u4ecb&#8221;) # \u5927V\u7684\u7b80\u4ecb\u6216\u80cc\u666f\u4fe1\u606f<\/p>\n<p>facts: List[str] = Field(description=&#8221;\u5927V\u7684\u7279\u70b9&#8221;) # \u5927V\u7684\u4e00\u4e9b\u663e\u8457\u7279\u70b9\u6216\u8005\u4e8b\u5b9e<\/p>\n<p>interest: List[str] = Field(description=&#8221;\u8fd9\u4e2a\u5927V\u53ef\u80fd\u611f\u5174\u8da3\u7684\u4e8b\u60c5&#8221;) # \u5927V\u53ef\u80fd\u611f\u5174\u8da3\u7684\u4e3b\u9898\u6216\u6d3b\u52a8<\/p>\n<p>letter: List[str] = Field(description=&#8221;\u4e00\u7bc7\u8054\u7edc\u8fd9\u4e2a\u5927V\u7684\u90ae\u4ef6&#8221;) # \u8054\u7edc\u5927V\u7684\u5efa\u8bae\u90ae\u4ef6\u5185\u5bb9<\/p>\n<p># \u5c06\u6a21\u578b\u5bf9\u8c61\u8f6c\u6362\u4e3a\u5b57\u5178<\/p>\n<p>def to_dict(self):<\/p>\n<p>return {<\/p>\n<p>&#8220;summary&#8221;: self.summary,<\/p>\n<p>&#8220;facts&#8221;: self.facts,<\/p>\n<p>&#8220;interest&#8221;: self.interest,<\/p>\n<p>&#8220;letter&#8221;: self.letter,<\/p>\n<p>}<\/p>\n<p># \u521b\u5efa\u4e00\u4e2a\u57fa\u4e8ePydantic\u6a21\u578b\u7684\u89e3\u6790\u5668\uff0c\u7528\u4e8e\u5c06\u6587\u672c\u8f93\u51fa\u89e3\u6790\u4e3a\u7279\u5b9a\u7684\u7ed3\u6784<\/p>\n<p>letter_parser: PydanticOutputParser = PydanticOutputParser(<\/p>\n<p>pydantic_object=TextParsing<\/p>\n<p>)<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u8fd9\u91cc\u6211\u4eec\u5b9a\u4e49\u4e86\u4e00\u4e2a\u6a21\u5f0f\uff0c\u5176\u5305\u542b\u56db\u4e2a\u5b57\u6bb5\uff0c\u5206\u522b\u662fsummary\u7b80\u4ecb\uff0cfacts \u7279\u70b9<\/p>\n<p>Interest \u5174\u8da3\u70b9 letter \u8054\u7edc\u90ae\u4ef6<\/p>\n<p>\u4e4b\u540e\u6211\u4eec\u5229\u7528\u8fd9\u4e2aoutput parser\u6307\u5b9a\u5927\u6a21\u578b\u7684\u8f93\u51fa<\/p>\n<table>\n<tbody>\n<tr>\n<td># \u751f\u6210\u6587\u6848\u7684\u51fd\u6570<\/p>\n<p>def generate_letter(information):<\/p>\n<p># \u8bbe\u8ba1\u63d0\u793a\u6a21\u677f<\/p>\n<p>letter_template = &#8220;&#8221;&#8221;<\/p>\n<p>\u4e0b\u9762\u662f\u8fd9\u4e2a\u4eba\u7684\u5fae\u535a\u4fe1\u606f {information}<\/p>\n<p>\u8bf7\u4f60\u5e2e\u6211:<\/p>\n<p>1. \u5199\u4e00\u4e2a\u7b80\u5355\u7684\u603b\u7ed3<\/p>\n<p>2. \u6311\u4e24\u4ef6\u6709\u8da3\u7684\u7279\u70b9\u8bf4\u4e00\u8bf4<\/p>\n<p>3. \u627e\u4e00\u4e9b\u4ed6\u6bd4\u8f83\u611f\u5174\u8da3\u7684\u4e8b\u60c5<\/p>\n<p>4. \u5199\u4e00\u7bc7\u70ed\u60c5\u6d0b\u6ea2\u7684\u4ecb\u7ecd\u4fe1<\/p>\n<p>\\n{format_instructions}&#8221;&#8221;&#8221;<\/p>\n<p>prompt_template = PromptTemplate(<\/p>\n<p>input_variables=[&#8220;information&#8221;],<\/p>\n<p>template=letter_template,<\/p>\n<p>partial_variables={<\/p>\n<p>&#8220;format_instructions&#8221;: letter_parser.get_format_instructions()<\/p>\n<p>},<\/p>\n<p>)<\/p>\n<p># \u521d\u59cb\u5316\u5927\u6a21\u578b<\/p>\n<p>llm = ChatOpenAI(model_name=&#8221;gpt-3.5-turbo&#8221;)<\/p>\n<p># \u521d\u59cb\u5316\u94fe<\/p>\n<p>chain = LLMChain(llm=llm, prompt=prompt_template)<\/p>\n<p># \u751f\u6210\u6587\u6848<\/p>\n<p>result = chain.run(information = information)<\/p>\n<p>return result<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0c\u521d\u59cb\u5316\u5927\u6a21\u578b\uff0c\u8fdb\u884c\u6587\u6848\u7684\u751f\u6210\u3002<\/p>\n<p>\u8fd9\u6837\uff0c\u6211\u4eec\u5f97\u5230\u4e86\u4e00\u4e2a\u5305\u542b\u4e0a\u9762\u6307\u5b9a\u7684\u683c\u5f0f\u7684json\u6587\u6863\u3002<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" width=\"1270\" height=\"228\" class=\"wp-image-5123\" src=\"http:\/\/xinblog.ltd\/wp-content\/uploads\/2024\/04\/word-image-1.jpeg\" srcset=\"http:\/\/xinblog.ltd\/wp-content\/uploads\/2024\/04\/word-image-1.jpeg 1270w, http:\/\/xinblog.ltd\/wp-content\/uploads\/2024\/04\/word-image-1-300x54.jpeg 300w, http:\/\/xinblog.ltd\/wp-content\/uploads\/2024\/04\/word-image-1-1024x184.jpeg 1024w, http:\/\/xinblog.ltd\/wp-content\/uploads\/2024\/04\/word-image-1-768x138.jpeg 768w\" sizes=\"(max-width: 1270px) 100vw, 1270px\" \/><\/p>\n<p>\u6700\u540e\u6211\u4eec\u8981\u5b9e\u73b0\u7b2c\u4e94\u6b65\uff0c\u5c06\u8fd9\u4e2a\u5de5\u5177\u90e8\u7f72\u5230\u670d\u52a1\u5668\u4e0a\uff0c\u63d0\u4f9b\u5bf9\u5916\u8bbf\u95ee\u7684\u63a5\u53e3<\/p>\n<p>\u8fd9\u91cc\u6211\u4eec\u4f7f\u7528flask app\u6765\u5b9e\u73b0<\/p>\n<p>\u9996\u5148\u6211\u4eec\u521b\u5efa\u4e00\u4e2aHTML\u6587\u4ef6<\/p>\n<p>\u5e76init \u4e00\u4e2a app<\/p>\n<table>\n<tbody>\n<tr>\n<td># \u5b9e\u4f8b\u5316Flask\u5e94\u7528<\/p>\n<p>app = Flask(__name__)<\/p>\n<p># \u4e3b\u9875\u8def\u7531\uff0c\u8fd4\u56deindex.html\u6a21\u677f<\/p>\n<p>@app.route(&#8220;\/&#8221;)<\/p>\n<p>def index():<\/p>\n<p>return render_template(&#8220;index.html&#8221;)<\/p>\n<p># \u5904\u7406\u8bf7\u6c42\u7684\u8def\u7531\uff0c\u4ec5\u5141\u8bb8POST\u8bf7\u6c42<\/p>\n<p>@app.route(&#8220;\/process&#8221;, methods=[&#8220;POST&#8221;])<\/p>\n<p>def process():<\/p>\n<p># \u83b7\u53d6\u63d0\u4ea4\u7684\u82b1\u7684\u540d\u79f0<\/p>\n<p>flower = request.form[&#8220;flower&#8221;]<\/p>\n<p># \u4f7f\u7528find_bigV\u51fd\u6570\u83b7\u53d6\u76f8\u5173\u6570\u636e<\/p>\n<p>response_str = find_bigV(flower=flower)<\/p>\n<p># \u4f7f\u7528json.loads\u5c06\u5b57\u7b26\u4e32\u89e3\u6790\u4e3a\u5b57\u5178<\/p>\n<p>response = json.loads(response_str)<\/p>\n<p># \u8fd4\u56de\u6570\u636e\u7684json\u54cd\u5e94<\/p>\n<p>return jsonify(<\/p>\n<p>{<\/p>\n<p>&#8220;summary&#8221;: response[&#8220;summary&#8221;],<\/p>\n<p>&#8220;facts&#8221;: response[&#8220;facts&#8221;],<\/p>\n<p>&#8220;interest&#8221;: response[&#8220;interest&#8221;],<\/p>\n<p>&#8220;letter&#8221;: response[&#8220;letter&#8221;],<\/p>\n<p>}<\/p>\n<p>)<\/p>\n<p># \u5224\u65ad\u662f\u5426\u662f\u4e3b\u7a0b\u5e8f\u8fd0\u884c\uff0c\u5e76\u8bbe\u7f6eFlask\u5e94\u7528\u7684host\u548cdebug\u6a21\u5f0f<\/p>\n<p>if __name__ == &#8220;__main__&#8221;:<\/p>\n<p>app.run(host=&#8221;0.0.0.0&#8243;, debug=True)<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u4e3b\u8981\u662f\u5728<\/p>\n<p>Process\u51fd\u6570\u4e2d<\/p>\n<p>\u6211\u4eec\u9996\u5148\u83b7\u53d6\u5230\u4e86flower\u8fd9\u4e2a\u5165\u53c2\u6570<\/p>\n<p>\u4e4b\u540e\u662f\u5229\u7528find\u51fd\u6570\uff0c\u83b7\u53d6\u5230\u5bf9\u5e94\u7684response<\/p>\n<p>\u6700\u540e\u89e3\u6790\u540e\u8fd4\u56de<\/p>\n<p>\u90a3\u4e48\u6211\u4eec\u603b\u7ed3\u4e00\u4e0b\uff0c\u6211\u4eec\u5b9e\u73b0\u4e86\u4e00\u4e2a\u5177\u6709\u641c\u7d22\u5fae\u535a\uff0c\u5e76\u5c06\u641c\u7d22\u7ed3\u679c\u4e00\u4e2a\u7279\u5b9a\u683c\u5f0f\u8fd4\u56de\u7684\u7a0b\u5e8f\uff0c\u6211\u4eec\u5229\u7528\u4e86LangChain\u4e2d\u7684\u94fe\uff0c\u4ee3\u7406\uff0c\u8f93\u51fa\u89e3\u91ca\u5668\uff0c\u6a21\u677f\uff0c\u81ea\u5b9a\u4e49\u7684\u5de5\u5177\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u90e8\u7f72\u4e00\u4e2a\u9c9c\u82b1\u7f51\u7edc\u7535\u5546\u7684\u4eba\u8109\u5de5\u5177 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[43],"tags":[],"_links":{"self":[{"href":"http:\/\/xinblog.ltd\/index.php?rest_route=\/wp\/v2\/posts\/5121"}],"collection":[{"href":"http:\/\/xinblog.ltd\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/xinblog.ltd\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/xinblog.ltd\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/xinblog.ltd\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5121"}],"version-history":[{"count":1,"href":"http:\/\/xinblog.ltd\/index.php?rest_route=\/wp\/v2\/posts\/5121\/revisions"}],"predecessor-version":[{"id":5124,"href":"http:\/\/xinblog.ltd\/index.php?rest_route=\/wp\/v2\/posts\/5121\/revisions\/5124"}],"wp:attachment":[{"href":"http:\/\/xinblog.ltd\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5121"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/xinblog.ltd\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5121"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/xinblog.ltd\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5121"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}