Context with state, fall back is not working
misysdclabs opened this issue · 4 comments
Hi Guys,
Is there anybody who use the "state" context parameter, and that works as described?
I'm working on a project where I have 5 intents now. I want the user to be able to change an entity in the previous intent or switch to a new topic. As I read in the docs this "state" context param is just what I need. Here is an example:
First user says:
"I’d like to have a big pepperoni pizza with tomato” (—> this fires "order_pizza" intent)
And than next comes A or B:
A ---> "And with cheese?” (—> "order_pizza" again)
B ---> "Send 6 dollars to Peter.” (—> "pay")
I copy here what I found in the documentation:
https://wit.ai/docs/console/complete-guide#advanced-topics-link
"If the query text or audio does not match these at all though, Wit.ai will fall back on normal intents, so that users are never trapped in a state (you don’t want to reinvent the IVR nightmare). Note that if an intent has a state, it won’t be activated for stateless queries (i.e. queries that don’t indicate a state in their context field)."
I have defined two states:
"all_intents" : I added this state to all the intents
"order_pizza": This added to my order_pizza intent
If I call wit with added only the order_pizza state wit won't understand the pay intent at all:
https://api.wit.ai/message?context={"state":["order_pizza"]}&q=Send 6 dollars to Peter
[...]"outcomes": [
{
"_text": "Send 6 dollars to Peter",
"confidence": 0,
"intent": "order_pizza", [...]
If I add both order_pizza and all_intents, and the text is again about ordering pizza, I will get the same answer when I add only all_intents:
https://api.wit.ai/message?context={"state":["order_pizza","all_intents"]}&q=And with cheese?
[...]"outcomes": [
{
"_text": "And with cheese?",
"confidence": 0.325,
"intent": "order_pizza", [...]
https://api.wit.ai/message?context={"state":["all_intents"]}&q=And with cheese?
[...]"outcomes": [
{
"_text": "And with cheese?",
"confidence": 0.325,
"intent": "order_pizza", [...]
What do I wrong?
Any help much appreciated.
Best,
Krisztian
Thanks for sharing the details of what you want to accomplish. In order to make it work, you will need to use the state but also another "contextual" intent.
I just created this small Wit app to better show you how it would work.
There are 3 intents for the sake of simplicity:
- order_pizza with a topping entity for expressions like "I’d like to have a big pepperoni pizza with tomato"
- pay for expressions like "Send $6 to Alex"
- order_pizza_change: this intent has a "pizza" state and regroups expressions like "can you add ham?, "and with olives?"...
You can now test your scenario in the Console
This is where in on the client side, you would set the context to the "pizza" state and send that state with the next query. In the console you can set the Context via bookmark icon on the right of the "Try out a sentence" field.
You should see this:
If you keep the "pizza" state, but type "send 6 dollars to peter", it will give you the correct pay intent
Hope this helps. Here is the example app: https://wit.ai/l5t/TestState
This is exactly just what I want, and thanks for the full story of it!
Did you put any state into order_pizza or pay intents?
What see here that it works for you, and just not at all for me :( As I wrote before, if there is a state in query which is put into my pay intent, it won't recognise it:
https://api.wit.ai/message?context={"state":["order_pizza"]}&q=Send 6 dollars to Peter
{
"msg_id": "5b43ff69-c7b9-4e68-b18f-dc0c94bef1e5",
"_text": "Send 6 dollars to Peter",
"outcomes": [
{
"_text": "Send 6 dollars to Peter",
"confidence": 0,
"intent": "order_pizza",
"entities": {
"pizza_topping": [
{
"type": "value",
"value": "Peter",
"suggested": true
[...]
Hmmm, maybe am I using an older version of WitAi?
No, you don't want to put any state on order_pizza or pay intents as they can be requested at any point in the conversation
Now it works as a charm, thanks a lot!
A side note here, I describe how mislead me your Advanced Topics on using the states, maybe I can help you to improve it.
I wanted my intent to be able to reenter after recognition, with priority and shorter version of the sentence, just to change a couple of params. I saw this on your site:
"Note that if an intent has a state, it won’t be activated for stateless queries (i.e. queries that don’t indicate a state in their context field)."
So I added all_intents just to smartly hack this rule. Now I understand why this is not working. But to copy my whole intent to be able to recapture some params... this is strange for me, even now after you described. Maybe you should write a paragraph about into the documentation.
thanks again, and all the best!