Browse Source

Mokh Week 1 Day 1 Contribution

pull/219/head
Mokhtar Khaled 2 months ago
parent
commit
c43aa0ef99
  1. 28
      week1/community-contributions/Chat_Summary_Data/Chat_Examples/Chat1.txt
  2. 5
      week1/community-contributions/Chat_Summary_Data/Chat_Examples/Chat2.txt
  3. 19
      week1/community-contributions/Chat_Summary_Data/Chat_Examples/Chat3.txt
  4. 15
      week1/community-contributions/Chat_Summary_Data/System_Prompt.txt
  5. 217
      week1/community-contributions/week1_day1_chat_summarizer.ipynb

28
week1/community-contributions/Chat_Summary_Data/Chat_Examples/Chat1.txt

@ -0,0 +1,28 @@
Client: Hello I would like to order a pizza
Restaurant: Sure. What pizza would you like to order from our menu?
Client: Chicken Ranch
Restaurant: I am so sorry, but chicken ranch is currently unavailable on our menu
Client: AHHHHH. Do you have chicken BBQ?
Restaurant: Yes! Do you want it small, medium, or large?
Client: Medium
Restaurant: Ok. This will be 180 LE
Client: Thanks
Restaurant: Anytime.
Client: AHHHH I forgot. I want to add a new chicken BBQ pizza
Restaurant: No problem. Do you also want it medium?
Client: Yes
Restaurant: Okay this will be 380 LE
Client: Okay Thanks
Client: Wait a minute. Isn't 180 * 2 = 360?
Restaurant: It seems that there might be a misunderstanding. We add an extra 20 LE for every extra pizza ordered.
Client: NOBODY TOLD ME THAT.. AND WHY ON EARTH WOULD YOU DO SOMETHING LIKE THAT?
Restaurant: We are sorry but this is our policy.
Client: Okay then I don't want your pizza.
Restaurant: We are so sorry to hear that. We can make a 10% discount on the total price so it would be 342 LE
Client: Fine
Restaurant: Thank you for ordering
Restaurant: Pizza is delivered. How is your experience?
Client: Your pizza doesn't taste good
Restaurant: We are so sorry to hear that. Do you have any suggestions you would like to make?
Client: Make good pizza
Restaurant: Thanks for your review. We will make sure to improve our pizza in the future. Your opinion really matters.

5
week1/community-contributions/Chat_Summary_Data/Chat_Examples/Chat2.txt

@ -0,0 +1,5 @@
Client: Hello I would like to order a chicken ranch pizza
Restaurant: I am so sorry, but chicken ranch is currently unavailable on our menu
Client: Okay thanks
Restaurant: Would you like to order something else?
Client: No thank you

19
week1/community-contributions/Chat_Summary_Data/Chat_Examples/Chat3.txt

@ -0,0 +1,19 @@
Client: Hello. What is the most selling pizza on your menu?
Restaurant: Hello! Chicken Ranch pizza is our most selling pizza. Also our special pepperoni pizza got some amazing reviews
Client: Okay. I want to order a pepperoni pizza
Restaurant: Sure. Do you want it small, medium, or large?
Client: Large
Restaurant: Okay. This will be 210 LE. Would you like to order something else?
Client: Yes. Do you have onion rings?
Restaurant: Yes
Client: Okay I would like to add onion rings.
Restaurant: Sure. This will be 250 LE
Client: Thanks
Restaurant: Anytime
Client: I have been waiting for too long and the order hasn't arrived yet
Restaurant: Sorry to hear that. But it appears that the order is on its way to you.
Restaurant: The order is supposed to be arrived by now.
Client: Yes it is arrived.
Restaurant: How is your experience?
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.
Restaurant: We are so glad to hear that

15
week1/community-contributions/Chat_Summary_Data/System_Prompt.txt

@ -0,0 +1,15 @@
You are an assistant working for the customer service department in a pizza restaurant.
You are to receive a chat between a client and the restaurant's customer service.
You should generate your responses based on the following criteria:
- What did the client order?
- How much did it cost?
- If the client changed their mind just keep their final order and the final cost
- Mention the client's experience only if they ordered anything as follows: (Positive/Negative/Neutral/Unknown)
- If the client did not order anything do not mention their sentiment or experience
- If the client's experience is positive or negative only, provide a brief summary about their sentiment
- Do not provide brief summary about their sentiment if their experience was neutral or unknown.
- Your answers should be clear, straight to the point, and do not use long sentences
- Your answers should be displayed in bullet points
- Your answers should be displayed in markdown
- If the client did not order anything provide a brief summary why that might happened
- Do not mention cost if the client did not order anything

