bstraehle commited on
Commit
7bf3f3d
1 Parent(s): 5fcd91e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -3
app.py CHANGED
@@ -117,8 +117,6 @@ def execute_tool_call(tool_call):
117
  name = tool_call.function.name
118
  args = json.loads(tool_call.function.arguments)
119
 
120
- #global tools
121
-
122
  return tools[name](**args)
123
 
124
  def execute_tool_calls(run_steps):
@@ -165,6 +163,28 @@ def extract_content_values(data):
165
 
166
  return text_values, image_values
167
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
168
  def chat(message, history):
169
  if not message:
170
  raise gr.Error("Message is required.")
@@ -183,7 +203,8 @@ def chat(message, history):
183
  run = wait_on_run(client, thread, run)
184
 
185
  run_steps = get_run_steps(client, thread, run)
186
-
 
187
  tool_call_id, tool_call_result = execute_tool_calls(run_steps)
188
 
189
  ### TODO
@@ -206,6 +227,9 @@ def chat(message, history):
206
  run_steps = get_run_steps(client, thread, run)
207
  tool_call_id, tool_call_result = execute_tool_calls(run_steps)
208
  ###
 
 
 
209
 
210
  messages = get_messages(client, thread)
211
 
 
117
  name = tool_call.function.name
118
  args = json.loads(tool_call.function.arguments)
119
 
 
 
120
  return tools[name](**args)
121
 
122
  def execute_tool_calls(run_steps):
 
163
 
164
  return text_values, image_values
165
 
166
+ def execute_tool_calls_recursive(client, thread, run_steps):
167
+ tool_call_id, tool_call_result = execute_tool_calls(run_steps)
168
+
169
+ if tool_call_result:
170
+ print(f"### tool_call_id={tool_call_id}")
171
+ print(f"### tool_call_result={tool_call_result}")
172
+
173
+ run = client.beta.threads.runs.submit_tool_outputs(
174
+ thread_id=thread.id,
175
+ run_id=run.id,
176
+ tool_outputs=[
177
+ {
178
+ "tool_call_id": tool_call_id,
179
+ "output": tool_call_result
180
+ }
181
+ ]
182
+ )
183
+
184
+ run = wait_on_run(client, thread, run)
185
+ run_steps = get_run_steps(client, thread, run)
186
+ execute_tool_calls_recursive(run_steps, client, thread)
187
+
188
  def chat(message, history):
189
  if not message:
190
  raise gr.Error("Message is required.")
 
203
  run = wait_on_run(client, thread, run)
204
 
205
  run_steps = get_run_steps(client, thread, run)
206
+
207
+ """
208
  tool_call_id, tool_call_result = execute_tool_calls(run_steps)
209
 
210
  ### TODO
 
227
  run_steps = get_run_steps(client, thread, run)
228
  tool_call_id, tool_call_result = execute_tool_calls(run_steps)
229
  ###
230
+ """
231
+
232
+ execute_tool_calls_recursive(client, thread, run_steps)
233
 
234
  messages = get_messages(client, thread)
235