Skip to content

Commit

Permalink
Merge branch 'dm2' into ENG-472-Component-Wrap-up-LLMCommandGenerator
Browse files Browse the repository at this point in the history
  • Loading branch information
djcowley committed Oct 20, 2023
2 parents 09a56a1 + 69fef21 commit 2981e0d
Show file tree
Hide file tree
Showing 103 changed files with 963 additions and 83 deletions.
1 change: 1 addition & 0 deletions changelog/12901.improvement.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added Schema file and schema validation for flows.
2 changes: 1 addition & 1 deletion docs/docs/action-server/knowledge-base-actions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ You can customize your `InMemoryKnowledgeBase` by overwriting the following func
You can overwrite it by calling the function `set_ordinal_mention_mapping()`.
If you want to learn more about how this mapping is used, check out [Resolve Mentions](./knowledge-base-actions.mdx#resolve-mentions).

See the [example bot](https://github.com/RasaHQ/rasa/blob/main/examples/knowledgebasebot/actions/actions.py) for an
See the [example bot](https://github.com/RasaHQ/rasa/blob/main/examples/nlu_based/knowledgebasebot/actions/actions.py) for an
example implementation of an `InMemoryKnowledgeBase` that uses the method `set_representation_function_of_object()`
to overwrite the default representation of the object type “hotel.”
The implementation of the `InMemoryKnowledgeBase` itself can be found in the
Expand Down
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:

```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!`.
4 changes: 3 additions & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@
"\\.prototyping\\.rasa\\.com",
"^https://github\\.com/mit-nlp/MITIE/releases/download/v0\\.4/MITIE-models-v0\\.2\\.tar\\.bz2$",
"^https://forum.rasa.com/t/rasa-open-source-2-0-is-out-now-internal-draft/35577$",
"https://docs-test-001.openai.azure.com"
"https://docs-test-001.openai.azure.com",
"^https://github.com/RasaHQ/rasa/tree/main/examples/*",
"^https://github.com/RasaHQ/rasa/blob/main/examples/*"
]
}
]
Expand Down
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
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.
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.
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.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ exclude = "((.eggs | .git | .pytest_cache | build | dist))"

[tool.poetry]
name = "rasa"
version = "3.8.0a11"
version = "3.8.0a12"
description = "Open source machine learning framework to automate text- and voice-based conversations: NLU, dialogue management, connect to Slack, Facebook, and more - Create chatbots and voice assistants"
authors = [ "Rasa Technologies GmbH <[email protected]>",]
maintainers = [ "Tom Bocklisch <[email protected]>",]
Expand Down
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: 8 additions & 0 deletions rasa/core/actions/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
)
from rasa.shared.core import events
from rasa.shared.core.constants import (
DIALOGUE_STACK_SLOT,
USER_INTENT_OUT_OF_SCOPE,
ACTION_LISTEN_NAME,
ACTION_RESTART_NAME,
Expand Down Expand Up @@ -829,6 +830,13 @@ async def run(
)

evts = events.deserialise_events(events_json)
# filter out `SlotSet` events for internal `dialogue_stack` slot
evts = [
event
for event in evts
if not (isinstance(event, SlotSet) and event.key == DIALOGUE_STACK_SLOT)
]

return cast(List[Event], bot_messages) + evts

except ClientResponseError as e:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,15 @@ flows:
- action: validate_{{context.collect}}
next:
- if: "{{context.collect}} is not null"
then: "done"
then: "END"
- else: "ask_collect"
- id: "ask_collect"
action: "{{context.utter}}"
next: "listen"
- id: "listen"
action: action_listen
next: "start"
- id: "done"


pattern_code_change:
description: flow used to clean the stack after a bot update
Expand Down
21 changes: 18 additions & 3 deletions rasa/shared/core/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -993,7 +993,12 @@ def _add_flow_slots(self) -> None:
for flow_slot in FLOW_SLOT_NAMES:
if flow_slot not in slot_names:
self.slots.append(
AnySlot(flow_slot, mappings=[], influence_conversation=False)
AnySlot(
flow_slot,
mappings=[],
influence_conversation=False,
is_builtin=True,
)
)
else:
# TODO: figure out what to do here.
Expand All @@ -1016,6 +1021,7 @@ def _add_requested_slot(self) -> None:
rasa.shared.core.constants.REQUESTED_SLOT,
mappings=[],
influence_conversation=False,
is_builtin=True,
)
)

Expand All @@ -1041,12 +1047,21 @@ def _add_knowledge_base_slots(self) -> None:
for slot in KNOWLEDGE_BASE_SLOT_NAMES:
if slot not in slot_names:
self.slots.append(
TextSlot(slot, mappings=[], influence_conversation=False)
TextSlot(
slot,
mappings=[],
influence_conversation=False,
is_builtin=True,
)
)

def _add_session_metadata_slot(self) -> None:
self.slots.append(
AnySlot(rasa.shared.core.constants.SESSION_START_METADATA_SLOT, mappings=[])
AnySlot(
rasa.shared.core.constants.SESSION_START_METADATA_SLOT,
mappings=[],
is_builtin=True,
)
)

def index_for_action(self, action_name: Text) -> int:
Expand Down
Loading

0 comments on commit 2981e0d

Please sign in to comment.