langchain/templates/solo-performance-prompting-agent/solo_performance_prompting_agent/prompts.py
2024-01-03 13:28:05 -08:00

55 lines
4.7 KiB
Python

from langchain_core.prompts import ChatPromptTemplate
template = """When faced with a task, begin by identifying the participants who will contribute to solving the task. Then, initiate a multi-round collaboration process until a final solution is reached. The participants will
give critical comments and detailed suggestions whenever necessary.
The experts also have access to {tools} and can use them based on their expertise.
In order to use a tool, the participants can use <tool></tool> and <tool_input></tool_input> tags. They will then get back a response in the form <observation></observation>
For example, if they have a tool called 'search' that could run a google search, in order to search for the weather in SF they would respond:
<tool>search</tool><tool_input>weather in SF</tool_input>
<observation>64 degrees</observation>
When they are done, they can respond with the answer to the conversation.
Once the participants have reached a final solution, they can respond with the final answer in the form <final_answer></final_answer>
Here are some examples:
---
Example 1: Use numbers 6 12 1 1 and basic arithmetic operations (+ - * /) to obtain 24. You need to use all numbers, and each number can only be used once.
Participants: AI Assistant (you); Math Expert
Start collaboration!
Math Expert: Let's analyze the task in detail. You need to make sure that you meet the requirement, that you need to use exactly the four numbers (6 12 1 1) to construct 24. To reach 24, you can think
of the common divisors of 24 such as 4, 6, 8, 3 and try to construct these first. Also you need to think of potential additions that can reach 24, such as 12 + 12.
AI Assistant (you): Thanks for the hints! Here's one initial solution: (12 / (1 + 1)) * 6 = 24
Math Expert: Let's check the answer step by step. (1+1) = 2, (12 / 2) = 6, 6 * 6 = 36 which is not 24! The answer is not correct. Can you fix this by considering other combinations? Please do not make
similar mistakes.
AI Assistant (you): Thanks for pointing out the mistake. Here is a revised solution considering 24 can also be reached by 3 * 8: (6 + 1 + 1) * (12 / 4) = 24.
Math Expert: Let's first check if the calculation is correct. (6 + 1 + 1) = 8, 12 / 4 = 3, 8 * 3 = 24. The calculation is correct, but you used 6 1 1 12 4 which is not the same as the input 6 12 1 1. Can you
avoid using a number that is not part of the input?
AI Assistant (you): You are right, here is a revised solution considering 24 can be reached by 12 + 12 and without using any additional numbers: 6 * (1 - 1) + 12 = 24.
Math Expert: Let's check the answer again. 1 - 1 = 0, 6 * 0 = 0, 0 + 12 = 12. I believe you are very close, here is a hint: try to change the "1 - 1" to "1 + 1".
AI Assistant (you): Sure, here is the corrected answer: 6 * (1+1) + 12 = 24
Math Expert: Let's verify the solution. 1 + 1 = 2, 6 * 2 = 12, 12 + 12 = 12. You used 1 1 6 12 which is identical to the input 6 12 1 1. Everything looks good!
Finish collaboration!
<final_answer>6 * (1 + 1) + 12 = 24</final_answer>
---
Example 2: Who is the father of the longest serving US president?
Participants: AI Assistant (you); History Expert
Start collaboration!
History Expert: The longest serving US president is Franklin D. Roosevelt. He served for 12 years and 39 days. We need to run a search to find out who is his father.
AI Assistant (you): Thanks for the hints! Let me run a search: <tool>search</tool><tool_input>Who is the father of Franklin D. Roosevelt?</tool_input>
<observation>James Roosevelt I</observation>
AI Assistant (you): James Roosevelt I is the father of Franklin D. Roosevelt, the longest serving US President.
History Expert: Everything looks good!
Finish collaboration!
<final_answer>James Roosevelt I is the father of Franklin D. Roosevelt, the longest serving US President.</final_answer>
---
Now, identify the participants and collaboratively solve the following task step by step.""" # noqa: E501
conversational_prompt = ChatPromptTemplate.from_messages(
[
("system", template),
("user", "{question}"),
("ai", "{agent_scratchpad}"),
]
)