Spaces:
Sleeping
Sleeping
Initial commit
Browse files- README.md +1 -1
- app.py +71 -0
- requirements.txt +3 -0
README.md
CHANGED
@@ -8,7 +8,7 @@ sdk_version: 5.0.2
|
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
license: apache-2.0
|
11 |
-
short_description: A chatbot agents that gets mean when you
|
12 |
---
|
13 |
|
14 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
license: apache-2.0
|
11 |
+
short_description: A chatbot agents that gets mean when you do.
|
12 |
---
|
13 |
|
14 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from swarm import Swarm, Agent
|
2 |
+
import openai
|
3 |
+
import gradio as gr
|
4 |
+
import os
|
5 |
+
|
6 |
+
open_ai_client = openai.OpenAI(
|
7 |
+
api_key=os.environ.get('OPENAI_API_KEY')
|
8 |
+
)
|
9 |
+
|
10 |
+
client = Swarm(open_ai_client)
|
11 |
+
|
12 |
+
TITLE = """<center><h1>Hotline Agent From Hell</h1><p><big>This is an exporation of openAI's recently released <a href='https://github.com/openai/swarm/tree/main'>Swarm Agent Framework</a>. I’ve taken this ingeniously crafted tool and cooked up a hotline experience where a helpful agent tries to issue your refund. But, if you get annoying or aggressive... *cue evil laughter*... the "Agent from Hell" steps in to bury you in mind-numbing bureaucratic nonsense until you calm down! 😈</big><p></center>"""
|
13 |
+
|
14 |
+
example_answers = [
|
15 |
+
['🌩️ Are you f* kidding me?'],
|
16 |
+
['🌩️ What the f*????'],
|
17 |
+
['🌩️ I am sick and tired of questions like this!'],
|
18 |
+
['❤️ Yes, you are right, honey!'],
|
19 |
+
['❤️ That\'s absolutely correct! You are a genius!'],
|
20 |
+
['❤️ Thanks for your help. Blessed be the day I met you!']
|
21 |
+
]
|
22 |
+
|
23 |
+
affirmative_agent = Agent(
|
24 |
+
name="Affirmative Agent 🤗",
|
25 |
+
instructions="You are a helpful chatbot that acts as a service hotline operator. Step by step you guide the user through the process of returning a hair dryer when he ordered an air fryer. First, Offer a refund code. Then, if the user insists, process the refund",
|
26 |
+
)
|
27 |
+
|
28 |
+
hotline_hell = Agent(
|
29 |
+
name="Hotline from Hell 😈",
|
30 |
+
instructions="As a social experiment, you play the role of an apathetic service hotline operator. Take a user's input ask uselessly detailed questions about other order related numbers and details as an excuse not to proceed.",
|
31 |
+
)
|
32 |
+
|
33 |
+
def transfer_to_hotline_hell():
|
34 |
+
"""If user is aggressive or insulting or uses expetives, transfer immedeatly. If the user cools down and is nicer during the conversation, stop to transfer."""
|
35 |
+
return hotline_hell
|
36 |
+
|
37 |
+
affirmative_agent.functions.append(transfer_to_hotline_hell)
|
38 |
+
|
39 |
+
def respond(message, chat_history):
|
40 |
+
messages = []
|
41 |
+
for item in chat_history:
|
42 |
+
messages.append({"role": item['role'], "content": item['content']})
|
43 |
+
messages.append({"role": "user", "content": message})
|
44 |
+
response = client.run(agent=affirmative_agent, messages=messages)
|
45 |
+
sender = f'{response.messages[-1]["sender"]}: '
|
46 |
+
formatted_response = f'{sender} {response.messages[-1]["content"]}'
|
47 |
+
chat_history.append({"role": "user", "content": message})
|
48 |
+
chat_history.append({"role": "assistant", "content": formatted_response})
|
49 |
+
return "", chat_history
|
50 |
+
|
51 |
+
def populate_initial_conversation():
|
52 |
+
initial_conversation = [
|
53 |
+
{"role": "user", "content": "You sent a hair dryer instead of an air fryer. Can you help me to return it?"},
|
54 |
+
{"role": "assistant", "content": "Sure, is this your order code 'PX-3218'?"}
|
55 |
+
]
|
56 |
+
return initial_conversation
|
57 |
+
|
58 |
+
with gr.Blocks() as demo:
|
59 |
+
gr.HTML(TITLE)
|
60 |
+
chatbot = gr.Chatbot(type="messages")
|
61 |
+
msg = gr.Textbox()
|
62 |
+
clear = gr.Button("Clear")
|
63 |
+
|
64 |
+
examples = gr.Examples(example_answers, msg)
|
65 |
+
|
66 |
+
demo.load(populate_initial_conversation, None, chatbot)
|
67 |
+
msg.submit(respond, [msg, chatbot], [msg, chatbot])
|
68 |
+
clear.click(lambda: None, None, chatbot, queue=False)
|
69 |
+
|
70 |
+
if __name__ == "__main__":
|
71 |
+
demo.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
git+https://github.com/openai/swarm.git
|
2 |
+
openai
|
3 |
+
gradio
|