Camel.schemas.outlines converter
OutlinesConverter
OutlinesConverter is a class that converts a string or a function into a BaseModel schema.
Parameters:
- model_type (str, optional): The model type to be used.
- platform (str, optional): The platform to be used. 1. transformers 2. mamba 3. vllm 4. llamacpp 5. mlx (default: “transformers”) **kwargs: The keyword arguments to be used. See the outlines documentation for more details. See
- https: //dottxt-ai.github.io/outlines/latest/reference/models/models/
init
convert_regex
Convert the content to the specified regex pattern.
Parameters:
- content (str): The content to be converted.
- regex_pattern (str): The regex pattern to be used.
Returns:
str: The converted content.
convert_json
Convert the content to the specified JSON schema given by output_schema.
Parameters:
- content (str): The content to be converted.
- output_schema (Union[str, Callable]): The expected format of the response.
Returns:
dict: The converted content in JSON format.
convert_pydantic
Convert the content to the specified Pydantic schema.
Parameters:
- content (str): The content to be converted.
- output_schema (Type[BaseModel]): The expected format of the response.
Returns:
BaseModel: The converted content in pydantic model format.
convert_type
Convert the content to the specified type.
The following types are currently available:
- int
- float
- bool
- datetime.date
- datetime.time
- datetime.datetime
- custom types (https://dottxt-ai.github.io/outlines/latest/reference/generation/types/)
Parameters:
- content (str): The content to be converted.
- type_name (type): The type to be used.
Returns:
str: The converted content.
convert_choice
Convert the content to the specified choice.
Parameters:
- content (str): The content to be converted.
- choices (List[str]): The choices to be used.
Returns:
str: The converted content.
convert_grammar
Convert the content to the specified grammar.
Parameters:
- content (str): The content to be converted.
- grammar (str): The grammar to be used.
Returns:
str: The converted content.
convert
Formats the input content into the expected BaseModel.
Parameters:
- type (
Literal["regex", "json", "type", "choice", "grammar"]
): The type of conversion to perform. Options are: - “regex”: Match the content against a regex pattern. - “pydantic”: Convert the content into a pydantic model. - “json”: Convert the content into a JSON based on a schema. - “type”: Convert the content into a specified type. - “choice”: Match the content against a list of valid choices. - “grammar”: Convert the content using a specified grammar. - content (str): The content to be formatted. **kwargs: Additional keyword arguments specific to the conversion type. - For “regex”:
- regex_pattern (str): The regex pattern to use for matching. - For “pydantic”:
- output_schema (Type[BaseModel]): The schema to validate and format the pydantic model. - For “json”:
- output_schema (Union[str, Callable]): The schema to validate and format the JSON object. - For “type”:
- type_name (str): The target type name for the conversion. - For “choice”:
- choices (List[str]): A list of valid choices to match against. - For “grammar”:
- grammar (str): The grammar definition to use for content conversion.