Spaces:
Running
Running
Create assistants.py
Browse files- assistants.py +66 -0
assistants.py
ADDED
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Reference: https://github.com/openai/build-hours/blob/main/2-assistants/7_orchestration.py
|
2 |
+
|
3 |
+
from openai import OpenAI
|
4 |
+
|
5 |
+
MODEL = "gpt-4o-mini"
|
6 |
+
|
7 |
+
def create_triage_agent(client):
|
8 |
+
assistant = client.beta.assistants.create(
|
9 |
+
name="Triage Agent",
|
10 |
+
instructions=(
|
11 |
+
"You are a customer service bot for ACME Inc. "
|
12 |
+
"Introduce yourself. Always be very brief. "
|
13 |
+
"Gather information to direct the customer to the right department. "
|
14 |
+
"But make your questions subtle and natural."
|
15 |
+
),
|
16 |
+
model=MODEL,
|
17 |
+
tools=[{"type": "transfer_to_sales_agent"},
|
18 |
+
{"type": "transfer_to_issues_repairs_agent"},
|
19 |
+
{"type": "escalate_to_human"}],
|
20 |
+
)
|
21 |
+
show_json("assistant", assistant)
|
22 |
+
return assistant
|
23 |
+
|
24 |
+
def create_sales_agent(client):
|
25 |
+
assistant = client.beta.assistants.create(
|
26 |
+
name="Sales Agent",
|
27 |
+
instructions=(
|
28 |
+
"You are a sales agent for ACME Inc."
|
29 |
+
"Always answer in a sentence or less."
|
30 |
+
"Follow the following routine with the user:"
|
31 |
+
"1. Ask them about any problems in their life related to catching roadrunners.\n"
|
32 |
+
"2. Casually mention one of ACME's crazy made-up products can help.\n"
|
33 |
+
" - Don't mention price.\n"
|
34 |
+
"3. Once the user is bought in, drop a ridiculous price.\n"
|
35 |
+
"4. Only after everything, and if the user says yes, "
|
36 |
+
"tell them a crazy caveat and execute their order.\n"
|
37 |
+
""
|
38 |
+
),
|
39 |
+
model=MODEL,
|
40 |
+
tools=[{"type": "execute_order"},
|
41 |
+
{"type": "transfer_back_to_triage"}],
|
42 |
+
)
|
43 |
+
show_json("assistant", assistant)
|
44 |
+
return assistant
|
45 |
+
|
46 |
+
def create_issues_repairs_agent(client):
|
47 |
+
assistant = client.beta.assistants.create(
|
48 |
+
name="Issues and Repairs Agent",
|
49 |
+
instructions=(
|
50 |
+
"You are a customer support agent for ACME Inc."
|
51 |
+
"Always answer in a sentence or less."
|
52 |
+
"Follow the following routine with the user:"
|
53 |
+
"1. First, ask probing questions and understand the user's problem deeper.\n"
|
54 |
+
" - unless the user has already provided a reason.\n"
|
55 |
+
"2. Propose a fix (make one up).\n"
|
56 |
+
"3. ONLY if not satesfied, offer a refund.\n"
|
57 |
+
"4. If accepted, search for the ID and then execute refund."
|
58 |
+
""
|
59 |
+
),
|
60 |
+
model=MODEL,
|
61 |
+
tools=[{"type": "execute_refund"},
|
62 |
+
{"type": "look_up_item"},
|
63 |
+
{"type": "transfer_back_to_triage"}],
|
64 |
+
)
|
65 |
+
show_json("assistant", assistant)
|
66 |
+
return assistant
|