Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -16,6 +16,7 @@ def transfer_to_triage_agent():
|
|
| 16 |
global triage_agent, triage_thread
|
| 17 |
set_current_agent(triage_agent)
|
| 18 |
set_current_thread(triage_thread)
|
|
|
|
| 19 |
|
| 20 |
def transfer_to_sales_agent():
|
| 21 |
"""Use for anything sales or buying related."""
|
|
@@ -23,6 +24,7 @@ def transfer_to_sales_agent():
|
|
| 23 |
global sales_agent, sales_thread
|
| 24 |
set_current_agent(sales_agent)
|
| 25 |
set_current_thread(sales_thread)
|
|
|
|
| 26 |
|
| 27 |
def transfer_to_issues_repairs_agent():
|
| 28 |
"""Use for issues, repairs, or refunds."""
|
|
@@ -30,6 +32,7 @@ def transfer_to_issues_repairs_agent():
|
|
| 30 |
global issues_repairs_agent, issues_repairs_thread
|
| 31 |
set_current_agent(issues_repairs_agent)
|
| 32 |
set_current_thread(issues_repairs_thread)
|
|
|
|
| 33 |
|
| 34 |
#
|
| 35 |
|
|
@@ -37,7 +40,8 @@ def escalate_to_human(summary):
|
|
| 37 |
"""Only call this if explicitly asked to."""
|
| 38 |
print(f"=> escalate_to_human: summary: {summary}")
|
| 39 |
#exit()
|
| 40 |
-
|
|
|
|
| 41 |
#
|
| 42 |
|
| 43 |
def execute_order(product, price: int):
|
|
@@ -148,9 +152,9 @@ def create_thread(client):
|
|
| 148 |
|
| 149 |
return thread
|
| 150 |
|
| 151 |
-
def create_message(client, thread, msg):
|
| 152 |
message = client.beta.threads.messages.create(
|
| 153 |
-
role=
|
| 154 |
thread_id=thread.id,
|
| 155 |
content=msg,
|
| 156 |
)
|
|
@@ -197,16 +201,18 @@ def execute_tool_call(tool_call):
|
|
| 197 |
return tools[name](**args)
|
| 198 |
|
| 199 |
def execute_tool_calls(steps):
|
|
|
|
|
|
|
| 200 |
for step in steps.data:
|
| 201 |
step_details = step.step_details
|
| 202 |
show_json("step_details", step_details)
|
| 203 |
|
| 204 |
if hasattr(step_details, "tool_calls"):
|
| 205 |
for tool_call in step_details.tool_calls:
|
| 206 |
-
execute_tool_call(tool_call)
|
| 207 |
show_json("tool_call", tool_call)
|
| 208 |
|
| 209 |
-
return
|
| 210 |
|
| 211 |
def list_messages(client, thread):
|
| 212 |
messages = client.beta.threads.messages.list(
|
|
@@ -281,8 +287,11 @@ def chat(message, history, openai_api_key):
|
|
| 281 |
|
| 282 |
steps = list_steps(client, thread, run)
|
| 283 |
|
| 284 |
-
|
| 285 |
-
print(
|
|
|
|
|
|
|
|
|
|
| 286 |
|
| 287 |
messages = list_messages(client, thread)
|
| 288 |
|
|
|
|
| 16 |
global triage_agent, triage_thread
|
| 17 |
set_current_agent(triage_agent)
|
| 18 |
set_current_thread(triage_thread)
|
| 19 |
+
return "transfer_to_triage_agent"
|
| 20 |
|
| 21 |
def transfer_to_sales_agent():
|
| 22 |
"""Use for anything sales or buying related."""
|
|
|
|
| 24 |
global sales_agent, sales_thread
|
| 25 |
set_current_agent(sales_agent)
|
| 26 |
set_current_thread(sales_thread)
|
| 27 |
+
return "transfer_to_sales_agent"
|
| 28 |
|
| 29 |
def transfer_to_issues_repairs_agent():
|
| 30 |
"""Use for issues, repairs, or refunds."""
|
|
|
|
| 32 |
global issues_repairs_agent, issues_repairs_thread
|
| 33 |
set_current_agent(issues_repairs_agent)
|
| 34 |
set_current_thread(issues_repairs_thread)
|
| 35 |
+
return "transfer_to_issues_repairs_agent"
|
| 36 |
|
| 37 |
#
|
| 38 |
|
|
|
|
| 40 |
"""Only call this if explicitly asked to."""
|
| 41 |
print(f"=> escalate_to_human: summary: {summary}")
|
| 42 |
#exit()
|
| 43 |
+
return "escalate_to_human"
|
| 44 |
+
|
| 45 |
#
|
| 46 |
|
| 47 |
def execute_order(product, price: int):
|
|
|
|
| 152 |
|
| 153 |
return thread
|
| 154 |
|
| 155 |
+
def create_message(client, thread, msg, type = "user"):
|
| 156 |
message = client.beta.threads.messages.create(
|
| 157 |
+
role=type,
|
| 158 |
thread_id=thread.id,
|
| 159 |
content=msg,
|
| 160 |
)
|
|
|
|
| 201 |
return tools[name](**args)
|
| 202 |
|
| 203 |
def execute_tool_calls(steps):
|
| 204 |
+
result = ""
|
| 205 |
+
|
| 206 |
for step in steps.data:
|
| 207 |
step_details = step.step_details
|
| 208 |
show_json("step_details", step_details)
|
| 209 |
|
| 210 |
if hasattr(step_details, "tool_calls"):
|
| 211 |
for tool_call in step_details.tool_calls:
|
| 212 |
+
result = execute_tool_call(tool_call)
|
| 213 |
show_json("tool_call", tool_call)
|
| 214 |
|
| 215 |
+
return result
|
| 216 |
|
| 217 |
def list_messages(client, thread):
|
| 218 |
messages = client.beta.threads.messages.list(
|
|
|
|
| 287 |
|
| 288 |
steps = list_steps(client, thread, run)
|
| 289 |
|
| 290 |
+
message = execute_tool_calls(steps)
|
| 291 |
+
print("\n\n\n[" + message + "]\n\n\n")
|
| 292 |
+
|
| 293 |
+
if message != "":
|
| 294 |
+
create_message(client, thread, message, "tool")
|
| 295 |
|
| 296 |
messages = list_messages(client, thread)
|
| 297 |
|