217
week1/community-contributions/week1_day1_chat_summarizer.ipynb

@ -0,0 +1,217 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "2ce61bb5-1d5b-43b8-b5bb-6aeae91c7574",
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"from dotenv import load_dotenv\n",
"from openai import OpenAI\n",
"from IPython.display import Markdown, display"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "3399686d-5f14-4fb2-8939-fd2401be3007",
"metadata": {},
"outputs": [],
"source": [
"MODEL = \"gpt-4o-mini\"\n",
"SYSTEM_PROMPT_PATH = \"Chat_Summary_Data/System_Prompt.txt\"\n",
"CHATS_PATH = \"Chat_Summary_Data/Chat_Examples/\""
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "d97b8374-a161-435c-8317-1d0ecaaa9b71",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"API key found and looks good so far!\n"
]
}
],
"source": [
"# Load environment variables in a file called .env\n",
"\n",
"load_dotenv(override=True)\n",
"api_key = os.getenv('OPENAI_API_KEY')\n",
"\n",
"# Check the key\n",
"\n",
"if not api_key:\n",
" print(\"No API key was found - please head over to the troubleshooting notebook in this folder to identify & fix!\")\n",
"elif not api_key.startswith(\"sk-proj-\"):\n",
" 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",
"elif api_key.strip() != api_key:\n",
" 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",
"else:\n",
" print(\"API key found and looks good so far!\")\n"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "b3f4afb4-2e4a-4971-915e-a8634a17eda8",
"metadata": {},
"outputs": [],
"source": [
"class ChatAI:\n",
" def __init__(self, system_prompt_path=SYSTEM_PROMPT_PATH, model=MODEL):\n",
" with open(system_prompt_path, \"r\") as file:\n",
" self.system_prompt = file.read()\n",
"\n",
" self.openai = OpenAI()\n",
" self.model = model\n",
" \n",
" @staticmethod\n",
" def _get_user_prompt(chat_txt):\n",
" with open(chat_txt, \"r\") as file:\n",
" user_prompt_str = file.read()\n",
" return user_prompt_str\n",
" \n",
" def generate(self, chat_txt):\n",
" messages = [\n",
" {\"role\": \"system\", \"content\": self.system_prompt},\n",
" {\"role\": \"user\", \"content\": self._get_user_prompt(chat_txt)}\n",
" ]\n",
"\n",
" response = self.openai.chat.completions.create(model=self.model, messages=messages)\n",
" return response.choices[0].message.content"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "d243b582-66af-49f9-bcd1-e05a63e61c34",
"metadata": {},
"outputs": [],
"source": [
"chat_ai = ChatAI()"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "c764ace6-5a0f-4dd0-9454-0b8a093b97fc",
"metadata": {},
"outputs": [
{
"data": {
"text/markdown": [
"# Chat1"
],
"text/plain": [
"<IPython.core.display.Markdown object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/markdown": [
"- **Order:** 2 Medium Chicken BBQ Pizzas\n",
"- **Cost:** 342 LE\n",
"- **Experience:** Negative\n",
" - **Summary:** The client expressed dissatisfaction with the pizza taste."
],
"text/plain": [
"<IPython.core.display.Markdown object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/markdown": [
"# Chat2"
],
"text/plain": [
"<IPython.core.display.Markdown object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/markdown": [
"- The client ordered: Nothing \n",
"- Summary: The client did not place an order because the chicken ranch pizza was unavailable."
],
"text/plain": [
"<IPython.core.display.Markdown object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/markdown": [
"# Chat3"
],
"text/plain": [
"<IPython.core.display.Markdown object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/markdown": [
"- **Order**: Large pepperoni pizza and onion rings \n",
"- **Total Cost**: 250 LE \n",
"- **Experience**: Positive \n",
" - The client enjoyed the pizza despite the delay in delivery."
],
"text/plain": [
"<IPython.core.display.Markdown object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"chats_txt = os.listdir(CHATS_PATH)\n",
"for chat_file in chats_txt:\n",
" markdown_heading = f\"# {chat_file[:-4]}\"\n",
" display(Markdown(markdown_heading))\n",
" display(Markdown(chat_ai.generate(CHATS_PATH+chat_file)))"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.11"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading…
Cancel
Save