Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made the code modular, readable & maintainable #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 45 additions & 9 deletions chatbot_food_service.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,63 @@
# Chat Bot

#chatbot v1.2
#ChangeLog - Made the code more modular, readable and maintainable
# Welcome message
print(" !! Welcome to Customer Service Chatbot !!")
print("Hi there! What type of cuisine are you in the mood for today?\n")

# Dictionary of questions and responses
qna1 = {
"i want pizza": "Today we have a special #deal# for you.\n\n You can get two large pizzas for the price of one. Would you like to take advantage of that offer?\n\n 1.Pizza Margherita\n 2.Quick Tomato Pizzas\n 3.Four Cheese Pizza\n 4.Cheesy Vegetable Pizza\n 5.Tandoori Paneer Pizza\n 6.Thin Crust Hawaiian Pizza\n 7.Uttapam Pizza\n 8.Chocolate Pizza\n 9.Onion Pizza\n 10.Veggie pizza\n\n Which type of Pizza are you in the mood for today?\n Please type the menu number\n",
qna = {
"i want pizza": {
"response": "Today we have a special #deal# for you.\n\nYou can get two large pizzas for the price of one. Would you like to take advantage of that offer?",
"options": {
"1": "Pizza Margherita",
"2": "Quick Tomato Pizzas",
"3": "Four Cheese Pizza",
"4": "Cheesy Vegetable Pizza",
"5": "Tandoori Paneer Pizza",
"6": "Thin Crust Hawaiian Pizza",
"7": "Uttapam Pizza",
"8": "Chocolate Pizza",
"9": "Onion Pizza",
"10": "Veggie pizza"
},
"followup": "Which type of Pizza are you in the mood for today?\nPlease type the menu number",
},
"1 and 7": "Pizza Margherita and Uttapam Pizza, Wonderful choice! Can I have your delivery address, please?",
"mfp, india": "Thank you! Your order will be delivered to Mfp, India. May I have your phone number for any delivery updates?",
"123456": "Thank you! Your order for one Pizza Margherita and one Uttapam Pizza will be delivered to Mfp, India.\n Your total is Rupee 350. Will you be paying with cash or UPI?",
"upi": "Great! I'll send UPI ID for payment. UPI: xxxx2154@xx \n If payment will done please type 'ok'.",
"123456": "Thank you! Your order for one Pizza Margherita and one Uttapam Pizza will be delivered to Mfp, India.\nYour total is Rupee 350. Will you be paying with cash or UPI?",
"upi": "Great! I'll send UPI ID for payment. UPI: xxxx2154@xx\nIf payment will done please type 'ok'.",
"ok": "Thank you for payment. Your order is confirmed, and you should receive it in about 30-40 minutes. Is there anything else I can assist you with?",
"that's all, thank you": "You're welcome! Enjoy your meal, and if you have any other questions in the future, feel free to reach out. \n !! Have a great day !! \n Please type 'exit'"
"that's all, thank you": "You're welcome! Enjoy your meal, and if you have any other questions in the future, feel free to reach out.\n!! Have a great day !!\nPlease type 'exit'",
}

# Main chat loop
while True:
cust = input("You: ")
cust = input("You: ").lower() # Convert input to lowercase for case-insensitive matching

# Check for exit command
if cust == "exit":
break
else:
# Respond to customer input using the predefined responses from the dictionary
print("\nBot: ", qna1[cust])
if cust in qna:
response_data = qna[cust]

if isinstance(response_data, str):
print("\nBot:", response_data)
else:
print("\nBot:", response_data["response"])

if "options" in response_data:
for key, value in response_data["options"].items():
print(f"{key}. {value}")

followup_input = input(response_data["followup"] + "\nYou: ").strip()
if followup_input in response_data["options"]:
print("\nBot:", response_data["options"][followup_input])
else:
print("\nBot: Invalid choice. Please select a valid option.")
else:
print("\nBot: Invalid response configuration. Please contact customer support.")

else:
print("\nBot: I'm sorry, I don't understand. Please try a different query.")