Outlines
Frameworks = Literal['transformers', 'llamacpp', 'vllm']
module-attribute
¶
Available frameworks for the structured output configuration.
StructuredOutputType
¶
Bases: TypedDict
TypedDict to represent the structured output configuration from outlines.
Source code in src/distilabel/steps/tasks/structured_outputs/outlines.py
format: Literal['json', 'regex']
instance-attribute
¶
One of "json" or "regex".
schema: Union[str, Type[BaseModel]]
instance-attribute
¶
The schema to use for the structured output. If "json", it
can be a pydantic.BaseModel class, or the schema as a string,
as obtained from model_to_schema(BaseModel)
, if "regex", it
should be a regex pattern as a string.
whitespace_pattern: Optional[Union[str, List[str]]]
instance-attribute
¶
If "json" corresponds to a string or a list of
strings with a pattern (doesn't impact string literals).
For example, to allow only a single space or newline with
whitespace_pattern=r"[
]?"
model_to_schema(schema)
¶
Helper function to return a string representation of the schema from a pydantic.BaseModel
class.
prepare_guided_output(structured_output, framework, llm)
¶
Prepares the LLM
to generate guided output using outlines
.
It allows to generate JSON or Regex structured outputs for the integrated frameworks.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
structured_output |
StructuredOutputType
|
the structured output configuration. |
required |
framework |
Frameworks
|
the framework to use for the structured output. |
required |
llm |
Any
|
the |
required |
Raises:
Type | Description |
---|---|
ValueError
|
if the format is not "json" or "regex". |
Returns:
Type | Description |
---|---|
Dict[str, Union[Callable, None]]
|
A dictionary containing the processor to use for the guided output, and in |
Dict[str, Union[Callable, None]]
|
case of "json" will also include the schema as a dict, to simplify serialization |
Dict[str, Union[Callable, None]]
|
and deserialization. |