Skip to content

Commit 08567cb

Browse files
committed
Tweaks to the LLMs per task documentation section.
1 parent cfe5f90 commit 08567cb

File tree

1 file changed

+29
-37
lines changed

1 file changed

+29
-37
lines changed

docs/user_guides/configuration-guide.md

Lines changed: 29 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -251,46 +251,51 @@ It is important to implement the following methods:
251251
In other words, to create your custom LLM provider, you need to implement the following interface methods: `_call`, `_llm_type`, and optionally `_acall`, `_astream`, `_stream`, and `_identifying_params`. Here's how you can do it:
252252

253253
```python
254-
from typing import Any, Dict, Iterator, List, Mapping, Optional
254+
from typing import Any, Iterator, List, Optional
255+
255256
from langchain.base_language import BaseLanguageModel
256-
from nemoguardrails.llm.providers import register_llm_provider
257-
from langchain_core.callbacks.manager import CallbackManagerForLLMRun, AsyncCallbackManagerForLLMRun
257+
from langchain_core.callbacks.manager import (
258+
CallbackManagerForLLMRun,
259+
AsyncCallbackManagerForLLMRun,
260+
)
258261
from langchain_core.outputs import GenerationChunk
259262
263+
from nemoguardrails.llm.providers import register_llm_provider
264+
265+
260266
class MyCustomLLM(BaseLanguageModel):
261-
async def _acall(
267+
268+
def _call(
262269
self,
263270
prompt: str,
264271
stop: Optional[List[str]] = None,
265-
run_manager: Optional[AsyncCallbackManagerForLLMRun] = None,
272+
run_manager: Optional[CallbackManagerForLLMRun] = None,
266273
**kwargs,
267274
) -> str:
268275
pass
269276
270-
def _call(
271-
self,
272-
prompt: str,
273-
stop: Optional[List[str]] = None,
274-
run_manager: Optional[CallbackManagerForLLMRun] = None,
275-
**kwargs,
276-
) -> str:
277+
async def _acall(
278+
self,
279+
prompt: str,
280+
stop: Optional[List[str]] = None,
281+
run_manager: Optional[AsyncCallbackManagerForLLMRun] = None,
282+
**kwargs,
283+
) -> str:
277284
pass
278-
# required to implement
279285
280-
def _stream(
286+
def _stream(
281287
self,
282288
prompt: str,
283289
stop: Optional[List[str]] = None,
284290
run_manager: Optional[CallbackManagerForLLMRun] = None,
285291
**kwargs: Any,
286-
) -> Iterator[GenerationChunk]:
287-
pass
288-
#Optional to implement
292+
) -> Iterator[GenerationChunk]:
293+
pass
289294
290295
# rest of the implementation
291-
....
296+
...
292297
293-
register_llm_provider("custom_llm", CustomLLM)
298+
register_llm_provider("custom_llm", MyCustomLLM)
294299
```
295300

296301
You can then use the custom LLM provider in your configuration:
@@ -301,31 +306,18 @@ models:
301306
engine: custom_llm
302307
```
303308

304-
```
305-
306309
### Configuring LLMs per Task
307310

308-
The interaction with the LLM is structured in a task-oriented manner. Each invocation of the LLM is associated with a specific task. These tasks are integral to the guardrails process and include:
311+
The interaction with the LLM is structured in a task-oriented manner. Each invocation of the LLM is associated with a specific task. These tasks are integral to the guardrail process and include:
309312

310313
1. `generate_user_intent`: This task transforms the raw user utterance into a canonical form. For instance, "Hello there" might be converted to `express greeting`.
311314
2. `generate_next_steps`: This task determines the bot's response or the action to be executed. Examples include `bot express greeting` or `bot respond to question`.
312315
3. `generate_bot_message`: This task decides the exact bot message to be returned.
313316
4. `general`: This task generates the next bot message based on the history of user and bot messages. It is used when there are no dialog rails defined (i.e., no user message canonical forms).
314317

315-
For a comprehensive list of tasks, refer to the [Task type](https://github.com/NVIDIA/NeMo-Guardrails/blob/develop/nemoguardrails/llm/types.py). Below we list some of the common tasks:
316-
317-
- `generate_intent_steps_message`
318-
- `self_check_input`
319-
- `self_check_output`
320-
- `llama_guard_check_input`
321-
- `llama_guard_check_output`
322-
- `patronus_lynx_check_output_hallucination`
323-
- `self_check_facts`
324-
- `check_hallucination`
325-
326318
For a comprehensive list of tasks, refer to the [Task type](https://github.com/NVIDIA/NeMo-Guardrails/blob/develop/nemoguardrails/llm/types.py).
327319

328-
You have the flexibility of selecting models for specific tasks. For example, you can use a different model for the `self_check_input` and `self_check_output` tasks from various providers. Here's an example configuration:
320+
You can use different LLM models for specific tasks. For example, you can use a different model for the `self_check_input` and `self_check_output` tasks from various providers. Here's an example configuration:
329321

330322
```yaml
331323
@@ -337,11 +329,11 @@ models:
337329
model: meta/llama3-8b-instruct
338330
engine: nim
339331
- type: self_check_output
340-
model: meta/llama-3.1-405b-instruct
332+
model: meta/llama-3.1-70b-instruct
341333
engine: nim
342334
```
343335

344-
as you can see for the `self_check_input` and `self_check_output` tasks, we are using different models. It is even possible to get more granular and use different models for a task like `generate_user_intent`.
336+
In the previous example, the `self_check_input` and `self_check_output` tasks use different models. It is even possible to get more granular and use different models for a task like `generate_user_intent`:
345337

346338
```yaml
347339
models:
@@ -352,7 +344,7 @@ models:
352344
model: meta/llama3-8b-instruct
353345
engine: nim
354346
- type: self_check_output
355-
model: meta/llama-3.1-405b-instruct
347+
model: meta/llama-3.1-70b-instruct
356348
engine: nim
357349
- type: generate_user_intent
358350
model: meta/llama-3.1-8b-instruct

0 commit comments

Comments
 (0)