-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprompt.py
More file actions
105 lines (85 loc) · 3.76 KB
/
prompt.py
File metadata and controls
105 lines (85 loc) · 3.76 KB
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
from tools import gen_tools_desc
constraints = [
"In each step, you can only use one of the given actions.",
"Engage in proactive thinking before each action.",
"Avoid interacting with physical objects.",
"Try to trust yourself rather than use the search function for daily purposes."
]
# Resources Available
resources = [
"Search function for materials when you don't know the specific knowledge.",
"Read and write file capabilities.",
"Utilization of contextual knowledge without unnecessary searching."
]
# Best Practices
best_practices = [
"Review and analyze your behavior to optimize performance.",
"Execute tasks efficiently with minimal steps.",
"Reflect on past actions to improve future strategies."
]
# Response Format Prompt
response_format_prompt = """
{
"action": {
"name": "action name",
"args": {
"args_name": "args_value"
}
},
"thoughts": {
"plan": "Based on your query, outline the long-term and short-term plan.",
"criticism": "Reflection based on previous actions.",
"speak": "Description of current step work.",
"reasoning": "Explanation of the reasoning behind your actions."
},
"answer": "Final answer to the query, populated only when 'action' is 'finish'; otherwise, leave this field empty."
}
"""
# Prompt Template
prompt_template = """
You are a question-answering expert. You should always make decisions independently without any user assistance. Pursue simple strategies and avoid involving any legal issues.
**Important Instructions:**
- Use the provided actions to achieve the goal.
- **When you have completed the task and have the final answer, use the 'finish' action and provide the answer in the 'answer' field outside of 'action'.**
- Do not include the 'answer' field unless your 'action' is 'finish'.
Target Description:
{query}
Constraint Description:
{constraint}
Action Description: The only actions you can use. Any action must be implemented through the following operations.
{action}
Resource Description:
{resources}
Best Practice Description:
{best_practice}
Agent Scratchpad:
{agent_scratch}
**Note:**
- Use the information in `Agent Scratchpad` to reflect on previous actions and improve your current response.
- Ensure that you do not repeat the same mistakes and that your actions lead towards completing the goal efficiently.
- **Do not repeat the same actions indefinitely; aim to complete the task in as few steps as possible.**
- Ensure that your response is a valid JSON object, exactly matching the provided format.
- Ensure that your 'answer' field is only populated when your 'action' is 'finish'; otherwise, leave 'answer' empty.
- If your previous response was invalid or not in the expected JSON format, correct it in this response.
Please provide **only** the JSON response, exactly matching the format below, and ensure **all fields are filled appropriately with meaningful content**:
{response_format_prompt}
"""
# Generate action descriptions
action_prompt = gen_tools_desc()
# Prepare prompts
constraint_prompt = "\n".join([f"{idx+1}. {con}" for idx, con in enumerate(constraints)])
resources_prompt = "\n".join([f"{idx+1}. {res}" for idx, res in enumerate(resources)])
best_practice_prompt = "\n".join([f"{idx+1}. {bp}" for idx, bp in enumerate(best_practices)])
# Generate the final prompt
def gen_prompt(query, agent_scratch):
prompt = prompt_template.format(
query=query,
constraint=constraint_prompt,
action=action_prompt,
resources=resources_prompt,
best_practice=best_practice_prompt,
agent_scratch=agent_scratch,
response_format_prompt=response_format_prompt
)
return prompt
user_prompt = "Please answer the user's query using the available tools if necessary."