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

Llm dialogue docs #12530

Merged
merged 4 commits into from
Jun 20, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 3 additions & 4 deletions docs/docs/llms/large-language-models.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,9 @@ This section of the documentation guides you through the diverse ways you can
integrate LLMs into Rasa. We will delve into the following topics:

1. [Setting up LLMs](./llm-setup.mdx)
2. [Intent Classification with LLMs](./llm-intent.mdx)
3. [Dialogue Handling using LLMs](./llm-intentless.mdx)
4. [NLG using LLMs](./llm-nlg.mdx)
5. [Custom usage of LLMs](./llm-custom.mdx)
2. [IntentDialogues with LLMs & Flows](./llm-dialogue.mdx)
4. [Business Logic with Flows](../flows.mdx)
5. [Handling Unhappy Paths](./unhappy-paths.mdx)

Each link will direct you to a detailed guide on the respective topic, offering
further depth and information about using LLMs with Rasa. By the end of this
Expand Down
84 changes: 67 additions & 17 deletions docs/docs/llms/llm-dialogue.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ id: llm-dialogue
sidebar_label: Dialogues with LLMs & Flows
title: Dialogues with LLMs & Flows
abstract: |
Dialogue Management combining LLMs and business logic (Flows).
This documentation explores dialogue management by combining Large Language Models (LLMs) and business logic through Flows.
---

import RasaDiscoveryBanner from "@theme/RasaDiscoveryBanner";
Expand All @@ -12,27 +12,77 @@ import RasaDiscoveryBanner from "@theme/RasaDiscoveryBanner";

## Motivation

The approach combine the best of both worlds:
Our approach aims to harness the strengths of both Large Language Models (LLMs)
and the control needed for business logic. This innovative blend enables you to
manage both the flexible and predictable aspects of dialogues within your
chatbot.

- the flexibility of LLMs and
- the control of business logic.
By utilizing LLMs, we can effectively handle ["unhappy paths"—instances](../glossary.mdx#happy--unhappy-paths) where
user interactions diverge from the expected or desired course. Meanwhile,
business logic or 'Flows' are used to manage ["happy paths"—scenarios](../glossary.mdx#happy--unhappy-paths) where
interactions proceed as anticipated.

The idea is to use LLMs to handle unhappy paths and to use business logic to
handle happy paths.

The combination of LLMs and Flows avoids "black box" behavior. This approach
allows to limit the specification of business logic to a minimum and provides
ample opportunity to customize dialogue behavior.
Combining LLMs and Flows helps prevent "black box" behaviors, whereby the
chatbot's responses can seem inexplicable or out of control. With this method,
you only need to specify a minimal amount of business logic. At the same time,
it opens up a wide range of possibilities for customizing your chatbot's
dialogue behavior.

## Approach

- specify happy paths with business logic
- specify patterns of unhappy paths using separate flows
- use flows to keep track of state
- use LLMs to update flow states
Here's a breakdown of our approach:

- We specify 'happy paths' using business logic. This means setting out clear,
pre-defined paths that the conversation should follow under ideal
circumstances using [Flows](../flows.mdx).
- We identify patterns of 'unhappy paths' and specify these using separate
Flows. These [conversational patterns](./unhappy-paths.mdx) define how the
chatbot should respond when the user's input doesn't match the expected course
of a flow.
- We use Flows to keep track of the conversation's state, ensuring we always
know where we are in the dialogue and what's been covered.
- We employ LLMs to update the state of these Flows. These language models
process user input, adjusting the conversation's course as needed.
- We use LLMs to [improve the chatbot's responses](./llm-nlg.mdx). These
language models generate the chatbot's responses, ensuring they feel natural and
fluent.

## Configuration and Setup
- get the dm2 branches
- configure the config.yml

## Example conversation
In order to set up and configure this approach:

- You'll first need to get the `dm2` branches of `rasa` and `rasa-plus`.
All components are implemented on these branches.
- Next, you'll need to configure the `config.yml` file to ensure your bot
recognizes and applies this combination of LLMs and Flows.

An example configuration file is shown below:

```yaml title="config.yml"
recipe: default.v1
language: en
pipeline:
- name: LLMFlowClassifier

policies:
- name: rasa.core.policies.flow_policy.FlowPolicy
- name: RulePolicy
```

To use the rephrasing capability, you'll also need to add the following to your
endpoint configuration:

```yaml title="endpoints.yml"
nlg:
type: rasa_plus.ml.LLMResponseRephraser
```

Additional configuration parameters are explained in detail in the documentation
pages for each of these components:
- [LLMFlowClassifier](./llm-flow-classifier.mdx)
- [FlowPolicy](./flow-policy.mdx)
- [LLMResponseRephraser](./llm-nlg.mdx)

## Example Conversation

[Example conversation goes here]