Skip to content

Instantly share code, notes, and snippets.

@arjunghosh
Created February 16, 2023 14:27
Show Gist options
  • Save arjunghosh/ebde7cdb96394c5310ab6aef63396330 to your computer and use it in GitHub Desktop.
Save arjunghosh/ebde7cdb96394c5310ab6aef63396330 to your computer and use it in GitHub Desktop.
ChatGPT generated code for a simple AI chatbot
import spacy
# Load a pre-trained NLP model from spaCy
nlp = spacy.load("en_core_web_sm")
# Define a function to handle user input and generate a response
def respond(input):
# Parse the user input using the NLP model
doc = nlp(input)
# Extract the main verb of the user input
main_verb = None
for token in doc:
if token.pos_ == "VERB":
main_verb = token
break
# Generate a response based on the main verb
if main_verb is None:
return "I'm sorry, I didn't understand what you said."
elif main_verb.lemma_ == "be":
return "What do you think about it?"
elif main_verb.lemma_ == "eat":
return "What kind of food do you like?"
elif main_verb.lemma_ == "go":
return "Where do you want to go?"
else:
return "I'm not sure what you mean by that."
# Define a loop to keep the chatbot running
while True:
# Get user input
user_input = input("You: ")
# Generate a response and print it
bot_response = respond(user_input)
print("Bot: " + bot_response)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment