Skip to content

Commit c00aa21

Browse files
committed
Refactor the docs and the examples folders.
1 parent f98d24d commit c00aa21

File tree

94 files changed

+365
-88
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+365
-88
lines changed

CHANGELOG.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1717
### Added
1818

1919
- Support for [custom configuration data](./docs/user_guide/configuration-guide.md#custom-data).
20-
- Example for using [custom LLM and multiple KBs](./examples/multi_kb/README.md)
20+
- Example for using [custom LLM and multiple KBs](examples/configs/multi_kb/README.md)
2121
- Support for [`PROMPTS_DIR`](./docs/user_guide/advanced/prompt-customization.md#prompt-configuration).
2222
- [#101](https://github.com/NVIDIA/NeMo-Guardrails/pull/101) Support for [using OpenAI embeddings](./docs/user_guide/configuration-guide.md#the-embeddings-model) models in addition to SentenceTransformers.
2323
- First set of end-to-end QA tests for the example configurations.
@@ -82,8 +82,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
8282
- Support for chat models i.e. prompting with a sequence of messages.
8383
- Experimental support for allowing the LLM to generate [multi-step flows](docs/user_guide/configuration-guide.md#multi-step-generation).
8484
- Example of using Llama Index from a guardrails configuration (#40).
85-
- [Example](examples/llm/hf_endpoint) for using HuggingFace Endpoint LLMs with a guardrails configuration.
86-
- [Example](examples/llm/hf_pipeline_dolly) for using HuggingFace Pipeline LLMs with a guardrails configuration.
85+
- [Example](examples/configs/llm/hf_endpoint) for using HuggingFace Endpoint LLMs with a guardrails configuration.
86+
- [Example](examples/configs/llm/hf_pipeline_dolly) for using HuggingFace Pipeline LLMs with a guardrails configuration.
8787
- Support to alter LLM parameters passed as `model_kwargs` in LangChain.
8888
- CLI tool for running evaluations on the different steps (e.g., canonical form generation, next steps, bot message) and on existing rails implementation (e.g., moderation, jailbreak, fact-checking, and hallucination).
8989
- [Initial evaluation](nemoguardrails/eval/README.md) results for `text-davinci-003` and `gpt-3.5-turbo`.

docs/README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ The getting started section covers two topics:
2121

2222
Five reference examples are provided as a general demonstration for building different types of rails:
2323

24-
* [Topical Rail](../examples/topical_rail/README.md): Making the bot stick to a specific topic of conversation.
25-
* [Moderation Rail](../examples/moderation_rail/README.md): Moderating a bot's response.
26-
* [Fact Checking and Hallucination Rail](../examples/grounding_rail/README.md): Ensuring factual answers.
27-
* [Secure Execution Rail](../examples/execution_rails/README.md): Executing a third-party service with LLMs.
28-
* [Jailbreaking Rail](../examples/jailbreak_check/README.md): Ensuring safe answers despite malicious intent from the user.
24+
* [Topical Rail](../examples/_deprecated/topical_rail/README.md): Making the bot stick to a specific topic of conversation.
25+
* [Moderation Rail](../examples/_deprecated/moderation_rail/README.md): Moderating a bot's response.
26+
* [Fact Checking and Hallucination Rail](../examples/_deprecated/grounding_rail/README.md): Ensuring factual answers.
27+
* [Secure Execution Rail](../examples/_deprecated/execution_rails/README.md): Executing a third-party service with LLMs.
28+
* [Jailbreaking Rail](../examples/_deprecated/jailbreak_check/README.md): Ensuring safe answers despite malicious intent from the user.
2929

3030
> **Note:** These examples are meant to showcase the process of building rails, not as out-of-the-box safety features. Customization and strengthening of the rails is highly recommended.
3131

docs/architecture/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ The stream of events processed by the guardrails runtime (a simplified view with
170170
171171
As shown in the examples [here](../README.md#examples), the event-driven design allows us to hook into the process and add additional guardrails.
172172
173-
For example, in the [grounding rail](../../examples/grounding_rail/README.md) example, we can add an additional fact-checking guardrail (through the `check_facts` action) after a question about the report.
173+
For example, in the [grounding rail](../../examples/bots/info/README.md) example, we can add an additional fact-checking guardrail (through the `check_facts` action) after a question about the report.
174174

175175
```colang
176176
define flow answer report question

docs/user_guide/advanced/red-teaming.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ To run a red teaming process, there are three steps involved:
1212
2. Create a set of challenges (`challenges.json`) and add them to the `config` folder.
1313
3. Start the server `nemoguardrails server` and use the Chat UI to interact with various configurations.
1414

15-
For a server configuration template with two guardrails configuration and a set of challenges, check out [this example](../../../examples/red-teaming).
15+
For a server configuration template with two guardrails configuration and a set of challenges, check out [this example](../../../examples/configs/red-teaming).
1616

1717
## Challenges
1818

@@ -54,4 +54,4 @@ The UI enables the user to rate the attack's success (No Success, Some Success,
5454

5555
## Recording the results
5656

57-
The sample configuration [here](../../../examples/red-teaming) includes an example of how to use a "custom logger" to save the ratings, including the complete history of the conversation, in a CSV file.
57+
The sample configuration [here](../../../examples/configs/red-teaming) includes an example of how to use a "custom logger" to save the ratings, including the complete history of the conversation, in a CSV file.

docs/user_guide/configuration-guide.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ You can specify additional parameters when using NeMo LLM models using the `para
122122

123123
The `api_host`, `api_key`, and `organization_id` are fetched automatically from the environment variables `NGC_API_HOST`, `NGC_API_KEY`, and `NGC_ORGANIZATION_ID`, respectively.
124124

125-
For more details, please refer to the NeMo LLM Service documentation and check out the [NeMo LLM example configuration](../../examples/llm/nemollm).
125+
For more details, please refer to the NeMo LLM Service documentation and check out the [NeMo LLM example configuration](../../examples/configs/llm/nemollm).
126126

127127
#### Custom LLM Models
128128

docs/user_guide/integration-with-langchain.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Existing LangChain chains can be used as actions when defining guardrails in Col
4242
bot remove last message
4343
bot $updated_msg
4444
```
45-
Checkout [this sample script](../../examples/demo_chain_as_action.py) for the complete example.
45+
Checkout [this sample script](../../examples/scripts/demo_chain_as_action.py) for the complete example.
4646

4747
## Add guardrails to existing chains
4848

@@ -73,7 +73,7 @@ define flow
7373
bot $answer
7474
```
7575

76-
Checkout [this sample script](../../examples/demo_chain_with_guardrails.py) for a complete example.
76+
Checkout [this sample script](../../examples/scripts/demo_chain_with_guardrails.py) for a complete example.
7777

7878
## Use chains in your custom actions
7979

docs/user_guide/python-api.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ You can register a Langchain chain as an action using the [LLMRails.register_act
138138
app.register_action(some_chain, name="some_chain")
139139
```
140140

141-
When a chain is invoked as an action, the parameters of the action correspond to the input keys of the chain. For the return value, if the output of the chain has a single key, the value will be returned. If the chain has multiple output keys, the dictionary of output keys and their values is returned. See [demo_chain_with_guardrails](../../examples/demo_chain_with_guardrails.py) and [demo_chain_as_action](../../examples/demo_chain_as_action.py) as examples.
141+
When a chain is invoked as an action, the parameters of the action correspond to the input keys of the chain. For the return value, if the output of the chain has a single key, the value will be returned. If the chain has multiple output keys, the dictionary of output keys and their values is returned. See [demo_chain_with_guardrails](../../examples/scripts/demo_chain_with_guardrails.py) and [demo_chain_as_action](../../examples/scripts/demo_chain_as_action.py) as examples.
142142

143143
### Custom Actions
144144

examples/README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,26 @@ doesn't deviate from a specified topic of conversation. This example covers:
2020
- Writing basic flows and messages
2121
- Covers querying and using a Knowledge Base
2222
- Labels: `Topical`; `good first example`
23-
- [Link to example](./topical_rail/README.md)
23+
- [Link to example](_deprecated/topical_rail/README.md)
2424
- **Factual Question Answering:** The example largely focuses on two key aspects - ensuring that
2525
the bot's response is accurate and mitigates hallucination issues. This example:
2626
- Covers querying and using a Knowledge Base
2727
- Ensures answers are factual
2828
- Reduces hallucination risks
2929
- Labels: `Topical`
30-
- [Link to example](./grounding_rail/README.md)
30+
- [Link to example](bots/info/README.md)
3131
- **Moderating Bots:** Moderation is a complex, multi-pronged approach task. In
3232
this example, we cover:
3333
- Ensuring Ethical Responses
3434
- Blocking restricted words
3535
- "2 Strikes" ~ shutting down a conversation with a hostile user.
3636
- Labels: `Safety`; `Security`;
37-
- [Link to example](./moderation_rail/README.md)
37+
- [Link to example](_deprecated/moderation_rail/README.md)
3838
- **Detect Jailbreaking Attempts:** Malicious actors will attempt to overwrite a
3939
bot's safety features. This example:
4040
- Adds jailbreak check on user's input
4141
- Labels: `Security`
42-
- [Link to example](./jailbreak_check/README.md)
42+
- [Link to example](_deprecated/jailbreak_check/README.md)
4343
- **Safe Execution:** LLMs are versatile but some problems are better solved by
4444
using pre-existing solutions. For instance, if Wolfram|Alpha is great at
4545
solving a mathematical problem, it is better to use it to solve mathematical
@@ -49,4 +49,4 @@ This example:
4949
- Walks through some security guideline
5050
- Showcases execution for a third-party service
5151
- Labels: `Security`
52-
- [Link to example](./execution_rails/README.md)
52+
- [Link to example](_deprecated/execution_rails/README.md)

examples/custom_prompt_context/README.md renamed to examples/_deprecated/custom_prompt_context/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This example shows how you can include custom data in your custom prompt.
44

55
A common use case is to let the LLM know the current date and time so that it can respond appropriately to user queries involving a time component, e.g., "What day is today?". To achieve this, you need to:
66

7-
1. Register an additional [prompt context variable](../../docs/user_guide/advanced/prompt-customization.md#prompt-variables) (i.e., an additional variable that will be available when the prompts are rendered). This can be achieved using the `register_prompt_context(name, value_or_fn)`.
7+
1. Register an additional [prompt context variable](../../../docs/user_guide/advanced/prompt-customization.md#prompt-variables) (i.e., an additional variable that will be available when the prompts are rendered). This can be achieved using the `register_prompt_context(name, value_or_fn)`.
88

99
2. Change the desired prompts to include the new variable(s).
1010

examples/execution_rails/README.md renamed to examples/_deprecated/execution_rails/README.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,12 @@ Below is a small snippet of the conversation we can provide the bot:
168168
### Managing conversation
169169

170170
For building this bot, developers need to work with `messages`, `flows`, and
171-
`actions`. We write `messages` & `flows` in their [canonical forms](../../docs/getting_started/hello-world.md#hello-world-example). Let's
171+
`actions`. We write `messages` & `flows` in their [canonical forms](../../../docs/getting_started/hello-world.md#hello-world-example). Let's
172172
examine them individually.
173173

174174
**Note:** Think of messages as generic intents and flows as pseudo-code
175175
for the flow of the conversation. For a more formal explanation, refer to this
176-
[document](../../docs/architecture/README.md#the-guardrails-process).
176+
[document](../../../docs/architecture/README.md#the-guardrails-process).
177177

178178
#### User and Bot Messages
179179

@@ -205,7 +205,7 @@ for the application. For situations where a flow or a message isn't defines,
205205
the underlying large language model comes up with the next step for the bot or with
206206
an appropriate canonical form. It may or may not leverage the existing rails
207207
to do so, but the mechanism of flows and messages ensures that the LLM can come
208-
up with appropriate responses. Refer to the [colang runtime description guide](../../docs/architecture/README.md#canonical-user-messages) for more information on the same.
208+
up with appropriate responses. Refer to the [colang runtime description guide](../../../docs/architecture/README.md#canonical-user-messages) for more information on the same.
209209

210210
#### Using Flows
211211

@@ -234,7 +234,7 @@ define flow
234234
execute wolfram alpha request
235235
bot respond to math question
236236
```
237-
The Wolfram|Alpha action comes with the library ([found here](../../nemoguardrails/actions/math.py)). Let's take a look at the key elements in the implementation of the action.
237+
The Wolfram|Alpha action comes with the library ([found here](../../../nemoguardrails/actions/math.py)). Let's take a look at the key elements in the implementation of the action.
238238
```
239239
async def wolfram_alpha_request(
240240
query: Optional[str] = None, context: Optional[dict] = None
@@ -334,7 +334,7 @@ new_message = rails.generate(messages=[{
334334
}])
335335
print(new_message)
336336
```
337-
Refer to [Python API Documentation](../../docs/user_guide/interface-guide.md#python-api) for more information.
337+
Refer to [Python API Documentation](../../../docs/user_guide/interface-guide.md#python-api) for more information.
338338
### UI
339339
Guardrails allows users to interact with the server with a stock UI. To launch the
340340
server and access the UI to interact with this example, the following steps are
@@ -345,17 +345,17 @@ the UI
345345
* Click "New Chat" on the top left corner of the screen and then proceed to
346346
pick `execution_rail` from the drop-down menu.
347347

348-
Refer to [Guardrails Server Documentation](../../docs/user_guide/interface-guide.md#guardrails-server) for more information.
348+
Refer to [Guardrails Server Documentation](../../../docs/user_guide/interface-guide.md#guardrails-server) for more information.
349349
### Command Line Chat
350350

351351
To chat with the bot with a command line interface simply use the following
352352
command while you are in this folder.
353353
```
354354
nemoguardrails chat --config=sample_rails
355355
```
356-
Refer to [Guardrails CLI Documentation](../../docs/user_guide/interface-guide.md#guardrails-cli) for more information.
356+
Refer to [Guardrails CLI Documentation](../../../docs/user_guide/interface-guide.md#guardrails-cli) for more information.
357357

358358
Wondering what to talk to your bot about?
359359
* Write your own action!
360360
* Try connecting your existing Machine Learning Pipeline via an action!
361-
* [Explore more examples](../README.md#examples) to help steer your bot!
361+
* [Explore more examples](../../README.md#examples) to help steer your bot!

examples/grounding_rail/README.md renamed to examples/_deprecated/grounding_rail/README.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ That certainly sounds reasonable, but there's a problem! If you look over the re
130130

131131
## Fact Checking Rail
132132

133-
The fact checking rail enables you to check the validity of the bot response based on the knowledge base. It takes as inputs the bot response and the relevant chunk from the knowledge base, and makes a call to the LLM asking if the response is true based on the retrieved chunk. The actual format of the LLM call can be seen in [`actions/fact_checking.py`](../../nemoguardrails/library/factchecking/actions.py).
133+
The fact checking rail enables you to check the validity of the bot response based on the knowledge base. It takes as inputs the bot response and the relevant chunk from the knowledge base, and makes a call to the LLM asking if the response is true based on the retrieved chunk. The actual format of the LLM call can be seen in [`actions/fact_checking.py`](../../../nemoguardrails/library/factchecking/actions.py).
134134

135135
Let's modify our flow from before to add the fact checking rail. Now, when the bot provides its answer, we'll execute the `check_facts` action, and store the response in the `accurate` variable. If the fact checking action deems the response to be false, we'll remove that message from the response and let the user know that the bot doesn't know the answer.
136136

@@ -201,11 +201,11 @@ Everything up until `Finished chain.` is part of the bot's "internal reasoning",
201201

202202
## Hallucination Rail
203203

204-
While the fact checking action works well when we have a relevant knowledge base to check against, we'd also like to guard against hallucination when we don't have a pre-configured knowledge base. For this use case, we can use the [`check_hallucination`](../../nemoguardrails/library/hallucination/actions.py) action.
204+
While the fact checking action works well when we have a relevant knowledge base to check against, we'd also like to guard against hallucination when we don't have a pre-configured knowledge base. For this use case, we can use the [`check_hallucination`](../../../nemoguardrails/library/hallucination/actions.py) action.
205205

206206
The hallucination rail uses a self-checking mechanism inspired by the [SelfCheckGPT](https://arxiv.org/abs/2303.08896) technique. Similar to the fact-checking rail, we ask the LLM itself to determine whether the most recent output is consistent with a piece of context. However, since we don't have a knowledge base to pull the context from, we use the LLM to generate multiple additional completions to serve as the context. The assumption is that if the LLM produces multiple completions that are inconsistent with each other, the original completion is likely to be a hallucination.
207207

208-
You can view [`actions/hallucination/hallucination.py`](../../nemoguardrails/library/hallucination/actions.py) to see the format of the the extra generations and the hallucination check call.
208+
You can view [`actions/hallucination/hallucination.py`](../../../nemoguardrails/library/hallucination/actions.py) to see the format of the the extra generations and the hallucination check call.
209209

210210
The current implementation only supports OpenAI LLM Engines.
211211

@@ -272,7 +272,7 @@ Again taking a look at the detailed output log, we see that the LLM produced sev
272272

273273
With a basic understanding of building the rails, the next step is to try out the bot and customize it! You can continue to interact with the bot via the API, or use the `nemoguardrails` CLI to launch an interactive command line or web chat interface. Customize your bot by adding in new flows or documents to the knowledge base, and test out the effects of adding and removing the rails explored in this notebook and others.
274274

275-
Refer [Python API Documentation](../../docs/user_guide/interface-guide.md#python-api) for more information.
275+
Refer [Python API Documentation](../../../docs/user_guide/interface-guide.md#python-api) for more information.
276276

277277
### UI
278278

@@ -286,7 +286,7 @@ the UI
286286
* Click "New Chat" on the top left corner of the screen and then proceed to
287287
pick `grounding_rail` from the drop-down menu.
288288

289-
Refer [Guardrails Server Documentation](../../docs/user_guide/interface-guide.md#guardrails-server) for more information.
289+
Refer [Guardrails Server Documentation](../../../docs/user_guide/interface-guide.md#guardrails-server) for more information.
290290

291291
### Command Line Chat
292292

@@ -296,6 +296,6 @@ command while you are in this folder:
296296
```bash
297297
nemoguardrails chat --config=.
298298
```
299-
Refer [Guardrails CLI Documentation](../../docs/user_guide/interface-guide.md#guardrails-cli) for more information.
299+
Refer [Guardrails CLI Documentation](../../../docs/user_guide/interface-guide.md#guardrails-cli) for more information.
300300

301-
* [Explore more examples](../README.md#examples) to help steer your bot!
301+
* [Explore more examples](../../README.md#examples) to help steer your bot!

0 commit comments

Comments
 (0)