-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprompt_templates.py
125 lines (107 loc) · 4.25 KB
/
prompt_templates.py
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
from langchain.prompts import PromptTemplate
# Updated CoT prompt template
CoT_prompt_template = PromptTemplate(
input_variables=["query", "tools_context", "tools", "examples"],
template="""
You are an AI assistant tasked with determining the appropriate tools and their arguments to solve a given query. You have access to a set of tools and their descriptions. Please analyze the query and provide a step-by-step reasoning to determine which tools to use and how to use them.
Query: {query}
Tool Descriptions:
{tools_context}
Available Tools:
{tools}
Example Use Cases:
{examples}
Please think through this step-by-step and provide your response strictly in the following JSON format without any additional text:
{{
"reasoning": [
"1. Analyze the query and identify the key requirements.",
"2. Review the available tools and their descriptions.",
"3. Consider the example use cases for guidance if present.",
"4. Determine which tools are necessary to fulfill the query.",
"5. For each selected tool, identify the required arguments based on the query."
],
"output": [
{{
"tool_name": "tool_name_here",
"arguments": [
{{
"argument_name": "arg_name_here",
"argument_value": "arg_value_here"
}}
]
}}
]
}}
Important notes:
1. If you need to use the output of a previous tool as input for another tool, use the format "$$PREV[i]", where i is the index of the previous tool (0-based). Example: if there was a need to use the first tool it is "$$PREV[0]"
2. If the query cannot be solved using existing tools, provide an empty JSON array as the output: {{"output": []}}.
3. Focus only on solving what is explicitly given in the query. Do not add extra steps or solve anything not directly requested.
4. For argument values that are arrays, provide them directly without using numbered keys.
5. Ensure that the "arguments" field is an array of objects, each containing "argument_name" and "argument_value" keys.
Ensure that your response is a valid JSON object with "reasoning" and "output" keys, and nothing else.
""",
)
# Updated ToT prompt template
ToT_prompt_template = PromptTemplate(
input_variables=["query", "tools_context", "tools", "examples"],
template="""
You are an AI assistant using the Tree of Thoughts strategy to solve queries with available tools. Analyze the query, generate multiple thought branches, evaluate them, and select the most promising path.
Query: {query}
Tool Descriptions:
{tools_context}
Available Tools:
{tools}
Example Use Cases:
{examples}
Please provide your response in the following JSON format without any additional text:
{{
"thought_tree": [
{{
"branch": 1,
"thoughts": [
"1. Initial thought for branch 1",
"2. Subsequent thought",
"3. Final thought for this branch"
],
"evaluation": "Evaluation of branch 1's potential"
}},
{{
"branch": 2,
"thoughts": [
"1. Initial thought for branch 2",
"2. Subsequent thought",
"3. Final thought for this branch"
],
"evaluation": "Evaluation of branch 2's potential"
}},
{{
"branch": 3,
"thoughts": [
"1. Initial thought for branch 3",
"2. Subsequent thought",
"3. Final thought for this branch"
],
"evaluation": "Evaluation of branch 3's potential"
}}
],
"selected_path": {{
"branch": "Number of the selected branch",
"reasoning": "Explanation for why this branch was selected"
}},
"output": [
{{
"tool_name": "tool_name_here",
"arguments": {{
"argument_name": "arg_value_here"
}}
}}
]
}}
Important notes:
1. If you need to use the output of a previous tool as input for another tool, use the format "$$PREV[i]", where i is the index of the previous tool (0-based).
2. If the query cannot be solved using existing tools, provide an empty JSON array as the output: {{"output": []}}.
3. Focus only on solving what is explicitly given in the query. Do not add extra steps or solve anything not directly requested.
4. For argument values that are arrays, provide them directly without using numbered keys.
Ensure that your response is a valid JSON object with "thought_tree", "selected_path", and "output" keys, and nothing else.
""",
)