Skip to content

Instantly share code, notes, and snippets.

@lando22
Last active May 26, 2022 21:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lando22/77d5ada465bb550a94dbed82a2b901c9 to your computer and use it in GitHub Desktop.
Save lando22/77d5ada465bb550a94dbed82a2b901c9 to your computer and use it in GitHub Desktop.
import humingbird
import random
intents = {
"greeting": ["Hi! Welcome to the ice cream shop.", "Welcome! What can i help you with?"],
"goodbye": ["Goodbye!", "Nice chatting! Have a great day."],
"menu": ["Here is our menu: https://www.randomicecream.co"],
"prices": ["Our prices our affordable for all!", "We have super low prices! Pracitcally free!"],
"start_order": ["Lets start the order here: https://www.fakepaymentlink.com"]
}
def detect_and_respond(query):
"""Detects an intent from the users query and returns a response from the most likely intent"""
prediction = humingbird.Text.predict(
text=query,
labels=["greeting", "goodbye", "menu", "prices", "start_order"]
)
highest_score = 0
highest_score_class = ""
for i in prediction:
if i["score"] > highest_score:
highest_score = i["score"]
highest_score_class = i["className"]
return random.choice(intents[highest_score_class])
detect_and_respond("Hi there! How are you today?")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment