bstraehle commited on
Commit
56bb047
1 Parent(s): e19371c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -25
app.py CHANGED
@@ -104,9 +104,9 @@ def create_sales_agent(client):
104
  return client.beta.assistants.create(
105
  name="Sales Agent",
106
  instructions=(
107
- "You are a sales agent for ACME Inc."
108
- "Always answer in a sentence or less."
109
- "Follow the following routine with the user:"
110
  "1. Ask them about any problems in their life related to catching roadrunners.\n"
111
  "2. Casually mention one of ACME's crazy made-up products can help.\n"
112
  " - Don't mention price.\n"
@@ -144,7 +144,7 @@ def create_issues_repairs_agent(client):
144
 
145
  def create_thread(client):
146
  thread = client.beta.threads.create()
147
- #show_json("thread", thread)
148
 
149
  return thread
150
 
@@ -154,7 +154,7 @@ def create_message(client, thread, msg):
154
  thread_id=thread.id,
155
  content=msg,
156
  )
157
- #show_json("message", message)
158
 
159
  return message
160
 
@@ -163,7 +163,7 @@ def create_run(client, assistant, thread):
163
  assistant_id=assistant.id,
164
  thread_id=thread.id,
165
  )
166
- #show_json("run", run)
167
 
168
  return run
169
 
@@ -174,7 +174,7 @@ def wait_on_run(client, thread, run):
174
  run_id=run.id,
175
  )
176
  time.sleep(0.25)
177
- #show_json("run", run)
178
 
179
  return run
180
 
@@ -195,10 +195,10 @@ def list_run_steps(client, thread, run):
195
 
196
  for step in run_steps.data:
197
  step_details = step.step_details
198
- #show_json("step_details", step_details)
199
 
200
  if not hasattr(step_details, "tool_calls"):
201
- break
202
 
203
  for tool_call in step_details.tool_calls:
204
  execute_tool_call(tool_call)
@@ -209,7 +209,7 @@ def list_messages(client, thread):
209
  messages = client.beta.threads.messages.list(
210
  thread_id=thread.id
211
  )
212
- #show_json("messages", messages)
213
 
214
  return messages
215
 
@@ -229,26 +229,22 @@ current_agent, current_thread = None, None
229
 
230
  def set_current_agent(agent):
231
  global current_agent
232
- #print("### set_current_agent ###")
233
  current_agent = agent
234
- #show_json("Current Agent", current_agent)
235
 
236
  def set_current_thread(thread):
237
  global current_thread
238
- #print("### set_current_thread ###")
239
  current_thread = thread
240
- #show_json("Current Thread", current_thread)
241
 
242
  def get_current_agent():
243
  global current_agent
244
- #print("### get_current_agent ###")
245
- #show_json("Current Agent", current_agent)
246
  return current_agent
247
 
248
  def get_current_thread():
249
  global current_thread
250
- #print("### get_current_thread ###")
251
- #show_json("Current Thread", current_thread)
252
  return current_thread
253
 
254
  #
@@ -271,30 +267,24 @@ def chat(message, history, openai_api_key):
271
  global client
272
 
273
  assistant = get_current_agent()
274
- show_json("Current Agent", assistant)
275
 
276
  thread = get_current_thread()
277
- show_json("Current Thread", thread)
278
 
279
- #print("111")
280
  create_message(client, thread, message)
281
 
282
  # async
283
  run = create_run(client, assistant, thread)
284
  run = wait_on_run(client, thread, run)
285
 
286
- print("222")
287
  list_run_steps(client, thread, run)
288
 
289
- print("333")
290
  messages = list_messages(client, thread)
291
 
292
- print("444")
293
  return extract_content_values(messages)[0]
294
 
295
  gr.ChatInterface(
296
  chat,
297
- chatbot=gr.Chatbot(height=500),
298
  textbox=gr.Textbox(placeholder="Type here", container=False, scale=7),
299
  title="Multi-Agent Orchestration",
300
  description="Demo using hand-off pattern: triage agent, sales agent, and issues & repairs agent",
 
104
  return client.beta.assistants.create(
105
  name="Sales Agent",
106
  instructions=(
107
+ "You are a sales agent for ACME Inc. "
108
+ "Always answer in a sentence or less. "
109
+ "Follow the following routine with the user: "
110
  "1. Ask them about any problems in their life related to catching roadrunners.\n"
111
  "2. Casually mention one of ACME's crazy made-up products can help.\n"
112
  " - Don't mention price.\n"
 
144
 
145
  def create_thread(client):
146
  thread = client.beta.threads.create()
147
+ show_json("thread", thread)
148
 
149
  return thread
150
 
 
154
  thread_id=thread.id,
155
  content=msg,
156
  )
157
+ show_json("message", message)
158
 
159
  return message
160
 
 
163
  assistant_id=assistant.id,
164
  thread_id=thread.id,
165
  )
166
+ show_json("run", run)
167
 
168
  return run
169
 
 
174
  run_id=run.id,
175
  )
176
  time.sleep(0.25)
177
+ show_json("run", run)
178
 
179
  return run
180
 
 
195
 
196
  for step in run_steps.data:
197
  step_details = step.step_details
198
+ show_json("step_details", step_details)
199
 
200
  if not hasattr(step_details, "tool_calls"):
201
+ continue
202
 
203
  for tool_call in step_details.tool_calls:
204
  execute_tool_call(tool_call)
 
209
  messages = client.beta.threads.messages.list(
210
  thread_id=thread.id
211
  )
212
+ show_json("messages", messages)
213
 
214
  return messages
215
 
 
229
 
230
  def set_current_agent(agent):
231
  global current_agent
 
232
  current_agent = agent
233
+ show_json("Current Agent", current_agent)
234
 
235
  def set_current_thread(thread):
236
  global current_thread
 
237
  current_thread = thread
238
+ show_json("Current Thread", current_thread)
239
 
240
  def get_current_agent():
241
  global current_agent
242
+ show_json("Current Agent", current_agent)
 
243
  return current_agent
244
 
245
  def get_current_thread():
246
  global current_thread
247
+ show_json("Current Thread", current_thread)
 
248
  return current_thread
249
 
250
  #
 
267
  global client
268
 
269
  assistant = get_current_agent()
 
270
 
271
  thread = get_current_thread()
 
272
 
 
273
  create_message(client, thread, message)
274
 
275
  # async
276
  run = create_run(client, assistant, thread)
277
  run = wait_on_run(client, thread, run)
278
 
 
279
  list_run_steps(client, thread, run)
280
 
 
281
  messages = list_messages(client, thread)
282
 
 
283
  return extract_content_values(messages)[0]
284
 
285
  gr.ChatInterface(
286
  chat,
287
+ chatbot=gr.Chatbot(),
288
  textbox=gr.Textbox(placeholder="Type here", container=False, scale=7),
289
  title="Multi-Agent Orchestration",
290
  description="Demo using hand-off pattern: triage agent, sales agent, and issues & repairs agent",