You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: app/prompts.py
+32-1
Original file line number
Diff line number
Diff line change
@@ -33,13 +33,44 @@
33
33
34
34
** If no tools are required, then return an empty list for "tool_calls". **
35
35
36
-
**Wrap the JSON response between ```json and ```**.
36
+
**Wrap the JSON response between ```json and ```, and rememebr "tool_calls" is a list.**.
37
37
38
38
**Whenever a message starts with 'SYSTEM MESSAGE', that is a guide and help information for you to generate your next response, do not consider them a message from the user, and do not reply to them at all. Just use the information and continue your conversation with the user.**"""
39
39
40
+
41
+
ENFORCED_SYSTAME_MESSAE="""A history of conversations between an AI assistant and the user, plus the last user's message, is given to you.
42
+
43
+
You have access to a specific tool that the AI assistant must use to provide a proper answer. The tool is a function that requires a set of parameters, which are provided in a JSON schema to explain what parameters the tool needs. Your task is to extract the values for these parameters from the user's last message and the conversation history.
44
+
45
+
Your job is to closely examine the user's last message and the history of the conversation, then extract the necessary parameter values for the given tool based on the provided JSON schema. Remember that you must use the specified tool to generate the response.
46
+
47
+
You should think step by step, provide your reasoning for your response, then add the JSON response at the end following the below schema:
48
+
49
+
50
+
{
51
+
"tool_calls": [{
52
+
"name": "function_name",
53
+
"arguments": {
54
+
"arg1": "value1",
55
+
"arg2": "value2",
56
+
...
57
+
}]
58
+
}
59
+
}
60
+
61
+
62
+
**Wrap the JSON response between ```json and ```, and rememebr "tool_calls" is a list.**.
63
+
64
+
Whenever a message starts with 'SYSTEM MESSAGE', that is a guide and help information for you to generate your next response. Do not consider them a message from the user, and do not reply to them at all. Just use the information and continue your conversation with the user."""
65
+
40
66
CLEAN_UP_MESSAGE="When I tried to extract the content between ```json and ``` and parse the content to valid JSON object, I faced with the abovr error. Remember, you are supposed to wrap the schema between ```json and ```, and do this only one time. First find out what went wrong, that I couldn't extract the JSON between ```json and ```, and also faced error when trying to parse it, then regenerate the your last message and fix the issue."
67
+
41
68
SUFFIX="""Think step by step and justify your response. Make sure to not miss in case to answer user query we need multiple tools, in that case detect all that we need, then generate a JSON response wrapped between "```json" and "```". Remember to USE THIS JSON WRAPPER ONLY ONE TIME."""
42
69
70
+
FORCE_CALL_SUFFIX="""For this task, you HAVE to choose the tool (function) {tool_name}, and ignore other rools. Therefore think step by step and justify your response, then closely examine the user's last message and the history of the conversation, then extract the necessary parameter values for the given tool based on the provided JSON schema. Remember that you must use the specified tool to generate the response. Finally generate a JSON response wrapped between "```json" and "```". Remember to USE THIS JSON WRAPPER ONLY ONE TIME."""
returnf"SYSTEM MESSAGE: \n```json\n{function_call_result}\n```\n\nThe above is the result after functions are called. Use the result to answer the user's last question.\n\n"
"description": "Use this function to search DuckDuckGo for a query.\n\nArgs:\n query(str): The query to search for.\n max_results (optional, default=5): The maximum number of results to return.\n\nReturns:\n The result from DuckDuckGo.",
57
+
"parameters": {
58
+
"type": "object",
59
+
"properties": {
60
+
"query": {
61
+
"type": "string"
62
+
},
63
+
"max_results": {
64
+
"type": [
65
+
"number",
66
+
"null"
67
+
]
68
+
}
69
+
}
70
+
}
71
+
}
72
+
},
73
+
{
74
+
"type": "function",
75
+
"function": {
76
+
"name": "duckduckgo_news",
77
+
"description": "Use this function to get the latest news from DuckDuckGo.\n\nArgs:\n query(str): The query to search for.\n max_results (optional, default=5): The maximum number of results to return.\n\nReturns:\n The latest news from DuckDuckGo.",
78
+
"parameters": {
79
+
"type": "object",
80
+
"properties": {
81
+
"query": {
82
+
"type": "string"
83
+
},
84
+
"max_results": {
85
+
"type": [
86
+
"number",
87
+
"null"
88
+
]
89
+
}
90
+
}
91
+
}
92
+
}
93
+
}
94
+
]
95
+
}
96
+
97
+
response=requests.post(
98
+
proxy_url,
99
+
headers=header,
100
+
json=request
101
+
)
102
+
# Check if the request was successful
103
+
ifresponse.status_code==200:
104
+
# Process the response data (if needed)
105
+
res=response.json()
106
+
message=res['choices'][0]['message']
107
+
tools_response_messages= []
108
+
ifnotmessage['content'] and'tool_calls'inmessage:
109
+
fortool_callinmessage['tool_calls']:
110
+
tool_name=tool_call['function']['name']
111
+
tool_args=tool_call['function']['arguments']
112
+
tool_args=json.loads(tool_args)
113
+
iftool_namenotinfunction_map:
114
+
print(f"Error: {tool_name} is not a valid function name.")
0 commit comments