bstraehle commited on
Commit
536b36d
1 Parent(s): 10d6c27

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -31
app.py CHANGED
@@ -214,7 +214,7 @@ def chat(message, history):
214
  if not message:
215
  raise gr.Error("Message is required.")
216
 
217
- global client, assistant, thread
218
 
219
  if assistant == None:
220
  assistant = load_assistant(client)
@@ -225,13 +225,13 @@ def chat(message, history):
225
  create_message(client, thread, message)
226
 
227
  run = create_run(client, assistant, thread)
228
- run = wait_on_run(client, thread, run)
229
 
 
230
  run_steps = get_run_steps(client, thread, run)
231
 
 
232
  tool_call_ids, tool_call_results = execute_tool_calls(run_steps)
233
 
234
- ### TODO
235
  print("###")
236
  print(len(tool_call_ids))
237
  print(tool_call_ids)
@@ -257,32 +257,32 @@ def chat(message, history):
257
  run = wait_on_run(client, thread, run)
258
  run_steps = get_run_steps(client, thread, run)
259
  ###
260
- tool_call_ids, tool_call_results = execute_tool_calls(run_steps)
261
-
262
- print("###")
263
- print(len(tool_call_ids))
264
- print(tool_call_ids)
265
- print(tool_call_ids[1])
266
- print(tool_call_results)
267
- print(tool_call_results[1])
268
- print("###")
269
 
270
- if tool_call_ids[1]:
271
- # https://platform.openai.com/docs/api-reference/runs/submitToolOutputs
272
- run = client.beta.threads.runs.submit_tool_outputs(
273
- thread_id=thread.id,
274
- run_id=run.id,
275
- #tool_outputs=generate_tool_outputs(tool_call_ids, tool_call_results)
276
- tool_outputs=[
277
- {
278
- "tool_call_id": tool_call_ids[1],
279
- "output": tool_call_results[1].to_json()
280
- }
281
- ]
282
- )
283
-
284
- run = wait_on_run(client, thread, run)
285
- run_steps = get_run_steps(client, thread, run)
 
 
 
 
 
 
 
 
286
  ###
287
 
288
  messages = get_messages(client, thread)
@@ -304,9 +304,9 @@ gr.ChatInterface(
304
  title="Python Code Generator",
305
  description=(
306
  "The assistant can **generate, explain, fix, optimize, document, and test code**. "
307
- "It can also <b>execute code</b>. "
308
- "It has access to <b>today tool</b> (to get current date) and "
309
- "<b>yfinance download tool</b> (to get stock data)."
310
  ),
311
  clear_btn="Clear",
312
  retry_btn=None,
 
214
  if not message:
215
  raise gr.Error("Message is required.")
216
 
217
+ global assistant, thread
218
 
219
  if assistant == None:
220
  assistant = load_assistant(client)
 
225
  create_message(client, thread, message)
226
 
227
  run = create_run(client, assistant, thread)
 
228
 
229
+ run = wait_on_run(client, thread, run)
230
  run_steps = get_run_steps(client, thread, run)
231
 
232
+ ### TODO
233
  tool_call_ids, tool_call_results = execute_tool_calls(run_steps)
234
 
 
235
  print("###")
236
  print(len(tool_call_ids))
237
  print(tool_call_ids)
 
257
  run = wait_on_run(client, thread, run)
258
  run_steps = get_run_steps(client, thread, run)
259
  ###
260
+ tool_call_ids, tool_call_results = execute_tool_calls(run_steps)
 
 
 
 
 
 
 
 
261
 
262
+ print("###")
263
+ print(len(tool_call_ids))
264
+ print(tool_call_ids)
265
+ print(tool_call_ids[1])
266
+ print(tool_call_results)
267
+ print(tool_call_results[1])
268
+ print("###")
269
+
270
+ if tool_call_ids[1]:
271
+ # https://platform.openai.com/docs/api-reference/runs/submitToolOutputs
272
+ run = client.beta.threads.runs.submit_tool_outputs(
273
+ thread_id=thread.id,
274
+ run_id=run.id,
275
+ #tool_outputs=generate_tool_outputs(tool_call_ids, tool_call_results)
276
+ tool_outputs=[
277
+ {
278
+ "tool_call_id": tool_call_ids[1],
279
+ "output": tool_call_results[1].to_json()
280
+ }
281
+ ]
282
+ )
283
+
284
+ run = wait_on_run(client, thread, run)
285
+ run_steps = get_run_steps(client, thread, run)
286
  ###
287
 
288
  messages = get_messages(client, thread)
 
304
  title="Python Code Generator",
305
  description=(
306
  "The assistant can **generate, explain, fix, optimize, document, and test code**. "
307
+ "It can also **execute code**. "
308
+ "It has access to <b>today tool</b> (get current date) and "
309
+ "to **yfinance download tool** (get stock data)."
310
  ),
311
  clear_btn="Clear",
312
  retry_btn=None,