How to get user message as value

rasa-core

(Anders) #1

Can anybody paste an example of using FreeTextFormField?

https://core.rasa.com/patterns.html?highlight=freetextformfield#validation-and-free-text-input

Documentation does not show how to use it


(Akela Drissner) #2

Does the last section in our new docs here answer your question? http://rasa.com/docs/core/slotfilling/

Basically it will just take the whole user utterance and store it in the provided slot


(Anders) #3

I will try and elaborate. So first I wonder how to define an intent which will work. From the documentation it says

[…] Typically your NLU model will assign this free-text input to 2-3 different intents. It’s easiest to add stories for each of these.

I don’t understand that line (buttom of page, warning box)

Without testing, this is what I imagine is the solution.

nlu_model.md

## intent:blabla_intent
- the quick brown fox jumps over the lazy dog
- the quick red fox jumps over the crazy dog 
- that fat brown fox walks past the lazy cat
- the quick brown coffee pours into the dirty mug

stories.md

##wildcard_story
*blabla_intent
   -custom_action_freetext

actions.py

class ActionGetFreetext(FormAction):

    @staticmethod
    def required_fields():
        return [
            FreeTextFormField(slot_freetext)
        ]

    def name(self):
        return 'custom_action_freetext'

    def submit(self, dispatcher, tracker, domain):
        # What goes here?

(Akela Drissner) #4

It might be that your NLU model gets confused by input in that field (e.g. if it’s just a person name or something) and so it could classify it as a number of intents. So you could make your story something like:

* blabla_intent OR blabla2 OR blabla3
  - custom_action_freetext

The submit() function can just return [] if you want. Or you might want to make an API call there or something that uses all the collected slots to get some information.


FreeTextFormField and Interactive Learning
(Leo@Vocinity) #5

Akela, it is possible to use “OR” in training stories? So let’s say i want my_action to be invoked after my_intent1, or following my_intent2, i can just write a story like this:

  • my_intent1 OR my_intent2
    • my_action

Until now, I thought you’d have to write two separate stories, one with

  • my_intent1
    • my_action

and one with

  • my_intent2
    • my_action

(Akela Drissner) #6

Yes you can do it :wink: http://rasa.com/docs/core/stories/


(Anders) #7

I don’t like the thought that it will be up to the NLU model to identify an intent as a wildcard. The user might say something that is scored more likely to be a different intent since nobody can predict what the wildcard text will be.

Wouldn’t it be better to have a special story element that treats the next message as a wild card, so the NLU model is overruled?

E.g.

stories.md

##wildcard_story
*greeting
   -ask_for_wildcard
*WILDCARD
  -utter_thank_you

(Akela Drissner) #8

This is something we’re currently researching on how to do best. At the moment I’m afraid this isn’t possible just yet though


(Anders) #9

I will stay glued to the blog and change log for any news and updates :stuck_out_tongue_winking_eye: