From c4a2cb28df8fed2c36d659838fd51c503f7db7fe Mon Sep 17 00:00:00 2001 From: Alan Nichol Date: Fri, 22 Sep 2023 11:06:51 +0200 Subject: [PATCH 01/11] add action labels, switch bot to assistant --- docs/docs/tutorial.mdx | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/docs/docs/tutorial.mdx b/docs/docs/tutorial.mdx index a4c390a042c1..e24f362f008e 100644 --- a/docs/docs/tutorial.mdx +++ b/docs/docs/tutorial.mdx @@ -11,7 +11,7 @@ import TutorialActionLabel from "@theme/TutorialActionLabel"; You will build an assistant in this tutorial for helping people transfer money. This tutorial does not assume and existing knowledge of Rasa or chatbots. -The techniques you will learn in this tutorial are fundamental to building any Rasa bot, +The techniques you will learn in this tutorial are fundamental to building any Rasa assistant, and understanding it will bring you quite far along to mastering Rasa. @@ -46,6 +46,11 @@ Here are some of the conversations your assistant will be able to handle: +## Following This Tutorial + +Whenever there is something for you to do, you'll see this label: + + ## Setup @@ -58,7 +63,7 @@ rasa init --template tutorial ``` By default, this tutorial uses the OpenAI API. -If you'd like to use a different LLM, follow the instructions [here](./llms/llm-configuration.mdx#other-llmsembeddings) +If you'd like to use a different LLM, follow the instructions [here](./llms/llm-configuration.mdx#other-llmsembeddings). To set your OpenAI API key, run the following command: @@ -94,6 +99,8 @@ In this tutorial you will primarily work with the following files: ## Testing your money transfer flow + + Train your assistant by running: ```bash @@ -106,7 +113,7 @@ And start talking to it in the shell by running: rasa shell ``` -Tell the bot that you'd like to transfer some money to a friend. +Tell the assistant that you'd like to transfer some money to a friend. ## Understanding your money transfer flow. @@ -226,6 +233,8 @@ flows: Slots are also used to build branching logic in flows. + + You're going to introduce an extra step to your flow, asking the user to confirm the amount and the recipient before sending the transfer. Since you are asking a yes/no question, you can store the result in a boolean `slot` @@ -295,7 +304,7 @@ In this case, we're using the value of the boolean slot `final_confirmation`. Conditions can be used to create branching logic, including logical operators like `AND`, `OR`, etc. You can learn more about conditions and advanced logic here (link). -To try out the updated version of your assistant, run `rasa train`, and then `rasa shell` to talk to your bot. +To try out the updated version of your assistant, run `rasa train`, and then `rasa shell` to talk to your assistant. It should now ask you to confirm before completing the transfer. @@ -346,6 +355,7 @@ and you pass information back to the conversation by returning a `SlotSet` event diagram of how slots are used with custom actions + Now you are going to make three additions to your `domain.yml`. You will add a top-level section listing your custom actions. @@ -410,6 +420,8 @@ flows: ## Testing your Custom Action + + Custom actions are run as a separate server to the main Rasa assistant. To start your custom action server, create a new terminal tab and run: @@ -424,7 +436,7 @@ action_endpoint: url: "http://localhost:5055/webhook" ``` -Then re-start your bot by running `rasa shell`. +Then re-start your assistant by running `rasa shell`. When you reach the `"check_funds"` step in your flow, Rasa will call the custom action `action_sufficient_funds`. We have hardcoded the user's balance to be `1000`, so if you try to send more, the assistant will tell you that you don't have enough funds in your account. From 4016d3e65c5b6432f618216704df1c4cf164eab6 Mon Sep 17 00:00:00 2001 From: Alan Nichol Date: Fri, 22 Sep 2023 11:30:46 +0200 Subject: [PATCH 02/11] add info about ask_before_filling --- docs/docs/tutorial.mdx | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/docs/docs/tutorial.mdx b/docs/docs/tutorial.mdx index e24f362f008e..86d25411d01a 100644 --- a/docs/docs/tutorial.mdx +++ b/docs/docs/tutorial.mdx @@ -307,6 +307,24 @@ You can learn more about conditions and advanced logic here (link). To try out the updated version of your assistant, run `rasa train`, and then `rasa shell` to talk to your assistant. It should now ask you to confirm before completing the transfer. +## Ensuring a Slot is Requested Explicitly + +If you start a conversation with your assistant and say "I would like to transfer 100 dollars to Joe", +the slots `amount` and `recipient` will be filled immediately based on the first message, and your conversation +will advance to the end of the flow. +If you want to ensure that your assistant explicitly asks the user before filling a slot value, +you can set the attribute `ask_before_filling` to `true` in your `collect` step. +For example, to ensure that you always ask a user for confirmation, your flow step would look like this: + +``` + - id: "confirm_transfer" + collect_information: final_confirmation + # highlight-next-line + ask_before_filling: true + next: + - if: final_confirmation + then: "transfer_successful" +``` ## Integrating an API call From 4124cc793fd77d42b431d347e619611963482d8e Mon Sep 17 00:00:00 2001 From: Alan Nichol Date: Fri, 22 Sep 2023 11:35:35 +0200 Subject: [PATCH 03/11] rename custom action to action_check_sufficient_funds --- docs/docs/tutorial.mdx | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/docs/tutorial.mdx b/docs/docs/tutorial.mdx index 86d25411d01a..1a4da9cd8bb7 100644 --- a/docs/docs/tutorial.mdx +++ b/docs/docs/tutorial.mdx @@ -337,8 +337,8 @@ You can learn more about everything you can do with responses here (link). The second type of `action` is a custom action. The name of a custom action starts with `action_`. -You are going to create a custom action, `action_check_balance`, to check whether the user has enough money -to make the transfer, and then add logic to your flow to handle both cases. +You are going to create a custom action, `action_check_sufficient_funds`, to check whether the +user has enough money to make the transfer, and then add logic to your flow to handle both cases. Your custom action is defined in the file `actions.py`. To learn more about custom actions, go here (link). @@ -351,9 +351,9 @@ from rasa_sdk import Action, Tracker from rasa_sdk.executor import CollectingDispatcher from rasa_sdk.events import SlotSet -class ActionSufficientFunds(Action): +class ActionCheckSufficientFunds(Action): def name(self) -> Text: - return "action_sufficient_funds" + return "action_check_sufficient_funds" def run(self, dispatcher: CollectingDispatcher, tracker: Tracker, @@ -383,7 +383,7 @@ add a new response to send to the user in case they do not have sufficient funds ```yaml-rasa title="domain.yml" # highlight-start actions: - - action_sufficient_funds + - action_check_sufficient_funds # highlight-end slots: @@ -419,7 +419,7 @@ flows: # highlight-start next: "check_funds" - id: "check_funds" - action: action_sufficient_funds + action: action_check_sufficient_funds next: - if: has_sufficient_funds then: "confirm_transfer" @@ -455,7 +455,7 @@ action_endpoint: ``` Then re-start your assistant by running `rasa shell`. -When you reach the `"check_funds"` step in your flow, Rasa will call the custom action `action_sufficient_funds`. +When you reach the `"check_funds"` step in your flow, Rasa will call the custom action `action_check_sufficient_funds`. We have hardcoded the user's balance to be `1000`, so if you try to send more, the assistant will tell you that you don't have enough funds in your account. From 84bc87a4717e230008ec42d52430c95e552ce449 Mon Sep 17 00:00:00 2001 From: Alan Nichol Date: Fri, 22 Sep 2023 12:07:44 +0200 Subject: [PATCH 04/11] add missing links in tutorial --- docs/docs/tutorial.mdx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/docs/tutorial.mdx b/docs/docs/tutorial.mdx index 1a4da9cd8bb7..5d1cfdbec16f 100644 --- a/docs/docs/tutorial.mdx +++ b/docs/docs/tutorial.mdx @@ -195,7 +195,7 @@ responses: After sending this message, Rasa will wait for a response from the user. When the user responds, Rasa will try to use their answer to fill the slot `recipient`. -Read about slot validation (link) to learn more about how to run additional checks on slot values. +Read about [slot validation](./concepts/slot-validation-actions.mdx) to learn more about how to run additional checks on slot values. The diagram below summarizes how slot values are used to collect and store information, and how they can be used to create branching logic. @@ -302,7 +302,7 @@ The `next` attribute of your `confirm_transfer` step includes a `condition`. The expression after the `if:` key will be evaluated and return `True` or `False`. In this case, we're using the value of the boolean slot `final_confirmation`. Conditions can be used to create branching logic, including logical operators like `AND`, `OR`, etc. -You can learn more about conditions and advanced logic here (link). +You can learn more about conditions and advanced logic [here](./concepts/flows.mdx). To try out the updated version of your assistant, run `rasa train`, and then `rasa shell` to talk to your assistant. It should now ask you to confirm before completing the transfer. @@ -333,7 +333,7 @@ If the name of the action starts with `utter_`, then this action sends a message The name of the action has to match the name of one of the `responses` defined in your domain. The final step in your flow contains the action `utter_transfer_complete`, and this response is also defined in your domain. Responses can contain buttons, images, and custom payloads. -You can learn more about everything you can do with responses here (link). +You can learn more about everything you can do with responses [here](./concepts/responses.mdx). The second type of `action` is a custom action. The name of a custom action starts with `action_`. @@ -341,7 +341,7 @@ You are going to create a custom action, `action_check_sufficient_funds`, to che user has enough money to make the transfer, and then add logic to your flow to handle both cases. Your custom action is defined in the file `actions.py`. -To learn more about custom actions, go here (link). +To learn more about custom actions, go [here](./concepts/custom-actions.mdx). Your `actions.py` file should look like this: From df2a7adef784be256b8df96bf4d40ce02ccce653 Mon Sep 17 00:00:00 2001 From: Alan Nichol Date: Fri, 22 Sep 2023 12:38:44 +0200 Subject: [PATCH 05/11] not working yet, trying to get a custom 'deleted line' magic comment --- docs/docs/tutorial.mdx | 4 ++++ docs/docusaurus.config.js | 13 +++++++++++++ docs/themes/theme-custom/custom.css | 8 ++++++++ 3 files changed, 25 insertions(+) diff --git a/docs/docs/tutorial.mdx b/docs/docs/tutorial.mdx index 5d1cfdbec16f..cda47a3d6894 100644 --- a/docs/docs/tutorial.mdx +++ b/docs/docs/tutorial.mdx @@ -14,6 +14,10 @@ This tutorial does not assume and existing knowledge of Rasa or chatbots. The techniques you will learn in this tutorial are fundamental to building any Rasa assistant, and understanding it will bring you quite far along to mastering Rasa. +```python +# highlight-deleted-line +rasa init --template tutorial +``` ## What are you building? diff --git a/docs/docusaurus.config.js b/docs/docusaurus.config.js index 04d57a468278..f29120fee1aa 100644 --- a/docs/docusaurus.config.js +++ b/docs/docusaurus.config.js @@ -132,6 +132,19 @@ module.exports = { gtm: { containerID: 'GTM-MMHSZCS', }, + prism: { + magicComments: [ + { + className: 'theme-code-block-highlighted-line', + line: 'highlight-next-line', + block: {start: 'highlight-start', end: 'highlight-end'}, + }, + { + className: 'code-block-deleted-line', + line: 'highlight-deleted-line', + }, + ], + }, }, themes: [ '@docusaurus/theme-search-algolia', diff --git a/docs/themes/theme-custom/custom.css b/docs/themes/theme-custom/custom.css index f66cfae04340..aa5a6bd00825 100644 --- a/docs/themes/theme-custom/custom.css +++ b/docs/themes/theme-custom/custom.css @@ -37,3 +37,11 @@ .prose th:empty, [class^=prose-] th:empty, [class*=" prose-"] th:empty { border-style: none; } + +.code-block-deleted-line { + background-color: #ff000020; + display: block; + margin: 0 calc(-1 * var(--ifm-pre-padding)); + padding: 0 var(--ifm-pre-padding); + border-left: 3px solid #ff000080; +} From 48fa7b9c61269aa71c0860fd0403ea3e1914b300 Mon Sep 17 00:00:00 2001 From: Alan Nichol Date: Wed, 27 Sep 2023 17:30:27 +0200 Subject: [PATCH 06/11] update tutorial to use new flows format --- docs/docs/tutorial.mdx | 167 ++++++++++++++++++----------------------- 1 file changed, 75 insertions(+), 92 deletions(-) diff --git a/docs/docs/tutorial.mdx b/docs/docs/tutorial.mdx index cda47a3d6894..4102e8fced72 100644 --- a/docs/docs/tutorial.mdx +++ b/docs/docs/tutorial.mdx @@ -127,18 +127,11 @@ Let's look at this definition to see what is going on: ```yaml-rasa title="flows.yml" flows: transfer_money: - description: | - This flow lets users send money to friends - and family, in US Dollars. + description: This flow lets users send money to friends and family. steps: - - id: "ask_recipient" - collect_information: recipient - next: "ask_amount" - - id: "ask_amount" - collect_information: amount - next: "transfer_successful" - - id: "transfer_successful" - action: utter_transfer_complete + - collect: recipient + - collect: amount + - action: utter_transfer_complete ``` The two key attributes of the `transfer_money` flow are the `description` and the `steps`. @@ -148,44 +141,37 @@ If a user says "I need to transfer some money", the description helps Rasa under The `steps` describe the business logic required to do what the user asked for. -There are three steps defined, each with an `id`. -The `id` can be anything you like, but it's a good idea to use names that make it clear what is going on. -The first step is a `collect_information` step, which is used to fill a `slot`. -A `collect_information` step sends a message to the user requesting information, and waits for an answer. +There are three steps defined. +The first step is a `collect` step, which is used to fill a `slot`. +A `collect` step sends a message to the user requesting information, and waits for an answer. ## Collecting Information in Slots -`Slots` are a key-value memory store used during a conversation. +`Slots` are variables your assistant can read and write throughout a conversation. Slots are defined in your `domain.yml` file. For example, the definition of your `recipient` slot looks like this: ```yaml-rasa title="domain.yml" slots: recipient: type: text - mappings: - - type: custom # ... ``` -They can be used to store information provided to you by the user or fetched via an API call. +Slots can be used to store information that users provide during the conversation, +or information that has been fetched via an API call. First, you're going to see how to store information provided by the end user in a slot. -To do this, you define a `collect_information` step like the first step in your flow above. +To do this, you define a `collect` step like the first step in your flow above. ```yaml-rasa title="flows.yml" flows: transfer_money: description: This flow lets users send money to friends and family. steps: - - id: "ask_recipient" - # highlight-next-line - collect_information: recipient - next: "ask_amount" - - id: "ask_amount" - collect_information: amount - next: "transfer_successful" - - id: "transfer_successful" - action: utter_transfer_complete + # highlight-next-line + - collect: recipient + - collect: amount + - action: utter_transfer_complete ``` Rasa will look for a `response` called `utter_ask_recipient` in your domain file and use this to @@ -199,7 +185,8 @@ responses: After sending this message, Rasa will wait for a response from the user. When the user responds, Rasa will try to use their answer to fill the slot `recipient`. -Read about [slot validation](./concepts/slot-validation-actions.mdx) to learn more about how to run additional checks on slot values. +Read about [slot validation](./concepts/slot-validation-actions.mdx) to learn how you +can run extra checks on the slot values Rasa has extracted. The diagram below summarizes how slot values are used to collect and store information, and how they can be used to create branching logic. @@ -211,7 +198,7 @@ and how they can be used to create branching logic. ## Action Steps -The third `step` in your `transfer_money` flow is not a `collect_information` step but an `action` step. +The third `step` in your `transfer_money` flow is not a `collect` step but an `action` step. When you reach an action step in a flow, your assistant will execute the corresponding action and then proceed to the next step. It will not stop to wait for the user's next message. @@ -222,15 +209,10 @@ flows: transfer_money: description: This flow lets users send money to friends and family. steps: - - id: "ask_recipient" - collect_information: recipient - next: "ask_amount" - - id: "ask_amount" - collect_information: amount - next: "transfer_successful" - - id: "transfer_successful" - # highlight-next-line - action: utter_transfer_complete + - collect: recipient + - collect: amount + # highlight-next-line + - action: utter_transfer_complete ``` ## Branching Logic @@ -246,19 +228,16 @@ which you will call `final_confirmation`. In your domain file, add the definition of the `final_confirmation` slot and the corresponding response: `utter_ask_final_confirmation`. +Also add a response to confirm the transfer has been cancelled. ```yaml-rasa title="domain.yml" slots: recipient: type: Text - mappings: - - type: custom # ... # highlight-start final_confirmation: type: bool - mappings: - - type: custom # highlight-end ``` @@ -270,43 +249,45 @@ responses: # highlight-start utter_ask_final_confirmation: - text: "Please confirm: you want to transfer {amount} to {recipient}?" + utter_transfer_cancelled: + - text: "Your transfer has been cancelled." # highlight-end ``` Notice that your confirmation question uses curly brackets `{}` to include slot values in your response. -Add a `collect_information` step to your flow and give it the id `confirm_transfer`. -Also change the `next` attribute of the `ask_amount` step to match the `id` of your newly created step: `confirm_transfer`. +Now add the branching logic to your flow. +First, add a `collect` step to your flow for the slot `final_confirmation`. +This step has a `next` attribute which implements the branching logic. +The expression after `if:` is a condition which will be evaluated to return `True` or `False`. +We're using the value of the boolean slot in the expression `not final_confirmation`. +You can learn more about conditions and advanced logic [here](./concepts/flows.mdx). +Notice that the final step in your flow now has an additional `id` attribute. +A `then` or `else` key can either be followed by a list of steps, or by the `id` +of a step to jump to. +The `id` is required for any step to be the target of a `then` or `else` statement. ```yaml-rasa title="flows.yml" flows: transfer_money: description: This flow lets users send money to friends and family. steps: - - id: "ask_recipient" - collect_information: recipient - next: "ask_amount" - - id: "ask_amount" - collect_information: amount - # highlight-start - next: "confirm_transfer" - - id: "confirm_transfer" - collect_information: final_confirmation + - collect: recipient + - collect: amount + # highlight-start + - collect: final_confirmation next: - - if: final_confirmation - then: "transfer_successful" - # highlight-end - - id: "transfer_successful" + - if: not final_confirmation + then: + - action: utter_transfer_cancelled + next: END + - else: transfer_successful + - id: transfer_successful + # highlight-end action: utter_transfer_complete - ``` -The `next` attribute of your `confirm_transfer` step includes a `condition`. -The expression after the `if:` key will be evaluated and return `True` or `False`. -In this case, we're using the value of the boolean slot `final_confirmation`. -Conditions can be used to create branching logic, including logical operators like `AND`, `OR`, etc. -You can learn more about conditions and advanced logic [here](./concepts/flows.mdx). To try out the updated version of your assistant, run `rasa train`, and then `rasa shell` to talk to your assistant. It should now ask you to confirm before completing the transfer. @@ -320,14 +301,18 @@ If you want to ensure that your assistant explicitly asks the user before fillin you can set the attribute `ask_before_filling` to `true` in your `collect` step. For example, to ensure that you always ask a user for confirmation, your flow step would look like this: -``` - - id: "confirm_transfer" - collect_information: final_confirmation - # highlight-next-line - ask_before_filling: true +```yaml-rasa title="flows.yml" +flows: + transfer_money: + description: This flow lets users send money to friends and family. + steps: + - collect: recipient + - collect: amount + - collect: final_confirmation + # highlight-next-line + ask_before_filling: true next: - - if: final_confirmation - then: "transfer_successful" + ... ``` ## Integrating an API call @@ -415,28 +400,26 @@ flows: transfer_money: description: This flow lets users send money to friends and family. steps: - - id: "ask_recipient" - collect_information: recipient - next: "ask_amount" - - id: "ask_amount" - collect_information: amount - # highlight-start - next: "check_funds" - - id: "check_funds" - action: action_check_sufficient_funds + - collect: recipient + - collect: amount + # highlight-start + - action: action_check_sufficient_funds next: - - if: has_sufficient_funds - then: "confirm_transfer" - - else: "insufficient_funds" - - id: "insufficient_funds" - action: utter_insufficient_funds - # highlight-end - - id: "confirm_transfer" - collect_information: final_confirmation + - if: not has_sufficient_funds + then: + - action: utter_insufficient_funds + next: END + - else: final_confirmation + - id: final_confirmation + # highlight-end + collect: final_confirmation next: - - if: final_confirmation - then: "transfer_successful" - - id: "transfer_successful" + - if: not final_confirmation + then: + - action: utter_transfer_cancelled + next: END + - else: transfer_successful + - id: transfer_successful action: utter_transfer_complete ``` From f2f12530b3c271adfc125a2b47eb4c0ab774d4ea Mon Sep 17 00:00:00 2001 From: Alan Nichol Date: Wed, 27 Sep 2023 17:40:23 +0200 Subject: [PATCH 07/11] Revert "not working yet, trying to get a custom 'deleted line' magic comment" This reverts commit df2a7adef784be256b8df96bf4d40ce02ccce653. --- docs/docs/tutorial.mdx | 4 ---- docs/docusaurus.config.js | 13 ------------- docs/themes/theme-custom/custom.css | 8 -------- 3 files changed, 25 deletions(-) diff --git a/docs/docs/tutorial.mdx b/docs/docs/tutorial.mdx index 4102e8fced72..108f0c9747af 100644 --- a/docs/docs/tutorial.mdx +++ b/docs/docs/tutorial.mdx @@ -14,10 +14,6 @@ This tutorial does not assume and existing knowledge of Rasa or chatbots. The techniques you will learn in this tutorial are fundamental to building any Rasa assistant, and understanding it will bring you quite far along to mastering Rasa. -```python -# highlight-deleted-line -rasa init --template tutorial -``` ## What are you building? diff --git a/docs/docusaurus.config.js b/docs/docusaurus.config.js index f29120fee1aa..04d57a468278 100644 --- a/docs/docusaurus.config.js +++ b/docs/docusaurus.config.js @@ -132,19 +132,6 @@ module.exports = { gtm: { containerID: 'GTM-MMHSZCS', }, - prism: { - magicComments: [ - { - className: 'theme-code-block-highlighted-line', - line: 'highlight-next-line', - block: {start: 'highlight-start', end: 'highlight-end'}, - }, - { - className: 'code-block-deleted-line', - line: 'highlight-deleted-line', - }, - ], - }, }, themes: [ '@docusaurus/theme-search-algolia', diff --git a/docs/themes/theme-custom/custom.css b/docs/themes/theme-custom/custom.css index aa5a6bd00825..f66cfae04340 100644 --- a/docs/themes/theme-custom/custom.css +++ b/docs/themes/theme-custom/custom.css @@ -37,11 +37,3 @@ .prose th:empty, [class^=prose-] th:empty, [class*=" prose-"] th:empty { border-style: none; } - -.code-block-deleted-line { - background-color: #ff000020; - display: block; - margin: 0 calc(-1 * var(--ifm-pre-padding)); - padding: 0 var(--ifm-pre-padding); - border-left: 3px solid #ff000080; -} From 410ec8ca40c2e1ea2f0ee893a1415406ee2d093b Mon Sep 17 00:00:00 2001 From: Alan Nichol Date: Thu, 28 Sep 2023 14:17:00 +0200 Subject: [PATCH 08/11] update example convos at top of tutorial --- docs/docs/tutorial.mdx | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/docs/docs/tutorial.mdx b/docs/docs/tutorial.mdx index ff5d0c23c257..09f6b701d594 100644 --- a/docs/docs/tutorial.mdx +++ b/docs/docs/tutorial.mdx @@ -24,7 +24,7 @@ Here are some of the conversations your assistant will be able to handle: - I'd like to transfer some money - Sure - who are we sending money to? - Jen + I want to send money + Who would you like to send money to? + to Jen How much would you like to send? $50 - Just to confirm: you want to send $50 to Jen? + Please confirm: you want to transfer $50.0 to Jen? yes - Ok, it's done! + All done. $50.0 has been sent to Jen. + Is there anything else I can help you with?! - I want to send $100 to Joe + I want to send 100 dollars to Joe - Just to confirm, you want to send $100.00 to Joe Smith? + Please confirm: you want to transfer $100.0 to Joe? yes. - All done. $100.00 has been sent to Joe Smith. + All done. $100.00 has been sent to Joe. + Is there anything else I can help you with? + + + + + I need to send $ 50 + Who would you like to send money to? + Jen + Please confirm: you want to transfer $50.0 to Jen? + actually no 60 + Ok, I corrected the amount. + Please confirm: you want to transfer $60.0 to Jen? + yes. + All done. $60.00 has been sent to Jen. Is there anything else I can help you with? From e562e1ad076f2c07235f346077bb52daf973d000 Mon Sep 17 00:00:00 2001 From: Alan Nichol Date: Tue, 17 Oct 2023 14:53:36 +0200 Subject: [PATCH 09/11] wip tutorial improvements --- docs/docs/tutorial.mdx | 63 ++++++++++++++++++++++++++++++++---------- 1 file changed, 49 insertions(+), 14 deletions(-) diff --git a/docs/docs/tutorial.mdx b/docs/docs/tutorial.mdx index 09f6b701d594..c1fee44c0ecc 100644 --- a/docs/docs/tutorial.mdx +++ b/docs/docs/tutorial.mdx @@ -151,6 +151,7 @@ flows: steps: - collect: recipient - collect: amount + description: the number of US dollars to send - action: utter_transfer_complete ``` @@ -160,15 +161,13 @@ But it is also helpful for anyone who inspects your code to understand what is g If a user says "I need to transfer some money", the description helps Rasa understand that this is the relevant flow. The `steps` describe the business logic required to do what the user asked for. -There are three steps defined, each with an `id`. -The `id` can be anything you like, but it's a good idea to use names that make it clear what is going on. -The first step is a `collect_information` step, which is used to fill a `slot`. -A `collect_information` step sends a message to the user requesting information, and waits for an answer. +The first step in your flow is a `collect` step, which is used to fill a `slot`. +A `collect` step sends a message to the user requesting information, and waits for an answer. ## Collecting Information in Slots -`Slots` are variables your assistant can read and write throughout a conversation. +`Slots` are variables that your assistant can read and write throughout a conversation. Slots are defined in your `domain.yml` file. For example, the definition of your `recipient` slot looks like this: ```yaml-rasa title="domain.yml" @@ -191,6 +190,7 @@ flows: # highlight-next-line - collect: recipient - collect: amount + description: the number of US dollars to send - action: utter_transfer_complete ``` @@ -216,6 +216,24 @@ and how they can be used to create branching logic. src={useBaseUrl("/img/slots_in_flows.png")} /> +### Descriptions in collect steps + +The second `collect` step includes a description of the information your assistant +will request from the user. +Descriptions are optional, but can help Rasa extract slot values more reliably. + +```yaml-rasa title="flows.yml" +flows: + transfer_money: + description: This flow lets users send money to friends and family. + steps: + - collect: recipient + - collect: amount + # highlight-next-line + description: the number of US dollars to send + - action: utter_transfer_complete +``` + ## Action Steps The third `step` in your `transfer_money` flow is not a `collect` step but an `action` step. @@ -231,6 +249,7 @@ flows: steps: - collect: recipient - collect: amount + description: the number of US dollars to send # highlight-next-line - action: utter_transfer_complete ``` @@ -276,8 +295,15 @@ responses: Notice that your confirmation question uses curly brackets `{}` to include slot values in your response. -Add a `collect_information` step to your flow and give it the id `confirm_transfer`. -Also change the `next` attribute of the `ask_amount` step to match the `id` of your newly created step: `confirm_transfer`. +Add a `collect` step to your flow for the slot `final_confirmation`. +This step includes a `next` attribute with your branching logic. +The expression after the `if` key will be evaluated to true or false to determine +the next step in your flow. +The `then` and `else` keys can contain either a list of steps or the `id` of a step +to jump to. +In this case, the `then` key contains an `action` step to inform the user their transfer +was cancelled. The `else` key contains the id `transfer_successful`. +Notice that you've added this `id` to the final step in your flow. ```yaml-rasa title="flows.yml" @@ -287,6 +313,7 @@ flows: steps: - collect: recipient - collect: amount + description: the number of US dollars to send # highlight-start - collect: final_confirmation next: @@ -295,9 +322,12 @@ flows: - action: utter_transfer_cancelled next: END - else: transfer_successful - - id: transfer_successful # highlight-end - action: utter_transfer_complete + - action: utter_transfer_complete + # highlight-next-line + id: transfer_successful + + ``` @@ -384,6 +414,9 @@ responses: Now you are going to update your flow logic to handle the cases where the user does or does not have enough money in their account to make the transfer. +Notice that your `collect: final_confirmation` step now also has an id so that your branching logic +can jump to it. + ```yaml-rasa title="flows.yml" flows: transfer_money: @@ -391,6 +424,7 @@ flows: steps: - collect: recipient - collect: amount + description: the number of US dollars to send # highlight-start - action: action_check_sufficient_funds next: @@ -399,17 +433,18 @@ flows: - action: utter_insufficient_funds next: END - else: final_confirmation - - id: final_confirmation - # highlight-end - collect: final_confirmation + # highlight-end + - collect: final_confirmation + # highlight-next-line + id: final_confirmation next: - if: not final_confirmation then: - action: utter_transfer_cancelled next: END - else: transfer_successful - - id: transfer_successful - action: utter_transfer_complete + - action: utter_transfer_complete + id: transfer_successful ``` ## Testing your Custom Action From 4852c9b71e2fb74d1df91256dc090926a0a63e3d Mon Sep 17 00:00:00 2001 From: Alan Nichol Date: Thu, 19 Oct 2023 16:45:27 -0400 Subject: [PATCH 10/11] remove header for nonexistent example conversation --- docs/docs/tutorial.mdx | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/docs/tutorial.mdx b/docs/docs/tutorial.mdx index c1fee44c0ecc..9c4873671272 100644 --- a/docs/docs/tutorial.mdx +++ b/docs/docs/tutorial.mdx @@ -26,7 +26,6 @@ Here are some of the conversations your assistant will be able to handle: { label: "Happy path", value: "happy-path" }, { label: "All at once", value: "all-upfront" }, { label: "Change of mind", value: "change-mind" }, - { label: "Interjection", value: "interjection" }, ]} groupId="example-conversations" defaultValue="happy-path" From f22a4cb7a2a02d7b3943533123efe866f69c0acc Mon Sep 17 00:00:00 2001 From: Alan Nichol Date: Fri, 20 Oct 2023 15:30:40 +0200 Subject: [PATCH 11/11] Update docs/docs/tutorial.mdx Co-authored-by: Maxime Vdb --- docs/docs/tutorial.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/docs/tutorial.mdx b/docs/docs/tutorial.mdx index 9c4873671272..96756f9a15b0 100644 --- a/docs/docs/tutorial.mdx +++ b/docs/docs/tutorial.mdx @@ -56,7 +56,7 @@ Here are some of the conversations your assistant will be able to handle: - I need to send $ 50 + I need to send $50 Who would you like to send money to? Jen Please confirm: you want to transfer $50.0 to Jen?