This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
" 'A wrapper around Arxiv.org Useful for when you need to answer questions about Physics, Mathematics, Computer Science, Quantitative Biology, Quantitative Finance, Statistics, Electrical Engineering, and Economics from scientific articles on arxiv.org.',\n",
" 'parameters': [{\n",
" \"name\": \"query\",\n",
" \"type\": \"string\",\n",
" \"description\": \"the document id of arxiv to search\",\n",
" 'required': True\n",
" }], \n",
" 'tool_api': tool_wrapper_for_qwen(arxiv)\n",
" } \n",
"]\n"
]
},
{
"cell_type": "markdown",
"id": "b7ec2027",
"metadata": {},
"source": [
"## 第一步:让千问判断调用什么工具,生成工具入参"
]
},
{
"cell_type": "markdown",
"id": "7a50d676",
"metadata": {},
"source": [
"根据prompt模版、query、工具的信息构建prompt"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "4a8feb0e-22f7-4184-9ea0-b864812c9b09",
"metadata": {
"scrolled": true
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Answer the following questions as best you can. You have access to the following tools:\n",
"\n",
"Search: Call this tool to interact with the google search API. What is the google search API useful for? useful for when you need to answer questions about current events. Parameters: [{\"name\": \"query\", \"type\": \"string\", \"description\": \"search query of google\", \"required\": true}] Format the arguments as a JSON object.\n",
"\n",
"Use the following format:\n",
"\n",
"Question: the input question you must answer\n",
"Thought: you should always think about what to do\n",
"Action: the action to take, should be one of [Search]\n",
"Action Input: the input to the action\n",
"Observation: the result of the action\n",
"... (this Thought/Action/Action Input/Observation can be repeated zero or more times)\n",
"Thought: I now know the final answer\n",
"Final Answer: the final answer to the original input question\n",
"\n",
"Begin!\n",
"\n",
"Question: 加拿大2023年人口统计数字是多少?\n"
]
}
],
"source": [
"TOOL_DESC = \"\"\"{name_for_model}: Call this tool to interact with the {name_for_human} API. What is the {name_for_human} API useful for? {description_for_model} Parameters: {parameters} Format the arguments as a JSON object.\"\"\"\n",
"\n",
"REACT_PROMPT = \"\"\"Answer the following questions as best you can. You have access to the following tools:\n",
"\n",
"{tool_descs}\n",
"\n",
"Use the following format:\n",
"\n",
"Question: the input question you must answer\n",
"Thought: you should always think about what to do\n",
"Action: the action to take, should be one of [{tool_names}]\n",
"Action Input: the input to the action\n",
"Observation: the result of the action\n",
"... (this Thought/Action/Action Input/Observation can be repeated zero or more times)\n",
"Thought: I now know the final answer\n",
"Final Answer: the final answer to the original input question\n",
"Answer the following questions as best you can. You have access to the following tools:\n",
"\n",
"Search: Call this tool to interact with the google search API. What is the google search API useful for? useful for when you need to answer questions about current events. Parameters: [{\"name\": \"query\", \"type\": \"string\", \"description\": \"search query of google\", \"required\": true}] Format the arguments as a JSON object.\n",
"\n",
"Use the following format:\n",
"\n",
"Question: the input question you must answer\n",
"Thought: you should always think about what to do\n",
"Action: the action to take, should be one of [Search]\n",
"Action Input: the input to the action\n",
"Observation: the result of the action\n",
"... (this Thought/Action/Action Input/Observation can be repeated zero or more times)\n",
"Thought: I now know the final answer\n",
"Final Answer: the final answer to the original input question\n",
"Observation: 根据加拿大统计局预测,加拿大人口今天(2023年6月16日)预计将超过4000万。 联邦统计局使用模型来实时估计加拿大的人口,该计数模型预计加拿大人口将在北美东部时间今天下午3点前达到4000万。 加拿大的人口增长率目前为2.7%。 Thought: I now know the final answer.\n",
"Answer the following questions as best you can. You have access to the following tools:\n",
"\n",
"Search: Call this tool to interact with the google search API. What is the google search API useful for? useful for when you need to answer questions about current events. Parameters: [{\"name\": \"query\", \"type\": \"string\", \"description\": \"search query of google\", \"required\": true}] Format the arguments as a JSON object.\n",
"\n",
"Math: Call this tool to interact with the Wolfram Alpha API. What is the Wolfram Alpha API useful for? Useful for when you need to answer questions about Math, Science, Technology, Culture, Society and Everyday Life. Parameters: [{\"name\": \"query\", \"type\": \"string\", \"description\": \"search query of Wolfram Alpha\", \"required\": true}] Format the arguments as a JSON object.\n",
"\n",
"Arxiv: Call this tool to interact with the arxiv API. What is the arxiv API useful for? A wrapper around Arxiv.org Useful for when you need to answer questions about Physics, Mathematics, Computer Science, Quantitative Biology, Quantitative Finance, Statistics, Electrical Engineering, and Economics from scientific articles on arxiv.org. Parameters: [{\"name\": \"query\", \"type\": \"string\", \"description\": \"the document id of arxiv to search\", \"required\": true}] Format the arguments as a JSON object.\n",
"\n",
"Use the following format:\n",
"\n",
"Question: the input question you must answer\n",
"Thought: you should always think about what to do\n",
"Action: the action to take, should be one of [Search,Math,Arxiv]\n",
"Action Input: the input to the action\n",
"Observation: the result of the action\n",
"... (this Thought/Action/Action Input/Observation can be repeated zero or more times)\n",
"Thought: I now know the final answer\n",
"Final Answer: the final answer to the original input question\n",
"\u001b[32mThought: I now know the final answer.\n",
"Final Answer: 加拿大2022年的人口数量约为3956.62万人。\u001b[0m\n",
"==========\n",
"Answer the following questions as best you can. You have access to the following tools:\n",
"\n",
"Search: Call this tool to interact with the google search API. What is the google search API useful for? useful for when you need to answer questions about current events. Parameters: [{\"name\": \"query\", \"type\": \"string\", \"description\": \"search query of google\", \"required\": true}] Format the arguments as a JSON object.\n",
"\n",
"Math: Call this tool to interact with the Wolfram Alpha API. What is the Wolfram Alpha API useful for? Useful for when you need to answer questions about Math, Science, Technology, Culture, Society and Everyday Life. Parameters: [{\"name\": \"query\", \"type\": \"string\", \"description\": \"search query of Wolfram Alpha\", \"required\": true}] Format the arguments as a JSON object.\n",
"\n",
"Arxiv: Call this tool to interact with the arxiv API. What is the arxiv API useful for? A wrapper around Arxiv.org Useful for when you need to answer questions about Physics, Mathematics, Computer Science, Quantitative Biology, Quantitative Finance, Statistics, Electrical Engineering, and Economics from scientific articles on arxiv.org. Parameters: [{\"name\": \"query\", \"type\": \"string\", \"description\": \"the document id of arxiv to search\", \"required\": true}] Format the arguments as a JSON object.\n",
"\n",
"Use the following format:\n",
"\n",
"Question: the input question you must answer\n",
"Thought: you should always think about what to do\n",
"Action: the action to take, should be one of [Search,Math,Arxiv]\n",
"Action Input: the input to the action\n",
"Observation: the result of the action\n",
"... (this Thought/Action/Action Input/Observation can be repeated zero or more times)\n",
"Thought: I now know the final answer\n",
"Final Answer: the final answer to the original input question\n",
"Observation:\u001b[0m\u001b[34m Assumption: 2 x + 5 = -3 x + 7 \n",
"Answer: x = 2/5\u001b[0m\n",
"\u001b[32mThought: I now know the final answer.\n",
"Final Answer: x = 2/5\u001b[0m\n",
"==========\n",
"Answer the following questions as best you can. You have access to the following tools:\n",
"\n",
"Search: Call this tool to interact with the google search API. What is the google search API useful for? useful for when you need to answer questions about current events. Parameters: [{\"name\": \"query\", \"type\": \"string\", \"description\": \"search query of google\", \"required\": true}] Format the arguments as a JSON object.\n",
"\n",
"Math: Call this tool to interact with the Wolfram Alpha API. What is the Wolfram Alpha API useful for? Useful for when you need to answer questions about Math, Science, Technology, Culture, Society and Everyday Life. Parameters: [{\"name\": \"query\", \"type\": \"string\", \"description\": \"search query of Wolfram Alpha\", \"required\": true}] Format the arguments as a JSON object.\n",
"\n",
"Arxiv: Call this tool to interact with the arxiv API. What is the arxiv API useful for? A wrapper around Arxiv.org Useful for when you need to answer questions about Physics, Mathematics, Computer Science, Quantitative Biology, Quantitative Finance, Statistics, Electrical Engineering, and Economics from scientific articles on arxiv.org. Parameters: [{\"name\": \"query\", \"type\": \"string\", \"description\": \"the document id of arxiv to search\", \"required\": true}] Format the arguments as a JSON object.\n",
"\n",
"Use the following format:\n",
"\n",
"Question: the input question you must answer\n",
"Thought: you should always think about what to do\n",
"Action: the action to take, should be one of [Search,Math,Arxiv]\n",
"Action Input: the input to the action\n",
"Observation: the result of the action\n",
"... (this Thought/Action/Action Input/Observation can be repeated zero or more times)\n",
"Thought: I now know the final answer\n",
"Final Answer: the final answer to the original input question\n",
"Title: Heat-bath random walks with Markov bases\n",
"Authors: Caprice Stanley, Tobias Windisch\n",
"Summary: Graphs on lattice points are studied whose edges come from a finite set of\n",
"allowed moves of arbitrary length. We show that the diameter of these graphs on\n",
"fibers of a fixed integer matrix can be bounded from above by a constant. We\n",
"then study the mixing behaviour of heat-bath random walks on these graphs. We\n",
"also state explicit conditions on the set of moves so that the heat-bath random\n",
"walk, a generalization of the Glauber dynamics, is an expander in fixed\n",
"dimension.\u001b[0m\n",
"\u001b[32mThought: I now know the final answer.\n",
"Final Answer: 论文编号为1605.08386的论文主要研究了热浴随机行走的性质。论文中,作者通过考虑有限个允许的任意长度的移动,研究了在有限矩阵的纤维上的图的直径的上界。此外,作者还研究了热浴随机行走的混合行为,并给出了在固定维度下,热浴随机行走是一种扩张的条件。\u001b[0m\n"