bstraehle commited on
Commit
5fcd91e
1 Parent(s): 07a71c9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -18
app.py CHANGED
@@ -2,9 +2,7 @@
2
  #
3
  # 1. Gradio session / multi-user thread
4
  # 2. Function calling - https://platform.openai.com/docs/assistants/tools/function-calling
5
- # - Date tool
6
- # - yfinance
7
- # - Web scraping tool (Tavily API)
8
 
9
  # Reference:
10
  #
@@ -77,7 +75,7 @@ def create_message(client, thread, msg):
77
  content=msg,
78
  )
79
 
80
- show_json("message", message)
81
 
82
  return message
83
 
@@ -119,7 +117,7 @@ def execute_tool_call(tool_call):
119
  name = tool_call.function.name
120
  args = json.loads(tool_call.function.arguments)
121
 
122
- global tools
123
 
124
  return tools[name](**args)
125
 
@@ -131,10 +129,9 @@ def execute_tool_calls(run_steps):
131
 
132
  for step in run_steps.data:
133
  step_details = step.step_details
134
- show_json("step_details", step_details)
135
  run_step_details.append(step_details)
 
136
 
137
- ###
138
  if hasattr(step_details, "tool_calls"):
139
  for tool_call in step_details.tool_calls:
140
  show_json("tool_call", tool_call)
@@ -142,7 +139,6 @@ def execute_tool_calls(run_steps):
142
  if hasattr(tool_call, "function"):
143
  tool_call_id = tool_call.id
144
  tool_call_result = execute_tool_call(tool_call)
145
- ###
146
 
147
  return tool_call_id, tool_call_result
148
 
@@ -190,21 +186,22 @@ def chat(message, history):
190
 
191
  tool_call_id, tool_call_result = execute_tool_calls(run_steps)
192
 
193
- ###
194
  if tool_call_result:
195
  print("### tool_call_id=" + tool_call_id)
196
  print("### tool_call_result=" + tool_call_result)
 
197
  run = client.beta.threads.runs.submit_tool_outputs(
198
- thread_id=thread.id,
199
- run_id=run.id,
200
- tool_outputs=[
201
- {
202
- "tool_call_id": tool_call_id,
203
- "output": tool_call_result
204
- }
205
- ]
206
  )
207
- print(run)
208
  run = wait_on_run(client, thread, run)
209
  run_steps = get_run_steps(client, thread, run)
210
  tool_call_id, tool_call_result = execute_tool_calls(run_steps)
 
2
  #
3
  # 1. Gradio session / multi-user thread
4
  # 2. Function calling - https://platform.openai.com/docs/assistants/tools/function-calling
5
+ # - get_stock_price - yfinance
 
 
6
 
7
  # Reference:
8
  #
 
75
  content=msg,
76
  )
77
 
78
+ #show_json("message", message)
79
 
80
  return message
81
 
 
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
 
 
129
 
130
  for step in run_steps.data:
131
  step_details = step.step_details
 
132
  run_step_details.append(step_details)
133
+ show_json("step_details", step_details)
134
 
 
135
  if hasattr(step_details, "tool_calls"):
136
  for tool_call in step_details.tool_calls:
137
  show_json("tool_call", tool_call)
 
139
  if hasattr(tool_call, "function"):
140
  tool_call_id = tool_call.id
141
  tool_call_result = execute_tool_call(tool_call)
 
142
 
143
  return tool_call_id, tool_call_result
144
 
 
186
 
187
  tool_call_id, tool_call_result = execute_tool_calls(run_steps)
188
 
189
+ ### TODO
190
  if tool_call_result:
191
  print("### tool_call_id=" + tool_call_id)
192
  print("### tool_call_result=" + tool_call_result)
193
+
194
  run = client.beta.threads.runs.submit_tool_outputs(
195
+ thread_id=thread.id,
196
+ run_id=run.id,
197
+ tool_outputs=[
198
+ {
199
+ "tool_call_id": tool_call_id,
200
+ "output": tool_call_result
201
+ }
202
+ ]
203
  )
204
+
205
  run = wait_on_run(client, thread, run)
206
  run_steps = get_run_steps(client, thread, run)
207
  tool_call_id, tool_call_result = execute_tool_calls(run_steps)