bstraehle commited on
Commit
51df0df
·
verified ·
1 Parent(s): 37a1f88

Update assistants.py

Browse files
Files changed (1) hide show
  1. assistants.py +30 -1
assistants.py CHANGED
@@ -193,4 +193,33 @@ def generate_tool_outputs(tool_call_ids, tool_call_results):
193
  tool_outputs.append(tool_output)
194
 
195
  return tool_outputs
196
- ###
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
193
  tool_outputs.append(tool_output)
194
 
195
  return tool_outputs
196
+ ###
197
+
198
+ def todo(thread, run, run_steps, iteration):
199
+ tool_call_ids, tool_call_results = execute_tool_calls(run_steps)
200
+
201
+ if len(tool_call_ids) > 0:
202
+ # https://platform.openai.com/docs/api-reference/runs/submitToolOutputs
203
+ tool_output = {}
204
+
205
+ try:
206
+ tool_output = {
207
+ "tool_call_id": tool_call_ids[iteration],
208
+ "output": tool_call_results[iteration].to_json()
209
+ }
210
+ except AttributeError:
211
+ tool_output = {
212
+ "tool_call_id": tool_call_ids[iteration],
213
+ "output": tool_call_results[iteration]
214
+ }
215
+
216
+ run = openai_client.beta.threads.runs.submit_tool_outputs(
217
+ thread_id=thread.id,
218
+ run_id=run.id,
219
+ tool_outputs=[tool_output]
220
+ )
221
+
222
+ run = wait_on_run(openai_client, thread, run)
223
+ run_steps = get_run_steps(openai_client, thread, run)
224
+
225
+ todo(thread, run, run_steps, iteration + 1)