Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -136,8 +136,8 @@ def execute_tool_call(tool_call):
|
|
136 |
def execute_tool_calls(run_steps):
|
137 |
run_step_details = []
|
138 |
|
139 |
-
tool_call_id =
|
140 |
-
tool_call_result =
|
141 |
|
142 |
for step in run_steps.data:
|
143 |
step_details = step.step_details
|
@@ -149,8 +149,8 @@ def execute_tool_calls(run_steps):
|
|
149 |
show_json("tool_call", tool_call)
|
150 |
|
151 |
if hasattr(tool_call, "function"):
|
152 |
-
tool_call_id
|
153 |
-
tool_call_result
|
154 |
|
155 |
return tool_call_id, tool_call_result
|
156 |
|
@@ -200,7 +200,7 @@ def chat(message, history):
|
|
200 |
|
201 |
### TODO
|
202 |
if tool_call_id:
|
203 |
-
print(
|
204 |
print(tool_call_result.to_json())
|
205 |
|
206 |
# https://platform.openai.com/docs/api-reference/runs/submitToolOutputs
|
@@ -210,36 +210,14 @@ def chat(message, history):
|
|
210 |
tool_outputs=[
|
211 |
{
|
212 |
"tool_call_id": tool_call_id,
|
213 |
-
"output": tool_call_result
|
214 |
}
|
215 |
]
|
216 |
)
|
217 |
|
218 |
run = wait_on_run(client, thread, run)
|
219 |
run_steps = get_run_steps(client, thread, run)
|
220 |
-
tool_call_id, tool_call_result = execute_tool_calls(run_steps)
|
221 |
-
###
|
222 |
-
"""
|
223 |
-
if tool_call_id:
|
224 |
-
print("### tool_call_id=" + tool_call_id)
|
225 |
-
print(tool_call_result)
|
226 |
-
|
227 |
-
# https://platform.openai.com/docs/api-reference/runs/submitToolOutputs
|
228 |
-
run = client.beta.threads.runs.submit_tool_outputs(
|
229 |
-
thread_id=thread.id,
|
230 |
-
run_id=run.id,
|
231 |
-
tool_outputs=[
|
232 |
-
{
|
233 |
-
"tool_call_id": tool_call_id,
|
234 |
-
"output": tool_call_result.to_json()
|
235 |
-
}
|
236 |
-
]
|
237 |
-
)
|
238 |
-
|
239 |
-
run = wait_on_run(client, thread, run)
|
240 |
-
run_steps = get_run_steps(client, thread, run)
|
241 |
-
tool_call_id, tool_call_result = execute_tool_calls(run_steps)
|
242 |
-
"""
|
243 |
###
|
244 |
|
245 |
messages = get_messages(client, thread)
|
|
|
136 |
def execute_tool_calls(run_steps):
|
137 |
run_step_details = []
|
138 |
|
139 |
+
tool_call_id = []
|
140 |
+
tool_call_result = []
|
141 |
|
142 |
for step in run_steps.data:
|
143 |
step_details = step.step_details
|
|
|
149 |
show_json("tool_call", tool_call)
|
150 |
|
151 |
if hasattr(tool_call, "function"):
|
152 |
+
tool_call_id.append(tool_call.id)
|
153 |
+
tool_call_result.append(execute_tool_call(tool_call))
|
154 |
|
155 |
return tool_call_id, tool_call_result
|
156 |
|
|
|
200 |
|
201 |
### TODO
|
202 |
if tool_call_id:
|
203 |
+
print(tool_call_id)
|
204 |
print(tool_call_result.to_json())
|
205 |
|
206 |
# https://platform.openai.com/docs/api-reference/runs/submitToolOutputs
|
|
|
210 |
tool_outputs=[
|
211 |
{
|
212 |
"tool_call_id": tool_call_id,
|
213 |
+
"output": tool_call_result
|
214 |
}
|
215 |
]
|
216 |
)
|
217 |
|
218 |
run = wait_on_run(client, thread, run)
|
219 |
run_steps = get_run_steps(client, thread, run)
|
220 |
+
#tool_call_id, tool_call_result = execute_tool_calls(run_steps)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
221 |
###
|
222 |
|
223 |
messages = get_messages(client, thread)
|