Skip to content

Commit 14d7cfc

Browse files
committed
Add auto-generated reference docs for public python API.
1 parent 8395a1e commit 14d7cfc

File tree

5 files changed

+308
-0
lines changed

5 files changed

+308
-0
lines changed

docs/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ The documentation is divided into the following sections:
88
4. [Evaluation Tools](#evaluation-tools)
99
5. [Architecture Guide](#architecture-guide)
1010
6. [Security Guidelines](./security/guidelines.md)
11+
7. [API Reference](./api/README.md)
1112

1213
## Getting Started
1314

docs/api/README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<!-- markdownlint-disable -->
2+
3+
# API Overview
4+
5+
## Modules
6+
7+
- [`nemoguardrails.rails.llm.config`](./nemoguardrails.rails.llm.config.md#module-nemoguardrailsrailsllmconfig): Module for the configuration of rails.
8+
- [`nemoguardrails.rails.llm.llmrails`](./nemoguardrails.rails.llm.llmrails.md#module-nemoguardrailsrailsllmllmrails): LLM Rails entry point.
9+
10+
## Classes
11+
12+
- [`config.Document`](./nemoguardrails.rails.llm.config.md#class-document): Configuration for documents that should be used for question answering.
13+
- [`config.Instruction`](./nemoguardrails.rails.llm.config.md#class-instruction): Configuration for instructions in natural language that should be passed to the LLM.
14+
- [`config.MessageTemplate`](./nemoguardrails.rails.llm.config.md#class-messagetemplate): Template for a message structure.
15+
- [`config.Model`](./nemoguardrails.rails.llm.config.md#class-model): Configuration of a model used by the rails engine.
16+
- [`config.RailsConfig`](./nemoguardrails.rails.llm.config.md#class-railsconfig): Configuration object for the models and the rails.
17+
- [`config.TaskPrompt`](./nemoguardrails.rails.llm.config.md#class-taskprompt): Configuration for prompts that will be used for a specific task.
18+
- [`llmrails.LLMRails`](./nemoguardrails.rails.llm.llmrails.md#class-llmrails): Rails based on a given configuration.
19+
20+
## Functions
21+
22+
- No functions
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
<!-- markdownlint-disable -->
2+
3+
<a href="../../nemoguardrails/rails/llm/config.py#L0"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square" /></a>
4+
5+
# <kbd>module</kbd> `nemoguardrails.rails.llm.config`
6+
Module for the configuration of rails.
7+
8+
9+
10+
---
11+
12+
<a href="../../nemoguardrails/rails/llm/config.py#L29"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square" /></a>
13+
14+
## <kbd>class</kbd> `Model`
15+
Configuration of a model used by the rails engine.
16+
17+
Typically, the main model is configured e.g.: { "type": "main", "engine": "openai", "model": "text-davinci-003" }
18+
19+
20+
21+
22+
23+
---
24+
25+
<a href="../../nemoguardrails/rails/llm/config.py#L49"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square" /></a>
26+
27+
## <kbd>class</kbd> `Instruction`
28+
Configuration for instructions in natural language that should be passed to the LLM.
29+
30+
31+
32+
33+
34+
---
35+
36+
<a href="../../nemoguardrails/rails/llm/config.py#L56"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square" /></a>
37+
38+
## <kbd>class</kbd> `Document`
39+
Configuration for documents that should be used for question answering.
40+
41+
42+
43+
44+
45+
---
46+
47+
<a href="../../nemoguardrails/rails/llm/config.py#L63"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square" /></a>
48+
49+
## <kbd>class</kbd> `MessageTemplate`
50+
Template for a message structure.
51+
52+
53+
54+
55+
56+
---
57+
58+
<a href="../../nemoguardrails/rails/llm/config.py#L72"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square" /></a>
59+
60+
## <kbd>class</kbd> `TaskPrompt`
61+
Configuration for prompts that will be used for a specific task.
62+
63+
64+
65+
66+
---
67+
68+
<a href="../../nemoguardrails/rails/llm/config.py#L93"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square" /></a>
69+
70+
### <kbd>classmethod</kbd> `TaskPrompt.check_fields`
71+
72+
```python
73+
check_fields(values)
74+
```
75+
76+
77+
78+
79+
80+
81+
---
82+
83+
<a href="../../nemoguardrails/rails/llm/config.py#L159"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square" /></a>
84+
85+
## <kbd>class</kbd> `RailsConfig`
86+
Configuration object for the models and the rails.
87+
88+
TODO: add typed config for user_messages, bot_messages, and flows.
89+
90+
91+
92+
93+
---
94+
95+
<a href="../../nemoguardrails/rails/llm/config.py#L318"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square" /></a>
96+
97+
### <kbd>method</kbd> `RailsConfig.from_content`
98+
99+
```python
100+
from_content(
101+
colang_content: Optional[str] = None,
102+
yaml_content: Optional[str] = None
103+
)
104+
```
105+
106+
Loads a configuration from the provided colang/YAML content.
107+
108+
---
109+
110+
<a href="../../nemoguardrails/rails/llm/config.py#L227"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square" /></a>
111+
112+
### <kbd>method</kbd> `RailsConfig.from_path`
113+
114+
```python
115+
from_path(
116+
config_path: str,
117+
test_set_percentage: Optional[float] = 0.0,
118+
test_set: Optional[Dict[str, List]] = {},
119+
max_samples_per_intent: Optional[int] = 0
120+
)
121+
```
122+
123+
Loads a configuration from a given path.
124+
125+
Supports loading a from a single file, or from a directory.
126+
127+
Also used for testing Guardrails apps, in which case the test_set is randomly created from the intent samples in the config files. In this situation test_set_percentage should be larger than 0.
128+
129+
If we want to limit the number of samples for an intent, set the max_samples_per_intent to a positive number. It is useful for testing apps, but also for limiting the number of samples for an intent in some scenarios. The chosen samples are selected randomly for each intent.
130+
131+
---
132+
133+
<a href="../../nemoguardrails/rails/llm/config.py#L339"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square" /></a>
134+
135+
### <kbd>classmethod</kbd> `RailsConfig.parse_object`
136+
137+
```python
138+
parse_object(obj)
139+
```
140+
141+
Parses a configuration object from a given dictionary.
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
<!-- markdownlint-disable -->
2+
3+
<a href="../../nemoguardrails/rails/llm/llmrails.py#L0"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square" /></a>
4+
5+
# <kbd>module</kbd> `nemoguardrails.rails.llm.llmrails`
6+
LLM Rails entry point.
7+
8+
9+
10+
---
11+
12+
<a href="../../nemoguardrails/rails/llm/llmrails.py#L38"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square" /></a>
13+
14+
## <kbd>class</kbd> `LLMRails`
15+
Rails based on a given configuration.
16+
17+
<a href="../../nemoguardrails/rails/llm/llmrails.py#L41"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square" /></a>
18+
19+
### <kbd>method</kbd> `LLMRails.__init__`
20+
21+
```python
22+
__init__(
23+
config: nemoguardrails.rails.llm.config.RailsConfig,
24+
llm: Optional[langchain.llms.base.BaseLLM] = None,
25+
verbose: bool = False
26+
)
27+
```
28+
29+
Initializes the LLMRails instance.
30+
31+
32+
33+
**Args:**
34+
35+
- <b>`config`</b>: A rails configuration.
36+
- <b>`llm`</b>: An optional LLM engine to use.
37+
- <b>`verbose`</b>: Whether the logging should be verbose or not.
38+
39+
40+
41+
42+
---
43+
44+
<a href="../../nemoguardrails/rails/llm/llmrails.py#L202"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square" /></a>
45+
46+
### <kbd>method</kbd> `LLMRails.generate`
47+
48+
```python
49+
generate(prompt: Optional[str] = None, messages: Optional[List[dict]] = None)
50+
```
51+
52+
Synchronous version of generate_async.
53+
54+
---
55+
56+
<a href="../../nemoguardrails/rails/llm/llmrails.py#L141"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square" /></a>
57+
58+
### <kbd>method</kbd> `LLMRails.generate_async`
59+
60+
```python
61+
generate_async(
62+
prompt: Optional[str] = None,
63+
messages: Optional[List[dict]] = None
64+
)
65+
```
66+
67+
Generates a completion or a next message.
68+
69+
The format for messages is currently the following: [ {"role": "user", "content": "Hello! How are you?"}, {"role": "assistant", "content": "I am fine, thank you!"}, ] System messages are not yet supported.
70+
71+
---
72+
73+
<a href="../../nemoguardrails/rails/llm/llmrails.py#L220"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square" /></a>
74+
75+
### <kbd>method</kbd> `LLMRails.register_action`
76+
77+
```python
78+
register_action(
79+
action: <built-in function callable>,
80+
name: Optional[str] = None
81+
)
82+
```
83+
84+
Register a custom action for the rails configuration.
85+
86+
---
87+
88+
<a href="../../nemoguardrails/rails/llm/llmrails.py#L224"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square" /></a>
89+
90+
### <kbd>method</kbd> `LLMRails.register_action_param`
91+
92+
```python
93+
register_action_param(name: str, value: Any)
94+
```
95+
96+
Registers a custom action parameter.
97+
98+
---
99+
100+
<a href="../../nemoguardrails/rails/llm/llmrails.py#L228"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square" /></a>
101+
102+
### <kbd>method</kbd> `LLMRails.register_filter`
103+
104+
```python
105+
register_filter(
106+
filter_fn: <built-in function callable>,
107+
name: Optional[str] = None
108+
)
109+
```
110+
111+
Register a custom filter for the rails configuration.
112+
113+
---
114+
115+
<a href="../../nemoguardrails/rails/llm/llmrails.py#L232"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square" /></a>
116+
117+
### <kbd>method</kbd> `LLMRails.register_output_parser`
118+
119+
```python
120+
register_output_parser(output_parser: <built-in function callable>, name: str)
121+
```
122+
123+
Register a custom output parser for the rails configuration.
124+
125+
---
126+
127+
<a href="../../nemoguardrails/rails/llm/llmrails.py#L236"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square" /></a>
128+
129+
### <kbd>method</kbd> `LLMRails.register_prompt_context`
130+
131+
```python
132+
register_prompt_context(name: str, value_or_fn: Any)
133+
```
134+
135+
Register a value to be included in the prompt context.
136+
137+
:name: The name of the variable or function that will be used. :value_or_fn: The value or function that will be used to generate the value.

nemoguardrails/rails/llm/llmrails.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ class LLMRails:
4141
def __init__(
4242
self, config: RailsConfig, llm: Optional[BaseLLM] = None, verbose: bool = False
4343
):
44+
"""Initializes the LLMRails instance.
45+
46+
Args:
47+
config: A rails configuration.
48+
llm: An optional LLM engine to use.
49+
verbose: Whether the logging should be verbose or not.
50+
"""
4451
self.config = config
4552
self.llm = llm
4653
self.verbose = verbose

0 commit comments

Comments
 (0)