Teacher Gavin's Transformer Live Lessons - Rasa Dialogue Robot Project Practical Education Bot Project Session Customization, Rich Response Decryption and Case Analysis (73)

   This article continues to focus on Rasa, an industrial-grade business dialogue platform and framework, to customize the Session of the Education Bot project in the education field of the Rasa dialogue robot project, how to override action_session_start to achieve customized functions, and to analyze the use of Rich Response in detail in combination with cases. .

 1. Session customization, Rich Response decryption and case analysis of the Education Bot project in the educational field of the Rasa dialogue robot project

  1. Analysis and configuration practice of config operating mechanism in Domain

This is the config information in the domain, these are the configuration information used by the chatbot at the system and session level:

Store_entites_as_slots is set to true here, which means that the entities extracted from the user message are saved to the slots of the current session. When an entity matches the "from_entity" slot mapping, if this parameter is set to true, the value of the entity will be set to the corresponding slot. If the slot_was_set is manually added in the story, it will be skipped. This feature can be turned off by setting the parameter to false, for example:

 2. Best practice for setting session_expiration_time and carry_over_slots_to_new_session

-session_expiration_time specifies the time for the session to expire. After the timeout, a new session needs to be started before the dialog can be executed.

A conversation session can be started in three ways:

- User and conversation bot start a conversation

- User sends first message to chatbot after session timeout

- Use intent "/session_start" to trigger a new session

                                                                                                       

-carry_over_slots_to_new_session specifies whether existing slots in the previous session need to be brought into the new session. When set to true, the existing slots in the previous session will be brought into the new session.

 3. Action_session_start operation mechanism and best practices

The default action "action_session_start" is triggered when a session is started. The default implementation is to bring all currently existing slots into the new session. Note that all conversations start with action_session_start. Override this action to initialize the tracker with slots obtained through an external API call, or with a conversation bot message to start the conversation. If you don't want all slots to be brought into the new session, but only the user name and phone number, you can override the default action_session_start with the following custom action:

If in the above fetch_slots method, you need to call an external third-party API to obtain slot information, you need to add an __init__ method to initialize the database connection, etc., and the initialization method will be executed when the action server loads the action. It can be used directly when serving.

When a user message triggers a session start, you can access this special slot "session_started_metadata" in order to obtain metadata information related to the user message. The following is an example:

Another example is that if the user's geographic location or preference information can be obtained when the user first logs into the dialogue system, we can use this information to set up slots once the user starts a dialogue with the dialogue bot. For example, if the user From NYC, when the user asks the dialogue robot about the weather, because the dialogue robot has obtained the user's location information through metadata, it can directly query the weather in NYC and provide it to the user without asking the user's location information.

 4. Analysis and example of Using Variables in Responses

Responses are also an action, but this action sends a message directly to the user without running any custom code or returning an event. Responses are defined directly under the responses key in the domain file, and can include rich text content such as buttons and attachments. You can use variables to write information to responses. For example, in the following example, Rasa automatically replaces the placeholder {name} in responses with the value in slot "name":

 5. Channel-Specific Response Variations analysis and examples

In order to let the chatbot choose different responses based on which channel the current user uses, the channel key can be used to specify the response corresponding to a specific channel. For example, in the following example, the first response is only used for channel "slack", And the use of the second response has nothing to do with the channel:

When using, you need to pay attention to ensure that the value of the channel key needs to be the same as the value returned by the name method of your input channel. If you use a built-in channel, the value of this key also needs to match the channel name in your credentials.yml file.

 6. Analysis and example of Conditional Response Variations

You can use conditional judgment to select the response based on the value of the slot. Compared with the ordinary response, this kind of response needs to specify the condition key when defining it. This key specifies the list containing the slot name and value. When a dialog triggers a response, it will check which response matches the current condition based on the value of the current dialog state slot. It should be noted that the slot value of the dialogue state and the limited value of the slot used in the response definition in the domain are matched by the symbol ==, that is, not only the value but also the slot type (for example, true of boolean type and string "true" are different of). In the following example, the slot "logged_in" is set to true:

 7. Rich Responses parsing and examples

The use of rich responses includes the use of buttons or the use of images, etc. The advantages of using buttons include convenience for users to operate, and the ability to directly send user intents according to the button's payload without the need for NLU prediction. Examples are as follows:

Entities can also be passed to the chatbot via buttons:

Here is an example of passing multiple entities:

'/intent_name{ {"entity_type_1":"entity_value_1", "entity_type_2": "entity_value_2"}}'

Note that in the above example two curly braces are used to enclose the contents of the entities section.

Guess you like

Origin blog.csdn.net/m0_49380401/article/details/123390317
Recommended