Skip to content

Instantly share code, notes, and snippets.

@loristns
Created May 12, 2018 10:12
Show Gist options
  • Save loristns/a318169f203b6f30552fe362531e21a0 to your computer and use it in GitHub Desktop.
Save loristns/a318169f203b6f30552fe362531e21a0 to your computer and use it in GitHub Desktop.
Kadot 1.0 Mini Bot
from kadot.bot_engine import ConversationNode
from kadot.models import EntityRecognizer
from kadot.vectorizers import VectorDict
import random
glove = VectorDict.load_glove(open('glove/glove.6B.50d.txt'))
city_recognizer = EntityRecognizer({
"I live in Paris ": ('Paris',),
"The city where I live is London": ('London',),
"in berlin, there is many things to do": ('berlin',),
"Tell me the forecast in New York": ('New', 'York'),
"Silicon Valley is in San Francisco and and its surroundings": ('San', 'Francisco'),
"Yesterday, I went to Dublin.": ('Dublin',)
})
bot = ConversationNode(glove)
bot.add_entity('city', city_recognizer)
@bot.intent([
'hi',
'hello !',
'goodbye',
'bye bye'
])
def greeting(raw, entities):
return raw + ' !'
@bot.intent([
"What is the weather like in Paris ?",
"What kind of weather will it do in London ?"
"Give me the weather forecast for Berlin please.",
"Tell me the forecast in New York !",
"Give me the weather in San Francisco...",
"I want the forecast in Dublin."
])
@bot.require_entity('city')
def weather(raw, entities):
return "In {}, it will be {}" \
.format(
' '.join(entities['city'][0]),
random.choice(['sunny', 'cloudy', 'rainy'])
)
bot.train()
while True:
print(bot.predict(text=input('> ')))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment