langchain问答和路由测试

基于APIChain和RouterChain打造的问答

  1. 首先准备好APIChain所需的api调用,我们构造2个Datatouch的api接口,使用GET的请求方式,每个接口支持多个参数。
  2. 制定好回答某类问题的标准流程SOP。
  3. 解答思路, 用户提问–RouterChain–APIChain或DefaultChain–答案LLM

代码功能实现

核心代码:路由Chain的实现

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
    def get_prompt_infos(self,name=None):
"""
获取提示模板的相关信息
param:name: 如果提供name,那么只返回属于这条name的信息
Returns:
"""
prompt_infos = [
{
"name": "菱歌研究院",
"description": "获取菱歌Datatouch网站下的菱歌研究院中的内容,包括发布的所有白皮书,文章等",
"example_question":["菱歌研究院最近发表的一篇文章讲了是关于什么的?","菱歌的白皮书有哪些?"], # 帮助匹配到正确的接口
"api_doc_name": "academic_docs",
"prompt_response_template": self.get_api_response_template(),
"prompt_url_template": self.get_api_url_template(),
"chain_type": "apichain",
"input_keyword": "question",
},
{
"name": "商品排行榜",
"description": "获取菱歌Datatouch网站下商品排行榜中的内容,根据时间对商品按热度,销量,涨幅等进行排名,还返回商品的功效简介和价格信息",
"example_question": ["最近2个月的商品排行情况?", "某某商品在最近2个月的热度如何?"], # 帮助匹配到正确的接口
"api_doc_name": "rank_docs",
"prompt_response_template": self.get_api_response_template(),
"prompt_url_template": self.get_api_url_template(),
"chain_type": "apichain",
"input_keyword": "question",
},
{
"name": "math",
"description": "用于解决数学问题",
"chain_type": "llmchain",
"input_keyword": "input",
"prompt_template": """You are a very good mathematician. You are great at answering math questions. \
You are so good because you are able to break down hard problems into their component parts, \
answer the component parts, and then put them together to answer the broader question.

Here is a question:
{input}"""
}
]
if name is not None:
for p_info in prompt_infos:
if p_info["name"] == name:
return p_info
else:
raise ValueError("名字为:{}的,不在我们的提示模板中".format(name))
return prompt_infos
def get_router_of_destination_chains(self):
"""
获取所有的路由的chains
Returns:
"""
prompt_infos = self.get_prompt_infos()
destination_chains = {}
for p_info in prompt_infos:
name = p_info["name"]
chain_type = p_info["chain_type"]
if chain_type == "apichain":
api_doc_name = p_info["api_doc_name"]
api_docs = self.get_api_docs(doc_name=api_doc_name)
prompt_response_template = p_info["prompt_response_template"]
prompt_url_template = p_info["prompt_url_template"]
# 只用了回复的template
chain = APIChain.from_llm_and_api_docs(self.llm, api_docs=api_docs,api_url_prompt=prompt_url_template, api_response_prompt=prompt_response_template,verbose=True)
elif chain_type == "llmchain":
prompt_template = p_info["prompt_template"]
prompt = PromptTemplate(template=prompt_template, input_variables=["input"])
chain = LLMChain(llm=self.llm, prompt=prompt)
else:
raise ValueError(f"不支持的chain_type: {chain_type},请检查")
destination_chains[name] = chain
return destination_chains, prompt_infos
def get_routers_chain(self):
"""
获取路由的chains, 路由的chains是一个多路由的chain
Returns:
"""
default_chain = ConversationChain(llm=self.llm, output_key="text")
destination_chains, prompt_infos = self.get_router_of_destination_chains()
destinations = [f"{p['name']}: {p['description']}" for p in prompt_infos]
destinations_str = "\n".join(destinations)
router_template = MULTI_PROMPT_ROUTER_TEMPLATE.format(
destinations=destinations_str
)
router_prompt = PromptTemplate(
template=router_template,
input_variables=["input"],
output_parser=RouterOutputParser(),
)
router_chain = LLMRouterChain.from_llm(self.llm, router_prompt)
# 不能用MultiPromptChain,会出现问题,不兼容APIChain
# chain = MultiPromptChain(router_chain=router_chain, destination_chains=destination_chains,
# default_chain=default_chain, verbose=True)
return router_chain, destination_chains, default_chain

回答实现:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
    def anwser(self,question):
"""
回答问题
1. 问题类型判断,判断使用的需要使用的接口和工具
2. 查看接口和工具使用的参数
3. 获取接口和工具中的参数,组织后,调用接口和工具
4. 对获取到的结果进行最终解答
Args:
question ():
Returns:
"""
# 第一次调用LLM,根据问题和各个Chain,选择最合适的Chain
router_chain, destination_chains, default_chain = self.get_routers_chain()
destination,next_inputs = router_chain.route(question)
if not destination:
response = default_chain(next_inputs)
else:
assert destination in destination_chains, f"destination: {destination} 不在destination_chains中"
# 需要检查next_inputs中的内容是否符合要求
prompt_infos = self.get_prompt_infos(name=destination)
input_keyword = prompt_infos["input_keyword"]
if input_keyword not in next_inputs:
new_inputs = {input_keyword: next_inputs["input"]}
next_inputs = new_inputs
response = destination_chains[destination](next_inputs)
return response
if __name__ == '__main__':
chatbot = ChatBot()
# response = chatbot.anwser("菱歌研究院最近发表的一篇文章讲了什么内容?")
# response = chatbot.anwser("菱歌Datatouch官网中商品排行榜中热度第一的商品是哪个,有什么功效?")
response = chatbot.anwser("你好啊,你知道中国的五岳是那几座山吗?")
print(response)

效果测试

1.模型内部知识,其它未匹配的到SOP的知识回答

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
[
{
"POE": "poe",
"input_prompt": "Given a raw text input to a language model select the model prompt best suited for the input. You will be given the names of the available prompts and a description of what the prompt is best suited for. You may also revise the original input if you think that revising it will ultimately lead to a better response from the language model.\n\n<< FORMATTING >>\nReturn a markdown code snippet with a JSON object formatted to look like:\n```json\n{\n \"destination\": string \\ name of the prompt to use or \"DEFAULT\"\n \"next_inputs\": string \\ a potentially modified version of the original input\n}\n```\n\nREMEMBER: \"destination\" MUST be one of the candidate prompt names specified below OR it can be \"DEFAULT\" if the input is not well suited for any of the candidate prompts.\nREMEMBER: \"next_inputs\" can just be the original input if you don't think any modifications are needed.\n\n<< CANDIDATE PROMPTS >>\n菱歌研究院: 获取菱歌Datatouch网站下的菱歌研究院中的内容,包括发布的所有白皮书,文章等\n商品排行榜: 获取菱歌Datatouch网站下商品排行榜中的内容,根据时间对商品按热度,销量,涨幅等进行排名,还返回商品的功效简介和价格信息\nmath: 用于解决数学问题\n\n<< INPUT >>\n你好啊,你知道中国的五岳是那几座山吗?\n\n<< OUTPUT >>\n",
"input_text": "",
"response": "```json\n{\n \"destination\": \"DEFAULT\",\n \"next_inputs\": \"你好啊,你知道中国的五岳是那几座山吗?\"\n}\n```"
}
]
[
{
"POE": "poe",
"input_prompt": "The following is a friendly conversation between a human and an AI. The AI is talkative and provides lots of specific details from its context. If the AI does not know the answer to a question, it truthfully says it does not know.\n\nCurrent conversation:\n\nHuman: 你好啊,你知道中国的五岳是那几座山吗?\nAI:",
"input_text": "",
"response": "你好!中国的五岳指的是五座历史上被誉为最高的山峰,它们分别是:华山、嵩山、泰山、衡山和恒山。这五座山峰都有着悠久的历史和文化背景,也是中国历史上的重要地标之一。"
}
]
{'input': '你好啊,你知道中国的五岳是那几座山吗?', 'history': '', 'text': '你好!中国的五岳指的是五座历史上被誉为最高的山峰,它们分别是:华山嵩山泰山衡山和恒山这五座山峰都有着悠久的历史和文化背景,也是中国历史上的重要地标之一'}

2.关于Datatouch中的排行榜相关的问题

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
[
{
"POE": "poe",
"input_prompt": "Given a raw text input to a language model select the model prompt best suited for the input. You will be given the names of the available prompts and a description of what the prompt is best suited for. You may also revise the original input if you think that revising it will ultimately lead to a better response from the language model.\n\n<< FORMATTING >>\nReturn a markdown code snippet with a JSON object formatted to look like:\n```json\n{\n \"destination\": string \\ name of the prompt to use or \"DEFAULT\"\n \"next_inputs\": string \\ a potentially modified version of the original input\n}\n```\n\nREMEMBER: \"destination\" MUST be one of the candidate prompt names specified below OR it can be \"DEFAULT\" if the input is not well suited for any of the candidate prompts.\nREMEMBER: \"next_inputs\" can just be the original input if you don't think any modifications are needed.\n\n<< CANDIDATE PROMPTS >>\n菱歌研究院: 获取菱歌Datatouch网站下的菱歌研究院中的内容,包括发布的所有白皮书,文章等\n商品排行榜: 获取菱歌Datatouch网站下商品排行榜中的内容,根据时间对商品按热度,销量,涨幅等进行排名,还返回商品的功效简介和价格信息\nmath: 用于解决数学问题\n\n<< INPUT >>\n菱歌Datatouch官网中商品排行榜中热度第一的商品是哪个,有什么功效?\n\n<< OUTPUT >>\n",
"input_text": "",
"response": "```json\n{\n \"destination\": \"商品排行榜\",\n \"next_inputs\": \"菱歌Datatouch官网中商品排行榜中热度第一的商品是哪个,有什么功效?\"\n}\n```"
}
]


> Entering new chain...
[
{
"POE": "poe",
"input_prompt": "You are given the below API Documentation:\n BASE URL: http://127.0.0.1:6301/api\nAPI Documentation\nThe API endpoint /rank accepts some filter variables, use GET Method, responds with a JSON of 商品名称,热度,涨幅,价格,功效介绍.\nParameter\tFormat\tRequired\tDefault\tDescription\nstartTime, string\tYes\t\t year-month, eg: 2023-05\nendTime, string\tYes\t\t year-month, eg: 2023-05\npage, Integer\tYes\t\t page number, default: 0\nsize, Integer\tYes\t\t limit items of per page, default: 5\ntype, Integer\tYes\t\t 1 means sort by 热度, 2 means sort by 销量, 1: 热度, 2: 销量, default: 1\n \n Using this documentation, generate the full API url to call for answering the user question.\n You should build the API url in order to get a response that is as short as possible, while still getting the necessary information to answer the question. Pay attention to deliberately exclude any unnecessary pieces of data in the API call.\n CAUSTION: only response the API url, no any other information and explanation.\n Question:菱歌Datatouch官网中商品排行榜中热度第一的商品是哪个,有什么功效?\n API url:",
"input_text": "",
"response": "http://127.0.0.1:6301/api/rank?startTime=2023-05&endTime=2023-05&page=0&size=1&type=1"
}
]
http://127.0.0.1:6301/api/rank?startTime=2023-05&endTime=2023-05&page=0&size=1&type=1
[{"商品名称": "半亩花田米酵氨基酸泡泡洁面慕斯", "热度": 47216, "环比涨幅": 90.22, "同比涨幅": 87.88, "图片链接": "http://img.lavector.com/lavectorimages/f93d527c83b7616b2876939ded81c3291686552069291.jpg", "价格": 39.9, "功效列表": ["深层清洁", "水油平衡", "柔肤", "改善粗糙", "祛闭口", "祛黑头", "祛痘", "收缩毛孔", "温和不刺激"]}]
[
{
"POE": "poe",
"input_prompt": "\n You are given the below API Documentation:\n BASE URL: http://127.0.0.1:6301/api\nAPI Documentation\nThe API endpoint /rank accepts some filter variables, use GET Method, responds with a JSON of 商品名称,热度,涨幅,价格,功效介绍.\nParameter\tFormat\tRequired\tDefault\tDescription\nstartTime, string\tYes\t\t year-month, eg: 2023-05\nendTime, string\tYes\t\t year-month, eg: 2023-05\npage, Integer\tYes\t\t page number, default: 0\nsize, Integer\tYes\t\t limit items of per page, default: 5\ntype, Integer\tYes\t\t 1 means sort by 热度, 2 means sort by 销量, 1: 热度, 2: 销量, default: 1\n \n Using this documentation, generate the full API url to call for answering the user question.\n You should build the API url in order to get a response that is as short as possible, while still getting the necessary information to answer the question. Pay attention to deliberately exclude any unnecessary pieces of data in the API call.\n API url:http://127.0.0.1:6301/api/rank?startTime=2023-05&endTime=2023-05&page=0&size=1&type=1\n Here is the response from the API:\n [{\"商品名称\": \"半亩花田米酵氨基酸泡泡洁面慕斯\", \"热度\": 47216, \"环比涨幅\": 90.22, \"同比涨幅\": 87.88, \"图片链接\": \"http://img.lavector.com/lavectorimages/f93d527c83b7616b2876939ded81c3291686552069291.jpg\", \"价格\": 39.9, \"功效列表\": [\"深层清洁\", \"水油平衡\", \"柔肤\", \"改善粗糙\", \"祛闭口\", \"祛黑头\", \"祛痘\", \"收缩毛孔\", \"温和不刺激\"]}]\n Question:菱歌Datatouch官网中商品排行榜中热度第一的商品是哪个,有什么功效?\n 根据上面的Question问题和API返回结果进行回答,用中文回答。\n 答:",
"input_text": "",
"response": "根据API返回结果,菱歌Datatouch官网商品排行榜中热度第一的商品是\"半亩花田米酵氨基酸泡泡洁面慕斯\"。该商品的功效包括深层清洁、水油平衡、柔肤、改善粗糙、祛闭口、祛黑头、祛痘、收缩毛孔、温和不刺激。"
}
]

> Finished chain.
{'question': '菱歌Datatouch官网中商品排行榜中热度第一的商品是哪个,有什么功效?', 'output': '根据API返回结果,菱歌Datatouch官网商品排行榜中热度第一的商品是"半亩花田米酵氨基酸泡泡洁面慕斯"该商品的功效包括深层清洁水油平衡柔肤改善粗糙祛闭口祛黑头祛痘收缩毛孔温和不刺激'}

3.灵活扩展排行榜中的问题

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
[
{
"POE": "poe",
"input_prompt": "Given a raw text input to a language model select the model prompt best suited for the input. You will be given the names of the available prompts and a description of what the prompt is best suited for. You may also revise the original input if you think that revising it will ultimately lead to a better response from the language model.\n\n<< FORMATTING >>\nReturn a markdown code snippet with a JSON object formatted to look like:\n```json\n{\n \"destination\": string \\ name of the prompt to use or \"DEFAULT\"\n \"next_inputs\": string \\ a potentially modified version of the original input\n}\n```\n\nREMEMBER: \"destination\" MUST be one of the candidate prompt names specified below OR it can be \"DEFAULT\" if the input is not well suited for any of the candidate prompts.\nREMEMBER: \"next_inputs\" can just be the original input if you don't think any modifications are needed.\n\n<< CANDIDATE PROMPTS >>\n菱歌研究院: 获取菱歌Datatouch网站下的菱歌研究院中的内容,包括发布的所有白皮书,文章等\n商品排行榜: 获取菱歌Datatouch网站下商品排行榜中的内容,根据时间对商品按热度,销量,涨幅等进行排名,还返回商品的功效简介和价格信息\nmath: 用于解决数学问题\n\n<< INPUT >>\n菱歌Datatouch官网中5月份商品排行榜中销量第二的商品是哪个,有什么功效?\n\n<< OUTPUT >>\n",
"input_text": "",
"response": "```json\n{\n \"destination\": \"商品排行榜\",\n \"next_inputs\": \"菱歌Datatouch官网中5月份商品排行榜中销量第二的商品是哪个,有什么功效?\"\n}\n```"
}
]


> Entering new chain...
[
{
"POE": "poe",
"input_prompt": "You are given the below API Documentation:\n BASE URL: http://127.0.0.1:6301/api\nAPI Documentation\nThe API endpoint /rank accepts some filter variables, use GET Method, responds with a JSON of 商品名称,热度,涨幅,价格,功效介绍.\nParameter\tFormat\tRequired\tDefault\tDescription\nstartTime, string\tYes\t\t year-month, eg: 2023-05\nendTime, string\tYes\t\t year-month, eg: 2023-05\npage, Integer\tYes\t\t page number, default: 0\nsize, Integer\tYes\t\t limit items of per page, default: 5\ntype, Integer\tYes\t\t 1 means sort by 热度, 2 means sort by 销量, 1: 热度, 2: 销量, default: 1\n \n Using this documentation, generate the full API url to call for answering the user question.\n You should build the API url in order to get a response that is as short as possible, while still getting the necessary information to answer the question. Pay attention to deliberately exclude any unnecessary pieces of data in the API call.\n CAUSTION: only response the API url, no any other information and explanation.\n Question:菱歌Datatouch官网中5月份商品排行榜中销量第二的商品是哪个,有什么功效?\n API url:",
"input_text": "",
"response": " http://127.0.0.1:6301/api/rank?endTime=2023-05&size=1&type=2&page=0"
}
]
http://127.0.0.1:6301/api/rank?endTime=2023-05&size=1&type=2&page=0
[{"商品名称": "至本舒颜修护洁面乳", "热度": 490202, "环比涨幅": 67.9, "同比涨幅": -59.01, "图片链接": "http://img.lavector.com/lavectorimages/4eb3166de70caf8c8e19e8158b042d9e.jpg", "价格": 55.0, "功效列表": ["清洁肌肤污垢", "温和不刺激"]}]
[
{
"POE": "poe",
"input_prompt": "\n You are given the below API Documentation:\n BASE URL: http://127.0.0.1:6301/api\nAPI Documentation\nThe API endpoint /rank accepts some filter variables, use GET Method, responds with a JSON of 商品名称,热度,涨幅,价格,功效介绍.\nParameter\tFormat\tRequired\tDefault\tDescription\nstartTime, string\tYes\t\t year-month, eg: 2023-05\nendTime, string\tYes\t\t year-month, eg: 2023-05\npage, Integer\tYes\t\t page number, default: 0\nsize, Integer\tYes\t\t limit items of per page, default: 5\ntype, Integer\tYes\t\t 1 means sort by 热度, 2 means sort by 销量, 1: 热度, 2: 销量, default: 1\n \n Using this documentation, generate the full API url to call for answering the user question.\n You should build the API url in order to get a response that is as short as possible, while still getting the necessary information to answer the question. Pay attention to deliberately exclude any unnecessary pieces of data in the API call.\n API url:http://127.0.0.1:6301/api/rank?endTime=2023-05&size=1&type=2&page=0\n Here is the response from the API:\n [{\"商品名称\": \"至本舒颜修护洁面乳\", \"热度\": 490202, \"环比涨幅\": 67.9, \"同比涨幅\": -59.01, \"图片链接\": \"http://img.lavector.com/lavectorimages/4eb3166de70caf8c8e19e8158b042d9e.jpg\", \"价格\": 55.0, \"功效列表\": [\"清洁肌肤污垢\", \"温和不刺激\"]}]\n Question:菱歌Datatouch官网中5月份商品排行榜中销量第二的商品是哪个,有什么功效?\n 根据上面的Question问题和API返回结果进行回答,用中文回答。\n 答:",
"input_text": "",
"response": " 至本舒颜修护洁面乳是5月份销量第二的商品,它具有清洁肌肤污垢、温和不刺激的功效。"
}
]

> Finished chain.
{'question': '菱歌Datatouch官网中5月份商品排行榜中销量第二的商品是哪个,有什么功效?', 'output': ' 至本舒颜修护洁面乳是5月份销量第二的商品,它具有清洁肌肤污垢温和不刺激的功效'}

4.关于菱歌研究院的中的问题回答

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
[
{
"POE": "poe",
"input_prompt": "Given a raw text input to a language model select the model prompt best suited for the input. You will be given the names of the available prompts and a description of what the prompt is best suited for. You may also revise the original input if you think that revising it will ultimately lead to a better response from the language model.\n\n<< FORMATTING >>\nReturn a markdown code snippet with a JSON object formatted to look like:\n```json\n{\n \"destination\": string \\ name of the prompt to use or \"DEFAULT\"\n \"next_inputs\": string \\ a potentially modified version of the original input\n}\n```\n\nREMEMBER: \"destination\" MUST be one of the candidate prompt names specified below OR it can be \"DEFAULT\" if the input is not well suited for any of the candidate prompts.\nREMEMBER: \"next_inputs\" can just be the original input if you don't think any modifications are needed.\n\n<< CANDIDATE PROMPTS >>\n菱歌研究院: 获取菱歌Datatouch网站下的菱歌研究院中的内容,包括发布的所有白皮书,文章等\n商品排行榜: 获取菱歌Datatouch网站下商品排行榜中的内容,根据时间对商品按热度,销量,涨幅等进行排名,还返回商品的功效简介和价格信息\nmath: 用于解决数学问题\n\n<< INPUT >>\n菱歌Datatouch官网中商品排行榜中热度第一的商品是哪个,有什么功效?\n\n<< OUTPUT >>\n",
"input_text": "",
"response": "```json\n{\n \"destination\": \"商品排行榜\",\n \"next_inputs\": \"菱歌Datatouch官网中商品排行榜中热度第一的商品是哪个,有什么功效?\"\n}\n```"
}
]


