Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -115,23 +115,19 @@ def get_run_steps(client, thread, run):
|
|
115 |
|
116 |
return run_steps
|
117 |
|
118 |
-
###
|
119 |
def execute_tool_call(tool_call):
|
120 |
name = tool_call.function.name
|
121 |
args = json.loads(tool_call.function.arguments)
|
122 |
-
|
123 |
-
print(f"name={name}")
|
124 |
-
print(f"args={args}")
|
125 |
|
126 |
global tools
|
127 |
|
128 |
return tools[name](**args)
|
129 |
-
###
|
130 |
|
131 |
-
def
|
132 |
run_step_details = []
|
133 |
|
134 |
-
|
|
|
135 |
|
136 |
for step in run_steps.data:
|
137 |
step_details = step.step_details
|
@@ -142,12 +138,13 @@ def get_run_step_details(run_steps):
|
|
142 |
if hasattr(step_details, "tool_calls"):
|
143 |
for tool_call in step_details.tool_calls:
|
144 |
show_json("tool_call", tool_call)
|
|
|
145 |
if hasattr(tool_call, "function"):
|
146 |
-
|
147 |
-
|
148 |
###
|
149 |
|
150 |
-
return
|
151 |
|
152 |
def get_messages(client, thread):
|
153 |
messages = client.beta.threads.messages.list(
|
@@ -191,18 +188,19 @@ def chat(message, history):
|
|
191 |
|
192 |
run_steps = get_run_steps(client, thread, run)
|
193 |
|
194 |
-
|
195 |
|
196 |
###
|
197 |
-
if
|
198 |
-
print("###
|
|
|
199 |
run = client.beta.threads.runs.submit_tool_outputs(
|
200 |
thread_id=thread.id,
|
201 |
run_id=run.id,
|
202 |
tool_outputs=[
|
203 |
{
|
204 |
-
"tool_call_id":
|
205 |
-
"output":
|
206 |
}
|
207 |
]
|
208 |
)
|
|
|
115 |
|
116 |
return run_steps
|
117 |
|
|
|
118 |
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 |
|
126 |
+
def execute_tool_calls(run_steps):
|
127 |
run_step_details = []
|
128 |
|
129 |
+
tool_call_id = ""
|
130 |
+
tool_call_result = ""
|
131 |
|
132 |
for step in run_steps.data:
|
133 |
step_details = step.step_details
|
|
|
138 |
if hasattr(step_details, "tool_calls"):
|
139 |
for tool_call in step_details.tool_calls:
|
140 |
show_json("tool_call", tool_call)
|
141 |
+
|
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 |
|
149 |
def get_messages(client, thread):
|
150 |
messages = client.beta.threads.messages.list(
|
|
|
188 |
|
189 |
run_steps = get_run_steps(client, thread, run)
|
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 |
)
|