Skip to content

Commit

Permalink
Add fake_bot example.
Browse files Browse the repository at this point in the history
  • Loading branch information
loristns committed Jun 12, 2018
1 parent 7f3588b commit 121d559
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions examples/fake_bot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
from kadot.bot_engine import Agent
from kadot.models import CRFExtractor
import random

# Set up an extractor to retrieve place names in queries.
places_extractor = CRFExtractor({
"For eg. at Suite 101, Johnshon Avenue in London.": ('Suite', '101', 'Johnshon', 'Avenue,', 'London'),
"The soldiers clashed at Gettysburg.": ('Gettysburg',),
"The treaty was signed at Versailles.": ('Versailles',),
"Give me the forecast in New York !": ('New', 'York'),
"I am on Brompton Road": ('Brompton', 'Road',),
"The plane stops at Dallas on the way to San Francisco ": ('Dallas', 'San', 'Francisco'),
"Yesterday, I went to Dublin.": ('Dublin',)
},
crf_filename='.crf_city_extractor_city'
)

bot = Agent()
bot.add_entity('place', places_extractor)


@bot.intent([
'hi',
'hello !',
'goodbye',
'bye bye',
'ok',
'thanks'
])
def smalltalk(raw, context):
"""
An intent to answer to greetings and appreciations.
Answer the same with an exclamation mark (!).
"""
return raw + '!', context


@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."
], entities=['place'])
def weather(raw, context):
"""
Say the weather for a given place (random ;p).
"""

if context['place']:
answer = "In {}, it will be {}".format(context['place'], random.choice(['sunny', 'cloudy', 'rainy']))
return answer, context
else:
return bot.prompt("In which city ?", key='place', callback=weather, context=context)


bot.train()

while True:
print(bot.predict(text=input('> ')))

0 comments on commit 121d559

Please sign in to comment.