> Entering new chain...
[
{
"POE": "poe",
"input_prompt": "You are given the below API Documentation:\n BASE URL: http://127.0.0.1:6301/api\nAPI Documentation\nThe API endpoint /rank accepts some filter variables, use GET Method, responds with a JSON of 商品名称,热度,涨幅,价格,功效介绍.\nParameter\tFormat\tRequired\tDefault\tDescription\nstartTime, string\tYes\t\t year-month, eg: 2023-05\nendTime, string\tYes\t\t year-month, eg: 2023-05\npage, Integer\tYes\t\t page number, default: 0\nsize, Integer\tYes\t\t limit items of per page, default: 5\ntype, Integer\tYes\t\t 1 means sort by 热度, 2 means sort by 销量, 1: 热度, 2: 销量, default: 1\n \n Using this documentation, generate the full API url to call for answering the user question.\n You should build the API url in order to get a response that is as short as possible, while still getting the necessary information to answer the question. Pay attention to deliberately exclude any unnecessary pieces of data in the API call.\n CAUSTION: only response the API url, no any other information and explanation.\n Question:菱歌Datatouch官网中商品排行榜中热度第一的商品是哪个,有什么功效?\n API url:",
"input_text": "",
"response": "http://127.0.0.1:6301/api/rank?startTime=2023-05&endTime=2023-05&page=0&size=1&type=1"
}
]
http://127.0.0.1:6301/api/rank?startTime=2023-05&endTime=2023-05&page=0&size=1&type=1
[{"商品名称": "半亩花田米酵氨基酸泡泡洁面慕斯", "热度": 47216, "环比涨幅": 90.22, "同比涨幅": 87.88, "图片链接": "http://img.lavector.com/lavectorimages/f93d527c83b7616b2876939ded81c3291686552069291.jpg", "价格": 39.9, "功效列表": ["深层清洁", "水油平衡", "柔肤", "改善粗糙", "祛闭口", "祛黑头", "祛痘", "收缩毛孔", "温和不刺激"]}]
[
{
"POE": "poe",
"input_prompt": "\n You are given the below API Documentation:\n BASE URL: http://127.0.0.1:6301/api\nAPI Documentation\nThe API endpoint /rank accepts some filter variables, use GET Method, responds with a JSON of 商品名称,热度,涨幅,价格,功效介绍.\nParameter\tFormat\tRequired\tDefault\tDescription\nstartTime, string\tYes\t\t year-month, eg: 2023-05\nendTime, string\tYes\t\t year-month, eg: 2023-05\npage, Integer\tYes\t\t page number, default: 0\nsize, Integer\tYes\t\t limit items of per page, default: 5\ntype, Integer\tYes\t\t 1 means sort by 热度, 2 means sort by 销量, 1: 热度, 2: 销量, default: 1\n \n Using this documentation, generate the full API url to call for answering the user question.\n You should build the API url in order to get a response that is as short as possible, while still getting the necessary information to answer the question. Pay attention to deliberately exclude any unnecessary pieces of data in the API call.\n API url:http://127.0.0.1:6301/api/rank?startTime=2023-05&endTime=2023-05&page=0&size=1&type=1\n Here is the response from the API:\n [{\"商品名称\": \"半亩花田米酵氨基酸泡泡洁面慕斯\", \"热度\": 47216, \"环比涨幅\": 90.22, \"同比涨幅\": 87.88, \"图片链接\": \"http://img.lavector.com/lavectorimages/f93d527c83b7616b2876939ded81c3291686552069291.jpg\", \"价格\": 39.9, \"功效列表\": [\"深层清洁\", \"水油平衡\", \"柔肤\", \"改善粗糙\", \"祛闭口\", \"祛黑头\", \"祛痘\", \"收缩毛孔\", \"温和不刺激\"]}]\n Question:菱歌Datatouch官网中商品排行榜中热度第一的商品是哪个,有什么功效?\n 根据上面的Question问题和API返回结果进行回答,用中文回答。\n 答:",
"input_text": "",
"response": "根据API返回结果,菱歌Datatouch官网商品排行榜中热度第一的商品是\"半亩花田米酵氨基酸泡泡洁面慕斯\"。该商品的功效包括深层清洁、水油平衡、柔肤、改善粗糙、祛闭口、祛黑头、祛痘、收缩毛孔、温和不刺激。"
}
]

> Finished chain.
{'question': '菱歌Datatouch官网中商品排行榜中热度第一的商品是哪个,有什么功效?', 'output': '根据API返回结果,菱歌Datatouch官网商品排行榜中热度第一的商品是"半亩花田米酵氨基酸泡泡洁面慕斯"该商品的功效包括深层清洁水油平衡柔肤改善粗糙祛闭口祛黑头祛痘收缩毛孔温和不刺激'}

langchain问答和路由测试
https://johnson7788.github.io/2023/06/15/langchain%E9%97%AE%E7%AD%94%E5%92%8C%E8%B7%AF%E7%94%B1%E6%B5%8B%E8%AF%95/
作者
Johnson
发布于
2023年6月15日
许可协议