bstraehle commited on
Commit
b23aed2
1 Parent(s): 830e356

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -26
app.py CHANGED
@@ -91,6 +91,7 @@ def create_run(client, assistant, thread):
91
 
92
  def wait_on_run(client, thread, run):
93
  while run.status == "queued" or run.status == "in_progress":
 
94
  run = client.beta.threads.runs.retrieve(
95
  thread_id=thread.id,
96
  run_id=run.id,
@@ -163,28 +164,6 @@ def extract_content_values(data):
163
 
164
  return text_values, image_values
165
 
166
- def execute_tool_calls_recursive(client, thread, run, 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(client, thread, run, run_steps)
187
-
188
  def chat(message, history):
189
  if not message:
190
  raise gr.Error("Message is required.")
@@ -204,7 +183,6 @@ def chat(message, history):
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
@@ -212,6 +190,7 @@ def chat(message, history):
212
  print("### tool_call_id=" + tool_call_id)
213
  print("### tool_call_result=" + tool_call_result)
214
 
 
215
  run = client.beta.threads.runs.submit_tool_outputs(
216
  thread_id=thread.id,
217
  run_id=run.id,
@@ -227,9 +206,6 @@ def chat(message, history):
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, run_steps)
233
 
234
  messages = get_messages(client, thread)
235
 
 
91
 
92
  def wait_on_run(client, thread, run):
93
  while run.status == "queued" or run.status == "in_progress":
94
+ print("### " + run.status)
95
  run = client.beta.threads.runs.retrieve(
96
  thread_id=thread.id,
97
  run_id=run.id,
 
164
 
165
  return text_values, image_values
166
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
167
  def chat(message, history):
168
  if not message:
169
  raise gr.Error("Message is required.")
 
183
 
184
  run_steps = get_run_steps(client, thread, run)
185
 
 
186
  tool_call_id, tool_call_result = execute_tool_calls(run_steps)
187
 
188
  ### TODO
 
190
  print("### tool_call_id=" + tool_call_id)
191
  print("### tool_call_result=" + tool_call_result)
192
 
193
+ # https://platform.openai.com/docs/api-reference/runs/submitToolOutputs
194
  run = client.beta.threads.runs.submit_tool_outputs(
195
  thread_id=thread.id,
196
  run_id=run.id,
 
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