Reputation: 3804
I am creating a chatbot using Wit.ai and am trying to achieve a more conversational style of interaction. Currently I have several stories that all require a location to function but are somewhat related. Here is an example of how I interact with my bot now:
What is the weather in Los Angeles, CA?
Bot response
How many people live in Los Angeles, CA?
Bot response
but I would like my chatbot to remember that I am talking about Los Angeles so the interaction would look like this:
What is the weather in Los Angeles, CA?
Bot Response
How many people live there?
Bot Response
even though 2 different stories are being executed. Currently I was able to accomplish this by adding an extra function (which I use in the same way merge was used) and a singleton to my code that pulls values from entities and stores them for later use according to session info like this:
session_info = {}
def _init_store(session_id):
global session_info
print "session info", session_info
if session_id in session_info:
pass
else:
s_info = {}
session_info[session_id] = s_info
def get_stored_info(session_id, key):
global session_info
try:
return session_info[session_id][key]
except:
return None
def add_stored_info(session_id, key, data):
_init_store(session_id)
global session_info
try:
session_info[session_id][key] = data
return True
except:
return False
I've read through all the docs and am slightly confused by what they say. The docs say this about contexts:
Converse allows you to build conversational app. It allows you to predict what your app should do at any given state in the conversation based on the current context and the user query.
The context is an object you manage to tell Wit.ai about the current state of the conversation. Wit.ai is able to predict the next action your bot should take by comparing — among other things — the context described in your Stories with the one you send to the the /converse endpoint. Wit will never update the context by itself, you have to manage the context object on your side. There is usually one context object per session. In addition to helping Wit.ai predict the next action, the context is used to create dynamic answers in templates.
I read this to mean that wit will pass around the context object I manage and not make any changes to it, meaning that I am responsible for adding and removing keys from it. However I also found this which states that "Conversation-aware entity extraction" has yet to be implemented so I am pretty confused about if this is doable or not.
Also I have found that when I look at the value of request['context']
that is passed in to each of my story execution functions the value of context is just an empty dictionary no matter what was added or removed before even though it says above that your context is never touched by wit.
Is this possible to do in wit itself or is there a wit approved way to achieve this or am what I doing now the best I can do? If I had to make a guess it would seem like it isn't supported yet but it seems like such a basic chatbot feature and the docs are ambiguous enough that I also could just be overlooking the proper way to do this. Any help would be greatly appreciated. I am using python in case that is relevant to anyone.
Upvotes: 3
Views: 1646
Reputation: 578
It should work the way you described it. Yes Wit doesn't update the context, so if you want to keep/remember something for later, you will have to use a client-side action to store it in the context. In you example, you will store the value of the entity wit/location in a context key, let's say loc
In your 'How many people live there?" story, you will have an client-side action that check is context.loc exists, if not, would ask for it via a branch a la https://wit.ai/docs/recipes#build-a-slot-based-bot recipe
Upvotes: 1