Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -175,17 +175,9 @@ def execute_tool_call(tool_call):
|
|
175 |
name = tool_call.function.name
|
176 |
args = json.loads(tool_call.function.arguments)
|
177 |
|
178 |
-
#print(f"{name}, {args}")
|
179 |
-
|
180 |
global tools
|
181 |
|
182 |
-
|
183 |
-
#print(tools)
|
184 |
-
#print("===")
|
185 |
-
#print(tools[name])
|
186 |
-
#print("===")
|
187 |
-
|
188 |
-
return tools[name](**args)
|
189 |
|
190 |
def list_run_steps(client, thread, run):
|
191 |
run_steps = client.beta.threads.runs.steps.list(
|
@@ -193,6 +185,7 @@ def list_run_steps(client, thread, run):
|
|
193 |
run_id=run.id,
|
194 |
order="asc",
|
195 |
)
|
|
|
196 |
|
197 |
for step in run_steps.data:
|
198 |
step_details = step.step_details
|
@@ -202,8 +195,10 @@ def list_run_steps(client, thread, run):
|
|
202 |
break
|
203 |
|
204 |
for tool_call in step_details.tool_calls:
|
205 |
-
|
206 |
-
|
|
|
|
|
207 |
return run_steps
|
208 |
|
209 |
def list_messages(client, thread):
|
@@ -264,27 +259,31 @@ def chat(message, history, openai_api_key):
|
|
264 |
global client
|
265 |
|
266 |
assistant = get_current_agent()
|
267 |
-
|
268 |
|
269 |
thread = get_current_thread()
|
270 |
-
|
271 |
|
|
|
272 |
create_message(client, thread, message)
|
273 |
|
274 |
# async
|
275 |
run = create_run(client, assistant, thread)
|
276 |
run = wait_on_run(client, thread, run)
|
277 |
|
|
|
278 |
list_run_steps(client, thread, run)
|
279 |
-
|
|
|
280 |
messages = list_messages(client, thread)
|
281 |
-
|
|
|
282 |
return extract_content_values(messages)[0]
|
283 |
|
284 |
gr.ChatInterface(
|
285 |
chat,
|
286 |
-
chatbot=gr.Chatbot(),
|
287 |
-
textbox=gr.Textbox(),
|
288 |
title="Multi-Agent Orchestration",
|
289 |
description="Demo using hand-off pattern: triage agent, sales agent, and issues & repairs agent",
|
290 |
clear_btn=None,
|
|
|
175 |
name = tool_call.function.name
|
176 |
args = json.loads(tool_call.function.arguments)
|
177 |
|
|
|
|
|
178 |
global tools
|
179 |
|
180 |
+
tools[name](**args)
|
|
|
|
|
|
|
|
|
|
|
|
|
181 |
|
182 |
def list_run_steps(client, thread, run):
|
183 |
run_steps = client.beta.threads.runs.steps.list(
|
|
|
185 |
run_id=run.id,
|
186 |
order="asc",
|
187 |
)
|
188 |
+
print("aaa")
|
189 |
|
190 |
for step in run_steps.data:
|
191 |
step_details = step.step_details
|
|
|
195 |
break
|
196 |
|
197 |
for tool_call in step_details.tool_calls:
|
198 |
+
print("bbb")
|
199 |
+
execute_tool_call(tool_call)
|
200 |
+
|
201 |
+
print("ccc")
|
202 |
return run_steps
|
203 |
|
204 |
def list_messages(client, thread):
|
|
|
259 |
global client
|
260 |
|
261 |
assistant = get_current_agent()
|
262 |
+
show_json("Current Agent", assistant)
|
263 |
|
264 |
thread = get_current_thread()
|
265 |
+
show_json("Current Thread", thread)
|
266 |
|
267 |
+
print("111")
|
268 |
create_message(client, thread, message)
|
269 |
|
270 |
# async
|
271 |
run = create_run(client, assistant, thread)
|
272 |
run = wait_on_run(client, thread, run)
|
273 |
|
274 |
+
print("222")
|
275 |
list_run_steps(client, thread, run)
|
276 |
+
|
277 |
+
print("333")
|
278 |
messages = list_messages(client, thread)
|
279 |
+
|
280 |
+
print("444")
|
281 |
return extract_content_values(messages)[0]
|
282 |
|
283 |
gr.ChatInterface(
|
284 |
chat,
|
285 |
+
chatbot=gr.Chatbot(height=300),
|
286 |
+
textbox=gr.Textbox(placeholder="Question", container=False, scale=7),
|
287 |
title="Multi-Agent Orchestration",
|
288 |
description="Demo using hand-off pattern: triage agent, sales agent, and issues & repairs agent",
|
289 |
clear_btn=None,
|