Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

moved existing examples into subfolder #12860

Merged
merged 18 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/docs/domain.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ abstract: The domain defines the universe in which your assistant operates. It s
---

Here is a full example of a domain, taken from the
[concertbot](https://github.com/RasaHQ/rasa/tree/main/examples/concertbot) example:
[concertbot](https://github.com/RasaHQ/rasa/tree/main/examples/nlu_based/concertbot) example:
amn41 marked this conversation as resolved.
Show resolved Hide resolved

```yaml-rasa (docs/sources/examples/concertbot/domain.yml)
```yaml-rasa (docs/sources/examples/nlu_based/concertbot/domain.yml)
```

## Multiple Domain Files
Expand Down
10 changes: 5 additions & 5 deletions docs/docs/reaching-out-to-user.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Sometimes you want an external device to change the course of an ongoing convers
For example, if you have a moisture-sensor attached to a Raspberry Pi, you could use it to notify
you when a plant needs watering via your assistant.

The examples below are from the [reminderbot example bot](https://github.com/RasaHQ/rasa/blob/main/examples/reminderbot),
The examples below are from the [reminderbot example bot](https://github.com/RasaHQ/rasa/blob/main/examples/nlu_based/reminderbot),
which includes both reminders and external events.

### 1. Trigger an Intent
Expand Down Expand Up @@ -90,7 +90,7 @@ In a real-life scenario, your external device would get the conversation ID from
In the dry plant example, you might have a database of plants, the users that water them, and the users'
conversation IDs. Your Raspberry Pi would get the conversation ID directly from the database.
To try out the reminderbot example locally, you'll need to get the conversation ID manually. See
the reminderbot [README](https://github.com/RasaHQ/rasa/blob/main/examples/reminderbot) for more information.
the reminderbot [README](https://github.com/RasaHQ/rasa/blob/main/examples/nlu_based/reminderbot) for more information.

### 3. Add NLU Training Data

Expand Down Expand Up @@ -159,7 +159,7 @@ External Events and Reminders don't work in request-response channels like the `
Custom connectors for assistants implementing reminders or external events should be built
off of the [CallbackInput channel](./connectors/your-own-website.mdx#callbackinput) instead of the RestInput channel.

See the [reminderbot README](https://github.com/RasaHQ/rasa/blob/main/examples/reminderbot/README.md)
See the [reminderbot README](https://github.com/RasaHQ/rasa/blob/main/examples/nlu_based/reminderbot/README.md)
for instructions on how to test your reminders locally.
:::

Expand All @@ -180,7 +180,7 @@ You should see the bot respond in your channel:
## Reminders

You can have your assistant reach out to the user after a set amount of time by using [Reminders](./action-server/events.mdx#reminder).
The examples below are from the [reminderbot example bot](https://github.com/RasaHQ/rasa/blob/main/examples/reminderbot).
The examples below are from the [reminderbot example bot](https://github.com/RasaHQ/rasa/blob/main/examples/nlu_based/reminderbot).
You can clone it and follow the instructions in `README` to try out the full version.

### Scheduling Reminders
Expand Down Expand Up @@ -432,7 +432,7 @@ intents:

To try out reminders you'll need to start a [CallbackChannel](./connectors/your-own-website.mdx#callbackinput).
You'll also need to start the action server to schedule, react to, and cancel your reminders.
See the [reminderbot README](https://github.com/RasaHQ/rasa/blob/main/examples/reminderbot) for details.
See the [reminderbot README](https://github.com/RasaHQ/rasa/blob/main/examples/nlu_based/reminderbot) for details.

Then, if you send the bot a message like `Remind me to call Paul Pots`, you should get a reminder
back five minutes later that says `Remember to call Paul Pots!`.
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 ActionCheckSufficientFunds(Action):
def name(self) -> Text:
return "action_check_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
23 changes: 23 additions & 0 deletions examples/money_transfer/data/flows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
flows:
transfer_money:
description: This flow lets users send money to friends and family.
steps:
- collect: recipient
- collect: amount
- action: action_check_sufficient_funds
next:
- if: not has_sufficient_funds
then:
- action: utter_insufficient_funds
next: END
- else: final_confirmation
- id: final_confirmation
collect: final_confirmation
next:
- if: not final_confirmation
then:
- action: utter_transfer_cancelled
next: END
- else: transfer_successful
- id: transfer_successful
action: utter_transfer_complete
amn41 marked this conversation as resolved.
Show resolved Hide resolved
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_check_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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
42 changes: 42 additions & 0 deletions examples/nlu_based/reminderbot/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
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
11 changes: 3 additions & 8 deletions rasa/cli/project_templates/tutorial/data/flows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@ flows:
transfer_money:
description: This flow lets users send money to friends and family.
steps:
- id: "ask_recipient"
collect: recipient
next: "ask_amount"
- id: "ask_amount"
collect: amount
next: "transfer_successful"
- id: "transfer_successful"
action: utter_transfer_complete
- collect: recipient
- collect: amount
- action: utter_transfer_complete
8 changes: 4 additions & 4 deletions tests/core/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,11 @@ def default_tracker(domain: Domain) -> DialogueStateTracker:
@pytest.fixture(scope="session")
async def trained_formbot(trained_async: Callable) -> Text:
return await trained_async(
domain="examples/formbot/domain.yml",
config="examples/formbot/config.yml",
domain="examples/nlu_based/formbot/domain.yml",
config="examples/nlu_based/formbot/config.yml",
training_files=[
"examples/formbot/data/rules.yml",
"examples/formbot/data/stories.yml",
"examples/nlu_based/formbot/data/rules.yml",
"examples/nlu_based/formbot/data/stories.yml",
],
)

Expand Down
8 changes: 4 additions & 4 deletions tests/core/policies/test_rule_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,7 @@ def test_rule_policy_finetune(
)

original_data = training.load_data(
"examples/rules/data/rules.yml", trained_rule_policy_domain
"examples/nlu_based/rules/data/rules.yml", trained_rule_policy_domain
)

loaded_policy.train(original_data + [new_rule], trained_rule_policy_domain)
Expand Down Expand Up @@ -805,7 +805,7 @@ def test_rule_policy_contradicting_rule_finetune(
)

original_data = training.load_data(
"examples/rules/data/rules.yml", trained_rule_policy_domain
"examples/nlu_based/rules/data/rules.yml", trained_rule_policy_domain
)

with pytest.raises(InvalidRule) as execinfo:
Expand Down Expand Up @@ -1847,15 +1847,15 @@ def test_immediate_submit(policy: RulePolicy):

@pytest.fixture()
def trained_rule_policy_domain() -> Domain:
return Domain.load("examples/rules/domain.yml")
return Domain.load("examples/nlu_based/rules/domain.yml")


@pytest.fixture()
def trained_rule_policy(
trained_rule_policy_domain: Domain, policy: RulePolicy
) -> RulePolicy:
trackers = training.load_data(
"examples/rules/data/rules.yml", trained_rule_policy_domain
"examples/nlu_based/rules/data/rules.yml", trained_rule_policy_domain
)

policy.train(trackers, trained_rule_policy_domain)
Expand Down
2 changes: 1 addition & 1 deletion tests/dialogues.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,6 @@

TEST_DOMAINS_FOR_DIALOGUES = [
"data/test_domains/default_with_slots.yml",
"examples/formbot/domain.yml",
"examples/nlu_based/formbot/domain.yml",
"data/test_moodbot/domain.yml",
]
30 changes: 15 additions & 15 deletions tests/examples/test_example_bots_training_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,23 @@
"config_file, domain_file, data_folder, raise_slot_warning, msg",
[
(
"examples/concertbot/config.yml",
"examples/concertbot/domain.yml",
"examples/concertbot/data",
"examples/nlu_based/concertbot/config.yml",
"examples/nlu_based/concertbot/domain.yml",
"examples/nlu_based/concertbot/data",
True,
None,
),
(
"examples/formbot/config.yml",
"examples/formbot/domain.yml",
"examples/formbot/data",
"examples/nlu_based/formbot/config.yml",
"examples/nlu_based/formbot/domain.yml",
"examples/nlu_based/formbot/data",
True,
None,
),
(
"examples/knowledgebasebot/config.yml",
"examples/knowledgebasebot/domain.yml",
"examples/knowledgebasebot/data",
"examples/nlu_based/knowledgebasebot/config.yml",
"examples/nlu_based/knowledgebasebot/domain.yml",
"examples/nlu_based/knowledgebasebot/data",
True,
"You are using an experimental feature: "
"Action 'action_query_knowledge_base'!",
Expand All @@ -43,16 +43,16 @@
None,
),
(
"examples/reminderbot/config.yml",
"examples/reminderbot/domain.yml",
"examples/reminderbot/data",
"examples/nlu_based/reminderbot/config.yml",
"examples/nlu_based/reminderbot/domain.yml",
"examples/nlu_based/reminderbot/data",
True,
None,
),
(
"examples/rules/config.yml",
"examples/rules/domain.yml",
"examples/rules/data",
"examples/nlu_based/rules/config.yml",
"examples/nlu_based/rules/domain.yml",
"examples/nlu_based/rules/data",
True,
None,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def test_train_core_with_original_or_provided_domain_and_compare(
default_execution_context: ExecutionContext,
):
# Choose an example where the provider will remove a lot of information:
example = Path("examples/formbot/")
example = Path("examples/nlu_based/formbot/")
training_files = [example / "data" / "rules.yml"]

# Choose a configuration with a policy
Expand Down
6 changes: 4 additions & 2 deletions tests/graph_components/providers/test_rule_only_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ def test_provide(
):
resource = Resource("some resource")

domain = Domain.load("examples/rules/domain.yml")
trackers = rasa.core.training.load_data("examples/rules/data/rules.yml", domain)
domain = Domain.load("examples/nlu_based/rules/domain.yml")
trackers = rasa.core.training.load_data(
"examples/nlu_based/rules/data/rules.yml", domain
)

policy = RulePolicy.create(
RulePolicy.get_default_config(),
Expand Down
2 changes: 1 addition & 1 deletion tests/shared/core/test_slot_mappings.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def test_slot_mapping_entity_is_desired(slot_name: Text, expected: bool):


def test_slot_mapping_intent_is_desired(domain: Domain):
domain = Domain.from_file("examples/formbot/domain.yml")
domain = Domain.from_file("examples/nlu_based/formbot/domain.yml")
tracker = DialogueStateTracker("sender_id_test", slots=domain.slots)
event1 = UserUttered(
text="I'd like to book a restaurant for 2 people.",
Expand Down
2 changes: 1 addition & 1 deletion tests/test_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ def test_early_exit_on_invalid_domain():
def test_verify_there_is_not_example_repetition_in_intents():
importer = RasaFileImporter(
domain_path="data/test_moodbot/domain.yml",
training_data_paths=["examples/knowledgebasebot/data/nlu.yml"],
training_data_paths=["examples/nlu_based/knowledgebasebot/data/nlu.yml"],
)
validator = Validator.from_importer(importer)
# force validator to not ignore warnings (default is True)
Expand Down
Loading