Классы Prompt и LLMResponse для унификации промптов и ответов
Обзор классов Guardrails для промптов и ответов, но без конкретных шагов для внедрения.
Обзор классов Guardrails для промптов и ответов, но без конкретных шагов для внедрения.
Можно применить при построении оркестрации: использовать классы Prompt/Instructions для шаблонизации промптов и LLMResponse для единообразного сбора ответов от разных моделей, что упрощает валидацию и логирование.
расшифровка ролика ↓
Title:
URL Source: https://raw.githubusercontent.com/guardrails-ai/guardrails/main/docs/api_reference/llm_interaction.md
Markdown Content: # Helpers for LLM Interactions
Class for representing a prompt entry.
## BasePrompt
```python class BasePrompt() ```
Base class for representing an LLM prompt.
#### \_\_init\_\_
```python def __init__(source: str, output_schema: Optional[str] = None, *, xml_output_schema: Optional[str] = None) ```
Initialize and substitute constants in the prompt.
#### substitute\_constants
```python def substitute_constants(text: str) -> str ```
Substitute constants in the prompt.
#### get\_prompt\_variables
```python def get_prompt_variables() -> List[str] ```
#### format
```python def format(**kwargs) -> "BasePrompt" ```
#### escape
```python def escape() -> str ```
Escape single curly braces into double curly braces.
The LLM prompt.
## Prompt
```python class Prompt(BasePrompt) ```
Prompt class.
The prompt is passed to the LLM as primary instructions.
#### format
```python def format(**kwargs) -> "Prompt" ```
Format the prompt using the given keyword arguments.
Instructions to the LLM, to be passed in the prompt.
## Instructions
```python class Instructions(BasePrompt) ```
Instructions class.
The instructions are passed to the LLM as secondary input. Different model may use these differently. For example, chat models may receive instructions in the system-prompt.
#### format
```python def format(**kwargs) -> "Instructions" ```
Format the prompt using the given keyword arguments.
## PromptCallableBase
## LLMResponse
```python class LLMResponse(ILLMResponse) ```
Standard information collection from LLM responses to feed the validation loop.
**Attributes**:
- `output` _str_ - The output from the LLM. - `stream_output` _Optional[Iterator]_ - A stream of output from the LLM. Default None. - `async_stream_output` _Optional[AsyncIterator]_ - An async stream of output from the LLM. Default None. - `prompt_token_count` _Optional[int]_ - The number of tokens in the prompt. Default None. - `response_token_count` _Optional[int]_ - The number of tokens in the response. Default None.