Spaces:
Runtime error
Runtime error
ricklamers
commited on
Commit
•
4d5c750
1
Parent(s):
7800b7d
fix: use custom cache
Browse files
app.py
CHANGED
@@ -65,11 +65,14 @@ def get_model_response(messages):
|
|
65 |
print(messages)
|
66 |
return None
|
67 |
|
|
|
|
|
68 |
def respond(message, history, system_message):
|
69 |
-
|
70 |
-
|
|
|
71 |
|
72 |
-
|
73 |
|
74 |
available_functions = {
|
75 |
"evaluate_math_expression": evaluate_math_expression,
|
@@ -77,9 +80,9 @@ def respond(message, history, system_message):
|
|
77 |
|
78 |
function_calls = []
|
79 |
while True:
|
80 |
-
response = get_model_response(
|
81 |
response_message = response.choices[0].message
|
82 |
-
|
83 |
|
84 |
if not response_message.tool_calls and response_message.content is not None:
|
85 |
break
|
@@ -92,7 +95,7 @@ def respond(message, history, system_message):
|
|
92 |
}
|
93 |
function_calls.append(function_call)
|
94 |
function_response = call_function(tool_call, available_functions)
|
95 |
-
|
96 |
function_calls.append({
|
97 |
"name": function_response["name"],
|
98 |
"result": json.loads(function_response["content"])
|
|
|
65 |
print(messages)
|
66 |
return None
|
67 |
|
68 |
+
conversation_cache = {}
|
69 |
+
|
70 |
def respond(message, history, system_message):
|
71 |
+
history_id = id(history)
|
72 |
+
if history_id not in conversation_cache:
|
73 |
+
conversation_cache[history_id] = [{"role": "system", "content": system_message}]
|
74 |
|
75 |
+
conversation_cache[history_id].append({"role": "user", "content": message})
|
76 |
|
77 |
available_functions = {
|
78 |
"evaluate_math_expression": evaluate_math_expression,
|
|
|
80 |
|
81 |
function_calls = []
|
82 |
while True:
|
83 |
+
response = get_model_response(conversation_cache[history_id])
|
84 |
response_message = response.choices[0].message
|
85 |
+
conversation_cache[history_id].append(response_message)
|
86 |
|
87 |
if not response_message.tool_calls and response_message.content is not None:
|
88 |
break
|
|
|
95 |
}
|
96 |
function_calls.append(function_call)
|
97 |
function_response = call_function(tool_call, available_functions)
|
98 |
+
conversation_cache[history_id].append(function_response)
|
99 |
function_calls.append({
|
100 |
"name": function_response["name"],
|
101 |
"result": json.loads(function_response["content"])
|