Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -6,6 +6,80 @@ from agents import get_current_agent, get_current_thread, set_current_agent, set
|
|
6 |
from openai import OpenAI
|
7 |
from utils import show_json
|
8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
#def create_assistant(client):
|
10 |
# assistant = client.beta.assistants.create(
|
11 |
# name="Math Tutor",
|
|
|
6 |
from openai import OpenAI
|
7 |
from utils import show_json
|
8 |
|
9 |
+
###
|
10 |
+
current_agent, current_thread = None, None
|
11 |
+
|
12 |
+
###
|
13 |
+
|
14 |
+
def set_current_agent(agent):
|
15 |
+
current_agent = agent
|
16 |
+
|
17 |
+
def set_current_thread(thread):
|
18 |
+
current_thread = thread
|
19 |
+
|
20 |
+
def get_current_agent():
|
21 |
+
return current_agent
|
22 |
+
|
23 |
+
def get_current_thread():
|
24 |
+
return current_thread
|
25 |
+
|
26 |
+
###
|
27 |
+
|
28 |
+
def transfer_to_sales_agent():
|
29 |
+
"""Use for anything sales or buying related."""
|
30 |
+
current_agent = sales_agent
|
31 |
+
|
32 |
+
def transfer_to_issues_repairs_agent():
|
33 |
+
"""Use for issues, repairs, or refunds."""
|
34 |
+
current_agent = issues_repairs_agent
|
35 |
+
|
36 |
+
def transfer_to_triage_agent():
|
37 |
+
"""Call this if the user brings up a topic outside of your purview,
|
38 |
+
including escalating to human."""
|
39 |
+
current_agent = triage_agent
|
40 |
+
|
41 |
+
###
|
42 |
+
|
43 |
+
def escalate_to_human(summary):
|
44 |
+
"""Only call this if explicitly asked to."""
|
45 |
+
print("Escalating to human agent...")
|
46 |
+
print("\n=== Escalation Report ===")
|
47 |
+
print(f"Summary: {summary}")
|
48 |
+
print("=========================\n")
|
49 |
+
exit()
|
50 |
+
|
51 |
+
###
|
52 |
+
|
53 |
+
def execute_order(product, price: int):
|
54 |
+
"""Price should be in USD."""
|
55 |
+
print("\n\n=== Order Summary ===")
|
56 |
+
print(f"Product: {product}")
|
57 |
+
print(f"Price: ${price}")
|
58 |
+
print("=================\n")
|
59 |
+
confirm = input("Confirm order? y/n: ").strip().lower()
|
60 |
+
if confirm == "y":
|
61 |
+
print("Order execution successful!")
|
62 |
+
return "Success"
|
63 |
+
else:
|
64 |
+
print(color("Order cancelled!", "red"))
|
65 |
+
return "User cancelled order."
|
66 |
+
|
67 |
+
def execute_refund(item_id, reason="not provided"):
|
68 |
+
print("\n\n=== Refund Summary ===")
|
69 |
+
print(f"Item ID: {item_id}")
|
70 |
+
print(f"Reason: {reason}")
|
71 |
+
print("=================\n")
|
72 |
+
print("Refund execution successful!")
|
73 |
+
return "Success"
|
74 |
+
|
75 |
+
def look_up_item(search_query):
|
76 |
+
"""Use to find item ID.
|
77 |
+
Search query can be a description or keywords."""
|
78 |
+
item_id = "item_132612938"
|
79 |
+
print("Found item:", item_id)
|
80 |
+
return item_id
|
81 |
+
###
|
82 |
+
|
83 |
#def create_assistant(client):
|
84 |
# assistant = client.beta.assistants.create(
|
85 |
# name="Math Tutor",
|