From 40b41ee770c91bab211e489fdab35334b54fe84d Mon Sep 17 00:00:00 2001 From: Alan Nichol Date: Mon, 25 Sep 2023 11:57:28 +0200 Subject: [PATCH] use (completed) tutorial bot as example - wip --- examples/money_transfer/actions.py | 19 ++++++++ examples/money_transfer/config.yml | 13 ++++++ examples/money_transfer/data/flows.yml | 28 ++++++++++++ examples/money_transfer/domain.yml | 43 +++++++++++++++++++ .../e2e_tests/complete_request.yml | 7 +++ examples/money_transfer/endpoints.yml | 42 ++++++++++++++++++ 6 files changed, 152 insertions(+) create mode 100644 examples/money_transfer/actions.py create mode 100644 examples/money_transfer/config.yml create mode 100644 examples/money_transfer/data/flows.yml create mode 100644 examples/money_transfer/domain.yml create mode 100644 examples/money_transfer/e2e_tests/complete_request.yml create mode 100644 examples/money_transfer/endpoints.yml diff --git a/examples/money_transfer/actions.py b/examples/money_transfer/actions.py new file mode 100644 index 000000000000..6c515f02c1ee --- /dev/null +++ b/examples/money_transfer/actions.py @@ -0,0 +1,19 @@ +from typing import Any, Text, Dict, List +from rasa_sdk import Action, Tracker +from rasa_sdk.executor import CollectingDispatcher +from rasa_sdk.events import SlotSet + +class ActionSufficientFunds(Action): + def name(self) -> Text: + return "action_sufficient_funds" + + def run(self, dispatcher: CollectingDispatcher, + tracker: Tracker, + domain: Dict[Text, Any]) -> List[Dict[Text, Any]]: + balance = 1000 # hard-coded for tutorial purposes + # a real api call would look something like + # result = requests.get("https://example.com/api/balance") + # balance = result.json()["balance"] + transfer_amount = tracker.get_slot("amount") + has_sufficient_funds = transfer_amount <= balance + return [SlotSet("has_sufficient_funds", has_sufficient_funds)] diff --git a/examples/money_transfer/config.yml b/examples/money_transfer/config.yml new file mode 100644 index 000000000000..3801f4a2c879 --- /dev/null +++ b/examples/money_transfer/config.yml @@ -0,0 +1,13 @@ +recipe: default.v1 +language: en +pipeline: + - name: LLMCommandGenerator + llm: + model_name: gpt-4 + +policies: + - name: rasa.core.policies.flow_policy.FlowPolicy +# - name: rasa_plus.ml.DocsearchPolicy +# - name: RulePolicy + +assistant_id: 20230405-114328-tranquil-mustard diff --git a/examples/money_transfer/data/flows.yml b/examples/money_transfer/data/flows.yml new file mode 100644 index 000000000000..21f49a366167 --- /dev/null +++ b/examples/money_transfer/data/flows.yml @@ -0,0 +1,28 @@ +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: "check_funds" + - id: "check_funds" + action: action_sufficient_funds + next: + - if: has_sufficient_funds + then: "confirm_transfer" + - else: "insufficient_funds" + - id: "insufficient_funds" + action: utter_insufficient_funds + - id: "confirm_transfer" + collect_information: final_confirmation + next: + - if: final_confirmation + then: "transfer_successful" + - else: "transfer_cancelled" + - id: "transfer_cancelled" + action: utter_transfer_cancelled + - id: "transfer_successful" + action: utter_transfer_complete \ No newline at end of file diff --git a/examples/money_transfer/domain.yml b/examples/money_transfer/domain.yml new file mode 100644 index 000000000000..5cdd8dc3fe1c --- /dev/null +++ b/examples/money_transfer/domain.yml @@ -0,0 +1,43 @@ +version: "3.1" + +slots: + recipient: + type: text + mappings: + - type: custom + amount: + type: float + mappings: + - type: custom + final_confirmation: + type: bool + mappings: + - type: custom + has_sufficient_funds: + type: bool + mappings: + - type: custom + +responses: + utter_ask_recipient: + - text: "Who would you like to send money to?" + + utter_ask_amount: + - text: "How much money would you like to send?" + + utter_transfer_complete: + - text: "All done. ${amount} has been sent to {recipient}." + + utter_ask_final_confirmation: + - text: "Please confirm: you want to transfer ${amount} to {recipient}?" + + utter_transfer_cancelled: + - text: "Your transfer has been cancelled." + + utter_insufficient_funds: + - text: "You do not have enough funds to make this transaction." + + + +actions: + - action_sufficient_funds diff --git a/examples/money_transfer/e2e_tests/complete_request.yml b/examples/money_transfer/e2e_tests/complete_request.yml new file mode 100644 index 000000000000..99072cb957c9 --- /dev/null +++ b/examples/money_transfer/e2e_tests/complete_request.yml @@ -0,0 +1,7 @@ +test_cases: + - test_case: user corrects recipient in the next message + steps: + - user: I want to send 400 dollars to James + - utter: utter_ask_final_confirmation + - user: yes + - utter: utter_transfer_complete diff --git a/examples/money_transfer/endpoints.yml b/examples/money_transfer/endpoints.yml new file mode 100644 index 000000000000..5f65275b8802 --- /dev/null +++ b/examples/money_transfer/endpoints.yml @@ -0,0 +1,42 @@ +# This file contains the different endpoints your bot can use. + +# Server where the models are pulled from. +# https://rasa.com/docs/rasa/model-storage#fetching-models-from-a-server + +#models: +# url: http://my-server.com/models/default_core@latest +# wait_time_between_pulls: 10 # [optional](default: 100) + +# Server which runs your custom actions. +# https://rasa.com/docs/rasa/custom-actions + +action_endpoint: + url: "http://localhost:5055/webhook" + +# Tracker store which is used to store the conversations. +# By default the conversations are stored in memory. +# https://rasa.com/docs/rasa/tracker-stores + +#tracker_store: +# type: redis +# url: +# port: +# db: +# password: +# use_ssl: + +#tracker_store: +# type: mongod +# url: +# db: +# username: +# password: + +# Event broker which all conversation events should be streamed to. +# https://rasa.com/docs/rasa/event-brokers + +#event_broker: +# url: localhost +# username: username +# password: password +# queue: queue