Skip to content

Instantly share code, notes, and snippets.

Last active May 26, 2022 21:14
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
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:"],
"prices": ["Our prices our affordable for all!", "We have super low prices! Pracitcally free!"],
"start_order": ["Lets start the order here:"]
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(
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