Skip to content

Commit 79dc694

Browse files
authored
Merge pull request ed-donner#219 from mokhtar77777/mokh_week1_day1
Mokh Week 1 Day 1 Contribution
2 parents 270a93e + c43aa0e commit 79dc694

File tree

5 files changed

+284
-0
lines changed

5 files changed

+284
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
Client: Hello I would like to order a pizza
2+
Restaurant: Sure. What pizza would you like to order from our menu?
3+
Client: Chicken Ranch
4+
Restaurant: I am so sorry, but chicken ranch is currently unavailable on our menu
5+
Client: AHHHHH. Do you have chicken BBQ?
6+
Restaurant: Yes! Do you want it small, medium, or large?
7+
Client: Medium
8+
Restaurant: Ok. This will be 180 LE
9+
Client: Thanks
10+
Restaurant: Anytime.
11+
Client: AHHHH I forgot. I want to add a new chicken BBQ pizza
12+
Restaurant: No problem. Do you also want it medium?
13+
Client: Yes
14+
Restaurant: Okay this will be 380 LE
15+
Client: Okay Thanks
16+
Client: Wait a minute. Isn't 180 * 2 = 360?
17+
Restaurant: It seems that there might be a misunderstanding. We add an extra 20 LE for every extra pizza ordered.
18+
Client: NOBODY TOLD ME THAT.. AND WHY ON EARTH WOULD YOU DO SOMETHING LIKE THAT?
19+
Restaurant: We are sorry but this is our policy.
20+
Client: Okay then I don't want your pizza.
21+
Restaurant: We are so sorry to hear that. We can make a 10% discount on the total price so it would be 342 LE
22+
Client: Fine
23+
Restaurant: Thank you for ordering
24+
Restaurant: Pizza is delivered. How is your experience?
25+
Client: Your pizza doesn't taste good
26+
Restaurant: We are so sorry to hear that. Do you have any suggestions you would like to make?
27+
Client: Make good pizza
28+
Restaurant: Thanks for your review. We will make sure to improve our pizza in the future. Your opinion really matters.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Client: Hello I would like to order a chicken ranch pizza
2+
Restaurant: I am so sorry, but chicken ranch is currently unavailable on our menu
3+
Client: Okay thanks
4+
Restaurant: Would you like to order something else?
5+
Client: No thank you
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Client: Hello. What is the most selling pizza on your menu?
2+
Restaurant: Hello! Chicken Ranch pizza is our most selling pizza. Also our special pepperoni pizza got some amazing reviews
3+
Client: Okay. I want to order a pepperoni pizza
4+
Restaurant: Sure. Do you want it small, medium, or large?
5+
Client: Large
6+
Restaurant: Okay. This will be 210 LE. Would you like to order something else?
7+
Client: Yes. Do you have onion rings?
8+
Restaurant: Yes
9+
Client: Okay I would like to add onion rings.
10+
Restaurant: Sure. This will be 250 LE
11+
Client: Thanks
12+
Restaurant: Anytime
13+
Client: I have been waiting for too long and the order hasn't arrived yet
14+
Restaurant: Sorry to hear that. But it appears that the order is on its way to you.
15+
Restaurant: The order is supposed to be arrived by now.
16+
Client: Yes it is arrived.
17+
Restaurant: How is your experience?
18+
Client: Your pizza tastes soooooo good. The order took too long to arrive but when I tasted the pizza, I was really enjoying it and forgot everything about the delay.
19+
Restaurant: We are so glad to hear that
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
You are an assistant working for the customer service department in a pizza restaurant.
2+
You are to receive a chat between a client and the restaurant's customer service.
3+
You should generate your responses based on the following criteria:
4+
- What did the client order?
5+
- How much did it cost?
6+
- If the client changed their mind just keep their final order and the final cost
7+
- Mention the client's experience only if they ordered anything as follows: (Positive/Negative/Neutral/Unknown)
8+
- If the client did not order anything do not mention their sentiment or experience
9+
- If the client's experience is positive or negative only, provide a brief summary about their sentiment
10+
- Do not provide brief summary about their sentiment if their experience was neutral or unknown.
11+
- Your answers should be clear, straight to the point, and do not use long sentences
12+
- Your answers should be displayed in bullet points
13+
- Your answers should be displayed in markdown
14+
- If the client did not order anything provide a brief summary why that might happened
15+
- Do not mention cost if the client did not order anything
Lines changed: 217 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,217 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 1,
6+
"id": "2ce61bb5-1d5b-43b8-b5bb-6aeae91c7574",
7+
"metadata": {},
8+
"outputs": [],
9+
"source": [
10+
"import os\n",
11+
"from dotenv import load_dotenv\n",
12+
"from openai import OpenAI\n",
13+
"from IPython.display import Markdown, display"
14+
]
15+
},
16+
{
17+
"cell_type": "code",
18+
"execution_count": 2,
19+
"id": "3399686d-5f14-4fb2-8939-fd2401be3007",
20+
"metadata": {},
21+
"outputs": [],
22+
"source": [
23+
"MODEL = \"gpt-4o-mini\"\n",
24+
"SYSTEM_PROMPT_PATH = \"Chat_Summary_Data/System_Prompt.txt\"\n",
25+
"CHATS_PATH = \"Chat_Summary_Data/Chat_Examples/\""
26+
]
27+
},
28+
{
29+
"cell_type": "code",
30+
"execution_count": 3,
31+
"id": "d97b8374-a161-435c-8317-1d0ecaaa9b71",
32+
"metadata": {},
33+
"outputs": [
34+
{
35+
"name": "stdout",
36+
"output_type": "stream",
37+
"text": [
38+
"API key found and looks good so far!\n"
39+
]
40+
}
41+
],
42+
"source": [
43+
"# Load environment variables in a file called .env\n",
44+
"\n",
45+
"load_dotenv(override=True)\n",
46+
"api_key = os.getenv('OPENAI_API_KEY')\n",
47+
"\n",
48+
"# Check the key\n",
49+
"\n",
50+
"if not api_key:\n",
51+
" print(\"No API key was found - please head over to the troubleshooting notebook in this folder to identify & fix!\")\n",
52+
"elif not api_key.startswith(\"sk-proj-\"):\n",
53+
" print(\"An API key was found, but it doesn't start sk-proj-; please check you're using the right key - see troubleshooting notebook\")\n",
54+
"elif api_key.strip() != api_key:\n",
55+
" print(\"An API key was found, but it looks like it might have space or tab characters at the start or end - please remove them - see troubleshooting notebook\")\n",
56+
"else:\n",
57+
" print(\"API key found and looks good so far!\")\n"
58+
]
59+
},
60+
{
61+
"cell_type": "code",
62+
"execution_count": 4,
63+
"id": "b3f4afb4-2e4a-4971-915e-a8634a17eda8",
64+
"metadata": {},
65+
"outputs": [],
66+
"source": [
67+
"class ChatAI:\n",
68+
" def __init__(self, system_prompt_path=SYSTEM_PROMPT_PATH, model=MODEL):\n",
69+
" with open(system_prompt_path, \"r\") as file:\n",
70+
" self.system_prompt = file.read()\n",
71+
"\n",
72+
" self.openai = OpenAI()\n",
73+
" self.model = model\n",
74+
" \n",
75+
" @staticmethod\n",
76+
" def _get_user_prompt(chat_txt):\n",
77+
" with open(chat_txt, \"r\") as file:\n",
78+
" user_prompt_str = file.read()\n",
79+
" return user_prompt_str\n",
80+
" \n",
81+
" def generate(self, chat_txt):\n",
82+
" messages = [\n",
83+
" {\"role\": \"system\", \"content\": self.system_prompt},\n",
84+
" {\"role\": \"user\", \"content\": self._get_user_prompt(chat_txt)}\n",
85+
" ]\n",
86+
"\n",
87+
" response = self.openai.chat.completions.create(model=self.model, messages=messages)\n",
88+
" return response.choices[0].message.content"
89+
]
90+
},
91+
{
92+
"cell_type": "code",
93+
"execution_count": 5,
94+
"id": "d243b582-66af-49f9-bcd1-e05a63e61c34",
95+
"metadata": {},
96+
"outputs": [],
97+
"source": [
98+
"chat_ai = ChatAI()"
99+
]
100+
},
101+
{
102+
"cell_type": "code",
103+
"execution_count": 8,
104+
"id": "c764ace6-5a0f-4dd0-9454-0b8a093b97fc",
105+
"metadata": {},
106+
"outputs": [
107+
{
108+
"data": {
109+
"text/markdown": [
110+
"# Chat1"
111+
],
112+
"text/plain": [
113+
"<IPython.core.display.Markdown object>"
114+
]
115+
},
116+
"metadata": {},
117+
"output_type": "display_data"
118+
},
119+
{
120+
"data": {
121+
"text/markdown": [
122+
"- **Order:** 2 Medium Chicken BBQ Pizzas\n",
123+
"- **Cost:** 342 LE\n",
124+
"- **Experience:** Negative\n",
125+
" - **Summary:** The client expressed dissatisfaction with the pizza taste."
126+
],
127+
"text/plain": [
128+
"<IPython.core.display.Markdown object>"
129+
]
130+
},
131+
"metadata": {},
132+
"output_type": "display_data"
133+
},
134+
{
135+
"data": {
136+
"text/markdown": [
137+
"# Chat2"
138+
],
139+
"text/plain": [
140+
"<IPython.core.display.Markdown object>"
141+
]
142+
},
143+
"metadata": {},
144+
"output_type": "display_data"
145+
},
146+
{
147+
"data": {
148+
"text/markdown": [
149+
"- The client ordered: Nothing \n",
150+
"- Summary: The client did not place an order because the chicken ranch pizza was unavailable."
151+
],
152+
"text/plain": [
153+
"<IPython.core.display.Markdown object>"
154+
]
155+
},
156+
"metadata": {},
157+
"output_type": "display_data"
158+
},
159+
{
160+
"data": {
161+
"text/markdown": [
162+
"# Chat3"
163+
],
164+
"text/plain": [
165+
"<IPython.core.display.Markdown object>"
166+
]
167+
},
168+
"metadata": {},
169+
"output_type": "display_data"
170+
},
171+
{
172+
"data": {
173+
"text/markdown": [
174+
"- **Order**: Large pepperoni pizza and onion rings \n",
175+
"- **Total Cost**: 250 LE \n",
176+
"- **Experience**: Positive \n",
177+
" - The client enjoyed the pizza despite the delay in delivery."
178+
],
179+
"text/plain": [
180+
"<IPython.core.display.Markdown object>"
181+
]
182+
},
183+
"metadata": {},
184+
"output_type": "display_data"
185+
}
186+
],
187+
"source": [
188+
"chats_txt = os.listdir(CHATS_PATH)\n",
189+
"for chat_file in chats_txt:\n",
190+
" markdown_heading = f\"# {chat_file[:-4]}\"\n",
191+
" display(Markdown(markdown_heading))\n",
192+
" display(Markdown(chat_ai.generate(CHATS_PATH+chat_file)))"
193+
]
194+
}
195+
],
196+
"metadata": {
197+
"kernelspec": {
198+
"display_name": "Python 3 (ipykernel)",
199+
"language": "python",
200+
"name": "python3"
201+
},
202+
"language_info": {
203+
"codemirror_mode": {
204+
"name": "ipython",
205+
"version": 3
206+
},
207+
"file_extension": ".py",
208+
"mimetype": "text/x-python",
209+
"name": "python",
210+
"nbconvert_exporter": "python",
211+
"pygments_lexer": "ipython3",
212+
"version": "3.11.11"
213+
}
214+
},
215+
"nbformat": 4,
216+
"nbformat_minor": 5
217+
}

0 commit comments

Comments
 (0)