Skip to content

Commit

Permalink
use (completed) tutorial bot as example - wip
Browse files Browse the repository at this point in the history
  • Loading branch information
amn41 committed Sep 25, 2023
1 parent a95f26d commit 40b41ee
Show file tree
Hide file tree
Showing 6 changed files with 152 additions and 0 deletions.
19 changes: 19 additions & 0 deletions examples/money_transfer/actions.py
Original file line number Diff line number Diff line change
@@ -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)]
13 changes: 13 additions & 0 deletions examples/money_transfer/config.yml
Original file line number Diff line number Diff line change
@@ -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
28 changes: 28 additions & 0 deletions examples/money_transfer/data/flows.yml
Original file line number Diff line number Diff line change
@@ -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
43 changes: 43 additions & 0 deletions examples/money_transfer/domain.yml
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions examples/money_transfer/e2e_tests/complete_request.yml
Original file line number Diff line number Diff line change
@@ -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
42 changes: 42 additions & 0 deletions examples/money_transfer/endpoints.yml
Original file line number Diff line number Diff line change
@@ -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: <host of the redis instance, e.g. localhost>
# port: <port of your redis instance, usually 6379>
# db: <number of your database within redis, e.g. 0>
# password: <password used for authentication>
# use_ssl: <whether or not the communication is encrypted, default false>

#tracker_store:
# type: mongod
# url: <url to your mongo instance, e.g. mongodb://localhost:27017>
# db: <name of the db within your mongo instance, e.g. rasa>
# username: <username used for authentication>
# password: <password used for authentication>

# 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

0 comments on commit 40b41ee

Please sign in to comment.