How does the formActions works? - rasa-nlu

I do not understand how the slot mapping does to know which "utterance" to answer the user to get the "entity" requested.
example of my form class:
class RestaurantForm(FormAction):
"""Example of a custom form action"""
def name(self):
# type: () -> Text
"""Unique identifier of the form"""
return "formaejemplo"
#staticmethod
def required_slots(tracker):
# type: () -> List[Text]
"""A list of required slots that the form has to fill"""
return ["valor1","valor2","valor3"]
def slot_mappings(self):
return {"valor1": self.from_entity(entity="valor1",intent="getvalor1"),
"valor2": self.from_entity(entity="valor2",intent="getvalor2"),
"valor3": self.from_entity(entity="valor3",intent="getvalor3")}
def submit(self, dispatcher, tracker, domain):
dispatcher.utter_template('utter_listo', tracker)
return []
domain.yml:
intents:
- peticion_habitacion:
use_entities: false
- getvalor1
- getvalor2
- getvalor3
entities:
- valor1
- valor2
- valor3
slots:
valor1:
type: unfeaturized
auto_fill: false
valor2:
type: unfeaturized
auto_fill: false
valor3:
type: unfeaturized
auto_fill: false
actions:
- utter_prueba
- utter_completo
templates:
utter_completo:
- text: "listo:\nvalor 1 {valor1} \nvalor 2 {valor2} \nvalor 3 {valor3}"
utter_prueba:
- text: "iniciando prueba:\n"
utter_valor1:
- text: "dame el valor 1 no enteros"
utter_valor2:
- text: "dame el valor 2 no enteros"
utter_valor3:
- text: "dame el valor 3 no enteros"
utter_listo:
- text: "prueba completa"
forms:
- formaejemplo
in the section where you get the value1, value2 etc ... it is according to the Rasa documentation: "valor1": self.from_entity (entity = "valor1", intent = "getvalor1" "the "valor 1" will be obtained from the intent getvalor1."
my question is, at what time or in what part or what file, the action form is told that it will have to send the "utterance" "utter_valor1" or "utter_valor2", because to several Internet examples plus the same examples of bots of rasa, I see that these send the utterance and then recover the value, but I can not get to understand how they send the utterance and then get the value

I assume you mean how the action sdk determines which template it should use to ask for a requested slot, right?
This logic is actually hardcoded here: https://github.com/RasaHQ/rasa_core_sdk/blob/cfffaac0013606f7614ab0f213bc39623ee8b53c/rasa_core_sdk/forms.py#L374
What it does is simply dispatches an utterance which is utter_ask_{the name of slot which should be requested}.
If the user then sends back his answer, the form action is triggered again and the slot value can be extracted.

Related

form is not activated in Rasa 2.0

I'm trying to integrate a form in my rasa chatbot.
In domain.yml, I have included the following:
I declared the slots:
slots:
question1:
type: text
question2:
type: text
question3:
type: text
the questions that the form is supposed to send to the user:
utter_ask_question1:
- text:" first question goes here"
utter_ask_question2:
- text:" second question goes here"
utter_ask_question3:
- text:" third question goes here"
defined the form as:
forms:
user_quiz_form:
question1:
- type: from_text
# entity: date
question2:
- type: from_text
question3:
- type: from_text
the actions section also contains :
actions:
- action_submit
- user_quiz_form
The file rules.yml contains:
- rule: Activate quiz form
steps:
- intent: quiz
- action: utter_quiz
- action: user_quiz_form
- active_loop: user_quiz_form
- rule: Submit quiz form
condition:
- active_loop: user_quiz_form
steps:
- action: user_quiz_form
- active_loop: null
- slot_was_set:
- requested_slot: null
- action: action_submit
and actions.py is:
from typing import Any, Text, Dict, List
from rasa_sdk import Action, Tracker
from rasa_sdk.events import SlotSet, EventType
from rasa_sdk.executor import CollectingDispatcher
import webbrowser
class ValidateForm(Action):
def name(self) -> Text:
return "user_quiz_form"
def run(
self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict
) -> List[EventType]:
required_slots = ["question1","question2", "question3"]
for slot_name in required_slots:
if tracker.slots.get(slot_name) is None:
# The slot is not filled yet. Request the user to fill this slot next.
return [SlotSet("requested_slot", slot_name)]
return [SlotSet("requested_slot", None)]
class ActionSubmit(Action):
def name(self) -> Text:
return "action_submit"
def run(
self,
dispatcher,
tracker: Tracker,
domain: "DomainDict",
) -> List[Dict[Text, Any]]:
print("****************SUBMIT*****************")
dispatcher.utter_message(template="utter_quiz_thanks", date=tracker.slots.get("question1"))
return []
When the form is triggered, it doesn't' ask the questions to the user and returns utter_quiz_thanks with None as question1 value.
Is this the same indentation you're using in your domain.yml? If so, you're missing some indents; the slots underneath the form need to be indented (see below for an example). My guess is that you're launching the form correctly, but due to the indent issues your assistant is treating it as a form with 0 questions.
forms:
restaurant_form:
cuisine:
- type: from_entity
entity: cuisine
num_people:
- type: from_entity
entity: number

Add button based questions in slack integrated RASA chatbot?

I want a chatbot with buttons in Slack integrated RASA Bot for example, How are you feeling? Sad or Happy. I want two-buttons(one for happy and one for sad) here and get input from the user and followed by other questions. What will be the stories.md, nlu.md, domain.yml, and frontend python code?
You can implement the buttons in your domain.yml file. It could look like the following:
responses:
utter_greet:
- text: "Hey! How are you?"
buttons:
- title: "great"
payload: "great"
- title: "super sad"
payload: "super sad"
The payload will then be sent to the nlu model to make the prediction on the intent. That's why your nlu.md should have examples for like mood_sad, mood_great in there.
Your stories.md should look regular - it should have examples of how the conversations could go. For example:
* greet
- utter_greet
* mood_sad
- action_cheer_up
You can also restrict the nlu part on buttons by sending actual intents (and potential entities) to the RegexInterpreter. In that case, you can define buttons in your domain as follows:
utter_greet:
- text: "Hey! How are you?"
buttons:
- title: "great"
payload: '/mood_great'
- title: "super sad"
payload: '/mood_sad'

disable cache mechanism in admin-on-rest

is it possible to disable your cache system?
I have an error when I have different object in my Edit page
for example I have this as my list in my API:
domain.com/api/products
list = [
{id: 1 , value: 'foo'},
{id: 2 , value: 'bar'},
]
and this for my single object:
domain.com/api/products/1
item = {id: 1 , value: 'foo' , user: 'baz'}
it causes an error in edit page since your system is using old data in list before rest API response and we don't have user data on the list
so I want to disable the cache system if its possible and just load the api result each time

API Blueprint and Dredd - Required field missing from response, but tests still pass

I am using a combination of API Blueprint and Dredd to test an API my application is dependent on. I am using attributes in API blueprint to define the structure of the response's body.
Apparently I'm missing something though because the tests always pass even though I've purposefully defined a fake "required" parameter that I know is missing from the API's response. It seems that Dredd is only testing whether the type of the response body (array) rather than the type and the parameters within it.
My API Blueprint file:
FORMAT: 1A
HOST: http://somehost.net
# API Title
## Endpoints [GET /endpoint/{date}]
+ Parameters
+ date: `2016-09-01` (string, required) - Date
+ Response 200 (application/json; charset=utf-8)
+ Attributes (array[Data])
## Data Structures
### Data
- realParameter: 2432432 (number)
- realParameter2: `some string` (string, required)
- realParameter3: `Something else` (string, required)
- realParameter4: 1 (number, required)
- fakeParam: 1 (number, required)
The response body:
[
{
"realParameter": 31,
"realParameter2": "some value",
"realParameter3": "another value",
"realParameter4": 8908
},
{
"realParameter": 54,
"realParameter2": "something here",
"realParameter3": "and here too",
"realParameter4": 6589
}
]
And my Dredd config file:
reporter: apiary
custom:
apiaryApiKey: somekey
apiaryApiName: somename
dry-run: null
hookfiles: null
language: nodejs
sandbox: false
server: null
server-wait: 3
init: false
names: false
only: []
output: []
header: []
sorted: false
user: null
inline-errors: false
details: false
method: []
color: true
level: info
timestamp: false
silent: false
path: []
blueprint: myApiBlueprintFile.apib
endpoint: 'http://ahost.com'
Does anyone have any idea why Dredd ignores the fact that "fakeParameter" doesn't actually show up in the response body and still allows the test to pass?
You've run into a limitation of MSON, the language API Blueprint uses for describing attributes. In many cases, MSON describes what MAY be present in the data structure rather than what MUST exactly be present.
The most prominent case are arrays, where basically any content of the array is optional and thus the underlying generated JSON Schema doesn't put any constraints on array contents. Dredd just respects that, so indirectly it becomes a Dredd issue too, however there's not much Dredd can do about it.
There's an issue for the problem: apiaryio/mson#66 You can follow and comment under the issue to get updated about this. Dredd is usually very prompt in getting the latest API Blueprint parser, so once it's implemented in the language itself, it won't take long to appear in Dredd.
Obvious (but tedious) workaround is to specify your own JSON Schema with stricter rules using the + Schema section alongside the + Attributes section.

Symfony-2 gives more than one validation error message

My validation.yml is given:
task:
- Email:
message: The email "{{ value }}" is not a valid email.
- MinLength: { limit: 50, message: You must be 50 or under to enter. }
My issue is that if I give "wrong-email" in the task-field it gives two error messages:
The email "wrong-email" is not a valid email.
You must be 50 or under to enter.
Actually, I want to show only one error-message at a time.
That means it should check for the validation "MinLength" only if it is a valid email.
Validation sequencing can be done using group sequences. I fixed group sequences for the YAML driver only today, so you might need to wait for the next release of the 2.0 or master branch.
MyEntity:
group_sequence: [MyEntity, Extra]
properties:
task:
- Email: { message: ... }
- MinLength { limit: 50, message: ..., groups: Extra }
Now the constraints in group "Extra" will only be validated if all constraints in group "MyEntity" (i.e. the default group) succeed.

Resources