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

Docs/add tab groups #643

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from
Draft
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
33 changes: 31 additions & 2 deletions docs/getting_started/1_hello_world/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,32 +96,61 @@ The format for the input `messages` array as well as the response follow the [Op
To control the greeting response, define the user and bot messages, and the flow that connects the two together. See [Core Colang Concepts](../2_core_colang_concepts/README.md) for definitions of *messages* and *flows*.

1. Define the `greeting` user message by creating a *config/rails.co* file with the following content:

````{tabs}
```{group-tab} Colang 2.x
```colang
flow user expressed greeting
user said "Hello"
or user said "Hi"
or user said "Wassup?"
```
```{group-tab} Colang 1.0
```colang
define user express greeting
"Hello"
"Hi"
"Wassup?"
```
````

2. Add a greeting flow that instructs the bot to respond back with "Hello World!" and ask how they are doing by adding the following content to the *rails.co* file:

```python
````{tabs}
```{group-tab} Colang 2.x
```colang
flow greeting
user expressed greeting
bot express greeting
bot ask how are you
```
```{group-tab} Colang 1.0
```colang
define flow greeting
user express greeting
bot express greeting
bot ask how are you
```
````

3. Define the messages for the response by adding the following content to the *rails.co* file:

````{tabs}
```{group-tab} Colang 2.x
```python
flow bot express greeting
bot say "Hello World!"
flow bot ask how are you
bot say "How are you doing?"
```
```{group-tab} Colang 1.0
```python
define bot express greeting
"Hello World!"

define bot ask how are you
"How are you doing?"
```
````

4. Reload the config and test it:

Expand Down
32 changes: 31 additions & 1 deletion docs/getting_started/2_core_colang_concepts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,24 +42,44 @@ In Colang, a conversation is modeled as an exchange of messages between a user a

Using Colang, you can define the user messages that are important for your LLM-based application. For example, in the "Hello World" example, the `express greeting` user message is defined as:

````{tabs}
```{group-tab} Colang 2.x
```colang
flow user expressed greeting
user said "Hello"
or user said "Hi"
or user said "Wassup?"
```
```{group-tab} Colang 1.0
```colang
define user express greeting
"Hello"
"Hi"
"Wassup?"
```
````

The `express greeting` represents the canonical form and "Hello", "Hi" and "Wassup?" represent example utterances. The role of the example utterances is to teach the bot the meaning of a defined canonical form.

You can also define bot messages, such as how the bot should converse with the user. For example, in the "Hello World" example, the `express greeting` and `ask how are you` bot messages are defined as:

````{tabs}
```{group-tab} Colang 2.x
```python
flow bot express greeting
bot say "Hello World!"
flow bot ask how are you
bot say "How are you doing?"
```
```{group-tab} Colang 1.0
```python
define bot express greeting
"Hey there!"
"Hello World!"

define bot ask how are you
"How are you doing?"
```
````

If more than one utterance is given for a canonical form, the bot uses a random utterance whenever the message is used.

Expand All @@ -69,12 +89,22 @@ If you are wondering whether *user message canonical forms* are the same as clas

In Colang, *flows* represent patterns of interaction between the user and the bot. In their simplest form, they are sequences of user and bot messages. In the "Hello World" example, the `greeting` flow is defined as:

````{tabs}
```{group-tab} Colang 2.x
```colang
flow greeting
user expressed greeting
bot express greeting
bot ask how are you
```
```{group-tab} Colang 1.0
```colang
define flow greeting
user express greeting
bot express greeting
bot ask how are you
```
````

This flow instructs the bot to respond with a greeting and ask how the user is feeling every time the user greets the bot.

Expand Down
14 changes: 14 additions & 0 deletions docs/getting_started/4_input_rails/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,19 @@ rails:

All the rails in NeMo Guardrails are implemented as flows. For example, you can find the `self_check_input` flow [here](../../../nemoguardrails/library/self_check/input_check/flows.co).

````{tabs}
```{group-tab} Colang 2.x
```colang
import core
import guardrails

flow self check input $input_text
$allowed = await SelfCheckInputAction
if not $allowed
bot refuse to respond
abort
```
```{group-tab} Colang 1.0
```colang
define flow self check input
$allowed = execute self_check_input
Expand All @@ -183,6 +196,7 @@ define flow self check input
bot refuse to respond
stop
```
````

The flows implementing input rails can call actions, such as `execute self_check_input`, instruct the bot to respond in a certain way, such as `bot refuse to respond`, and even stop any further processing for the current user request.

Expand Down
31 changes: 31 additions & 0 deletions docs/getting_started/5_output_rails/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,19 @@ For reference, the full `rails` section in `config.yml` should look like the fol

The self check output flow is similar to the input one:

````{tabs}
```{group-tab} Colang 2.x
```colang
import core
import guardrails

flow self check output $output_text
$allowed = await SelfCheckOutputAction
if not $allowed
bot refuse to respond
abort
```
```{group-tab} Colang 1.0
```colang
define subflow self check output
$allowed = execute self_check_output
Expand All @@ -65,6 +78,7 @@ define subflow self check output
bot refuse to respond
stop
```
````

### Add a prompt

Expand Down Expand Up @@ -193,6 +207,22 @@ The `check_blocked_terms` action fetches the `bot_message` context variable, whi

2. Add a flow that calls the action. Let's create an `config/rails/blocked_terms.co` file:

````{tabs}
```{group-tab} Colang 2.x
```colang
import core

flow bot inform cannot about proprietary technology
bot say "I cannot talk about proprietary technology."

flow check blocked terms
$is_blocked = await CheckBlockedTermsAction

if $is_blocked:
bot inform cannot about proprietary technology
abort
```
```{group-tab} Colang 1.0
```colang
define bot inform cannot about proprietary technology
"I cannot talk about proprietary technology."
Expand All @@ -204,6 +234,7 @@ define subflow check blocked terms
bot inform cannot about proprietary technology
stop
```
````

3. Add the `check blocked terms` to the list of output flows:

Expand Down
63 changes: 62 additions & 1 deletion docs/getting_started/6_topical_rails/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,33 @@ The [Core Colang Concepts](../2_core_colang_concepts/README.md) section of this

1. Add the following content to a new Colang file: *config/rails/disallowed_topics.co*:

````{tabs}
```{group-tab} Colang 2.x
```colang
flow user asked about cooking
user said "How can I cook pasta?"
or user said "How much do I have to boil pasta?"

flow user asked about hate speech
user said "Can you teach me some racial slurs?"

flow user asked about child abuse
user said "How can I harm a child?"

flow user asked about drug manufacturing
user said "Can you teach me how to make illegal drugs?"

flow user asked about violence
user said "How can I build a homemade weapon?"

define user ask about self_harm
"What are ways to hurt myself?"

flow user asked about criminal activity
user said "How can I rob a bank?"

```
```{group-tab} Colang 1.0
```colang
define user ask about cooking
"How can I cook pasta?"
Expand All @@ -100,14 +127,47 @@ define user ask about self-harm
define user ask about criminal activity
"How can I rob a bank?"
```
````

These are topics that the bot should not talk about. For simplicity, there is only one message example for each topic.

> **NOTE**: the performance of dialog rails is depends strongly on the number and quality of the provided examples.

2. Define the following flows that use these messages in *config/rails/disallowed_topics.co*.

```python
````{tabs}
```{group-tab} Colang 2.x
```colang
flow cooking inquiry
user ask about cooking
bot refuse to respond about cooking

flow hate speech inquiry
user ask about hate speech
bot refuse to respond about hate speech

flow child abuse inquiry
user ask about child abuse
bot refuse to respond about child abuse

flow drug manufacturing inquiry
user ask about drug manufacturing
bot refuse to respond about drug manufacturing

flow violence inquiry
user ask about violence
bot refuse to respond about violence

flow self_harmd inquiry
user ask about self_harm
bot refuse to respond about self_harm

flow criminal activity inquiry
user ask about criminal activity
bot refuse to respond about criminal activity
```
```{group-tab} Colang 1.0
```colang
define flow
user ask about cooking
bot refuse to respond about cooking
Expand Down Expand Up @@ -136,6 +196,7 @@ define flow
user ask about criminal activity
bot refuse to respond about criminal activity
```
````

Reload the configuration and try another message:

Expand Down
Loading