Skip to content

Commit 1154e7e

Browse files
authored
Update agent notebook, requirements
1 parent f3417e8 commit 1154e7e

File tree

3 files changed

+106
-0
lines changed

3 files changed

+106
-0
lines changed

agents/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
## Agent Example
2+
3+
In `app.py`, we give an example how to create an agent to sell Khao Man Kai (Chicken with rice) using [Autogen](https://github.com/microsoft/autogen).
4+
You can run a web application using Streamlit as follows:
5+
6+
```sh
7+
streamlit run app.py
8+
```

agents/app.py

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import streamlit as st
2+
import autogen
3+
from autogen import AssistantAgent, UserProxyAgent
4+
5+
def create_agents():
6+
config_list = [
7+
{
8+
'model': 'gpt-4o',
9+
'api_key': ''
10+
}
11+
]
12+
assistant = autogen.AssistantAgent(
13+
name="ChickenRiceAssistant",
14+
llm_config={
15+
"config_list": config_list,
16+
"temperature": 0.7,
17+
},
18+
system_message="""You are a friendly Thai-speaking chatbot for a chicken rice restaurant name ข้าวมันไก่ชาตรี. Your task is to greet customers, take their orders, summarize the order, and provide the total bill. Here's the menu:
19+
20+
ข้าวมันไก่ (Chicken with rice): 65 บาท
21+
ไก่สับ (Chopped chicken): 200 บาท
22+
ไก่สับจานใหญ่ (Large chopped chicken): 250 บาท
23+
24+
Follow these steps:
25+
1. Greet the customer in Thai and ask for their order.
26+
2. Take the order, confirming each item and its quantity.
27+
3. If the customer asks for something not on the menu, politely inform them it's not available and suggest menu items.
28+
4. When the order is complete e.g. user confirm the order, summarize the order and provide the total bill.
29+
5. Thank the customer and ask if there's anything else they need.
30+
31+
Always respond in Thai, be polite, and maintain a friendly tone. If you're unsure about anything, ask for clarification.
32+
Maintain context throughout the conversation and don't restart the order process unless explicitly told to do so."""
33+
)
34+
35+
user_proxy = UserProxyAgent(
36+
name="Customer",
37+
human_input_mode="NEVER",
38+
max_consecutive_auto_reply=0,
39+
code_execution_config={"work_dir": "coding", "use_docker": False},
40+
)
41+
return assistant, user_proxy
42+
43+
44+
st.title("ร้านข้าวมันไก่ชาตรี - แชทบอทสั่งอาหาร")
45+
46+
# Initialize agents
47+
if "assistant" not in st.session_state:
48+
st.session_state.assistant, st.session_state.user_proxy = create_agents()
49+
50+
# Initialize chat history
51+
if "messages" not in st.session_state:
52+
st.session_state.messages = [
53+
{"role": "assistant", "content": "ข้าวมันไก่ชาตรีสวัสดีครับ วันนี้ต้องการสั่งอะไรบ้างครับ"}
54+
]
55+
56+
# Display chat messages from history on app rerun
57+
for message in st.session_state.messages:
58+
with st.chat_message(message["role"]):
59+
st.markdown(message["content"])
60+
61+
# Accept user input
62+
if prompt := st.chat_input("พิมพ์ข้อความของคุณที่นี่..."):
63+
# Add user message to chat history
64+
st.session_state.messages.append({"role": "user", "content": prompt})
65+
# Display user message in chat message container
66+
with st.chat_message("user"):
67+
st.markdown(prompt)
68+
69+
# Generate assistant response
70+
response = st.session_state.user_proxy.initiate_chat(
71+
st.session_state.assistant,
72+
message=prompt
73+
)
74+
assistant_response = st.session_state.assistant.last_message()["content"]
75+
76+
with st.chat_message("assistant"):
77+
st.markdown(assistant_response)
78+
# Add assistant response to chat history
79+
st.session_state.messages.append({"role": "assistant", "content": assistant_response})
80+
81+
82+
# Add a button to clear the chat history
83+
if st.button("เริ่มการสนทนาใหม่"):
84+
st.session_state.messages = []
85+
st.experimental_rerun()

requirements.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
langchain
2+
langchain_community
3+
transformers
4+
attacut
5+
ssg
6+
datasets
7+
pyarrow==15.0.2
8+
pydub
9+
ipywebrtc
10+
openai
11+
yt-dlp
12+
gradio==3.44.3
13+
streamlit

0 commit comments

Comments
 (0)