Spaces:
Running
Running
ricklamers
commited on
Commit
•
6403e58
1
Parent(s):
182dc7c
fix: correct message role history
Browse files- .gitignore +7 -1
- __pycache__/app.cpython-310.pyc +0 -0
- app.py +7 -8
.gitignore
CHANGED
@@ -1,3 +1,9 @@
|
|
1 |
.env
|
2 |
|
3 |
-
.venv
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
.env
|
2 |
|
3 |
+
.venv
|
4 |
+
|
5 |
+
__pycache__
|
6 |
+
|
7 |
+
.vscode
|
8 |
+
|
9 |
+
.idea
|
__pycache__/app.cpython-310.pyc
DELETED
Binary file (3.23 kB)
|
|
app.py
CHANGED
@@ -61,11 +61,10 @@ def get_model_response(messages):
|
|
61 |
)
|
62 |
|
63 |
def respond(message, history, system_message):
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
conversation.append({"role": "user", "content": message})
|
69 |
|
70 |
available_functions = {
|
71 |
"evaluate_math_expression": evaluate_math_expression,
|
@@ -73,9 +72,9 @@ def respond(message, history, system_message):
|
|
73 |
|
74 |
function_calls = []
|
75 |
while True:
|
76 |
-
response = get_model_response(conversation)
|
77 |
response_message = response.choices[0].message
|
78 |
-
conversation.append(response_message)
|
79 |
|
80 |
if not response_message.tool_calls and response_message.content is not None:
|
81 |
break
|
@@ -88,7 +87,7 @@ def respond(message, history, system_message):
|
|
88 |
}
|
89 |
function_calls.append(function_call)
|
90 |
function_response = call_function(tool_call, available_functions)
|
91 |
-
conversation.append(function_response)
|
92 |
function_calls.append({
|
93 |
"name": function_response["name"],
|
94 |
"result": json.loads(function_response["content"])
|
|
|
61 |
)
|
62 |
|
63 |
def respond(message, history, system_message):
|
64 |
+
if not hasattr(respond, 'conversation'):
|
65 |
+
respond.conversation = [{"role": "system", "content": system_message}]
|
66 |
+
|
67 |
+
respond.conversation.append({"role": "user", "content": message})
|
|
|
68 |
|
69 |
available_functions = {
|
70 |
"evaluate_math_expression": evaluate_math_expression,
|
|
|
72 |
|
73 |
function_calls = []
|
74 |
while True:
|
75 |
+
response = get_model_response(respond.conversation)
|
76 |
response_message = response.choices[0].message
|
77 |
+
respond.conversation.append(response_message)
|
78 |
|
79 |
if not response_message.tool_calls and response_message.content is not None:
|
80 |
break
|
|
|
87 |
}
|
88 |
function_calls.append(function_call)
|
89 |
function_response = call_function(tool_call, available_functions)
|
90 |
+
respond.conversation.append(function_response)
|
91 |
function_calls.append({
|
92 |
"name": function_response["name"],
|
93 |
"result": json.loads(function_response["content"])
|