To find out how many apples the cafeteria has now, we need to follow these steps:
1. Start with the initial number of apples: 23 apples. 2. Subtract the number of apples used for lunch: 23 - 20 = 3 apples remaining. 3. Add the number of apples bought: 3 + 6 = 9 apples.
So, the cafeteria now has 9 apples. print(response.choices[0].message.content)
提供 Few-Shots 样本
1 2 3 4 5 6
question = """Q: Roger has 5 tennis balls. He buys 2 more cans of tennis balls. Each can has 3 tennis balls. How many tennis balls does he have now? A: The answer is 11. Q: The cafeteria had 23 apples. If they used 20 to make lunch and bought 6 more, how many apples do they have? A:"""
使用magic word(或称引导提示词)
比如下面的question就用了引导提示词Let's think step by step:
1 2 3 4 5 6 7
question = """Q: Roger has 5 tennis balls. He buys 2 more cans of tennis balls. Each can has 3 tennis balls. How many tennis balls does he have now? A: The answer is 11. Q: The cafeteria had 23 apples. If they used 20 to make lunch and bought 6 more, how many apples do they have? A: Let's think step by step."""
需求:DuckDuckGo API分析问题“Compare the population gap between Toronto and New York city”
思路:任务拆分,单独解决,总结
任务拆分
1 2 3 4 5 6
plan_system_prompt = """ Let's first understand the problem and devise a plan to solve the problem. Please output the plan starting with the header 'Plan:' and then followed by a numbered list of steps. Please make the plan the minimum number of steps required to accurately complete the task. If the task is a question, the final step should almost always be 'Given the above steps taken, please respond to the users original question'. """
调用第三方工具:DuckDuckGo Search API
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
from duckduckgo_search import DDGS
definternet_search(query: str): with DDGS() as ddgs: ddgs_gen = ddgs.text( query, max_results=5, region="wt-wt", safesearch="moderate", timelimit="y", backend="api", ) if ddgs_gen: return [r for r in ddgs_gen] return"No results found."
search_res = internet_search('the current population of Toronto')