Mukul Program Coming Soon
Mukul Program Coming Soon
# For this simple example, we'll just return a random response from a list
responses = ["I'm sorry, I don't understand. Can you please try again?",
"That's an interesting point. Can you tell me more?", "Thanks for sharing that with
me!", "I'm glad you asked. Here's what I think..."]
response = random.choice(responses)
# You can also pass context information between different calls to this
function
# For example, if the user has already provided their name, you could store
that information in the context and use it to personalize the response
if context and "name" in context:
response = f"Hi {context['name']}, " + response
return response
# Main loop
print("Welcome to Chatbot!")
context = {} # Initialize an empty context
while True:
user_input = get_user_input()
if user_input == "exit":
print("Chatbot: Goodbye!")
break
else:
response = generate_response(user_input, context=context)
print("Chatbot: " + response)
# You can also update the context based on the user's input and the
chatbot's response
if "name" not in context:
# For example, if the user's input contains their name, you could
extract it and store it in the context
if "my name is" in user_input.lower():
name = user_input.split("my name is")[-1].strip()
context["name"] = name
# Alternatively, you could prompt the user for their name and store it
in the context
else:
print("Chatbot: What's your name?")
name = get_user_input()
context["name"] = name