camel.schemas package#
Submodules#
camel.schemas.base module#
- class camel.schemas.base.BaseConverter[source]#
Bases:
ABC
A base class for schema outputs that includes functionality for managing the response format.
- Parameters:
output_schema (Optional[Type[BaseModel]], optional) – The expected format of the response. (default:
None
)
- abstract convert(content: str, *args: Any, **kwargs: Dict[str, Any]) Any [source]#
Structures the input text into the expected response format.
- Parameters:
text (str) – The input text to be structured.
output_schema (Optional[Type[BaseModel]], optional) – The expected format of the response. Defaults to None.
prompt (Optional[str], optional) – The prompt to be used.
- Returns:
The converted response.
- Return type:
Any
camel.schemas.openai_converter module#
- class camel.schemas.openai_converter.OpenAISchemaConverter(model_type: ~<unknown>.ModelType = ModelType.GPT_4O_MINI, model_config_dict: ~typing.Dict[str, ~typing.Any] | None = None, api_key: str | None = None)[source]#
Bases:
BaseConverter
OpenAISchemaConverter is a class that converts a string or a function into a BaseModel schema.
- Parameters:
model_type (ModelType, optional) – The model type to be used. (default: ModelType.GPT_4O_MINI)
model_config_dict (Optional[Dict[str, Any]], optional) – A dictionary that will be fed into:obj:openai.ChatCompletion.create(). If
None
,ChatGPTConfig().as_dict()
will be used. (default:None
)api_key (Optional[str], optional) – The API key for authenticating with the OpenAI service. (default:
None
)output_schema (Optional[Type[BaseModel]], optional) – The expected format of the response. (default:
None
)prompt (Optional[str], optional) – The prompt to be used. (default:
None
)
- convert(content: str, output_schema: Type[BaseModel] | str | Callable, prompt: str | None = '\n Extract key entities and attributes from the user \n provided text, and convert them into a structured JSON format.\n') BaseModel [source]#
Formats the input content into the expected BaseModel
- Parameters:
content (str) – The content to be formatted.
output_schema (Union[Type[BaseModel], str, Callable]) – The expected format of the response.
- Returns:
The formatted response.
- Return type:
BaseModel
camel.schemas.outlines_converter module#
- class camel.schemas.outlines_converter.OutlinesConverter(model_type: str, platform: Literal['vllm', 'transformers', 'mamba', 'llamacpp', 'mlx'] = 'transformers', **kwargs: Any)[source]#
Bases:
BaseConverter
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/
- convert(content: str, type: Literal['regex', 'json', 'type', 'choice', 'grammar'], **kwargs) Any [source]#
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.
"regex" (- For) – regex_pattern (str): The regex pattern to use for matching.
"pydantic" (- For) –
- output_schema (Type[BaseModel]): The schema to validate and
format the pydantic model.
"json" (- For) –
- output_schema (Union[str, Callable]): The schema to validate
and format the JSON object.
"type" (- For) – type_name (str): The target type name for the conversion.
"choice" (- For) – choices (List[str]): A list of valid choices to match against.
"grammar" (- For) –
- grammar (str): The grammar definition to use for content
conversion.
- convert_choice(content: str, choices: List[str]) str [source]#
Convert the content to the specified choice.
- Parameters:
content (str) – The content to be converted.
choices (List[str]) – The choices to be used.
- Returns:
The converted content.
- Return type:
str
- convert_grammar(content: str, grammar: str) str [source]#
Convert the content to the specified grammar.
- Parameters:
content (str) – The content to be converted.
grammar (str) – The grammar to be used.
- Returns:
The converted content.
- Return type:
str
- convert_json(content: str, output_schema: str | Callable) dict [source]#
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:
The converted content in JSON format.
- Return type:
dict
- convert_pydantic(content: str, output_schema: Type[BaseModel]) BaseModel [source]#
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:
The converted content in pydantic model format.
- Return type:
BaseModel
- convert_regex(content: str, regex_pattern: str) str [source]#
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:
The converted content.
- Return type:
str
- convert_type(content: str, type_name: type) str [source]#
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:
The converted content.
- Return type:
str
Module contents#
- class camel.schemas.OpenAISchemaConverter(model_type: ~<unknown>.ModelType = ModelType.GPT_4O_MINI, model_config_dict: ~typing.Dict[str, ~typing.Any] | None = None, api_key: str | None = None)[source]#
Bases:
BaseConverter
OpenAISchemaConverter is a class that converts a string or a function into a BaseModel schema.
- Parameters:
model_type (ModelType, optional) – The model type to be used. (default: ModelType.GPT_4O_MINI)
model_config_dict (Optional[Dict[str, Any]], optional) – A dictionary that will be fed into:obj:openai.ChatCompletion.create(). If
None
,ChatGPTConfig().as_dict()
will be used. (default:None
)api_key (Optional[str], optional) – The API key for authenticating with the OpenAI service. (default:
None
)output_schema (Optional[Type[BaseModel]], optional) – The expected format of the response. (default:
None
)prompt (Optional[str], optional) – The prompt to be used. (default:
None
)
- convert(content: str, output_schema: Type[BaseModel] | str | Callable, prompt: str | None = '\n Extract key entities and attributes from the user \n provided text, and convert them into a structured JSON format.\n') BaseModel [source]#
Formats the input content into the expected BaseModel
- Parameters:
content (str) – The content to be formatted.
output_schema (Union[Type[BaseModel], str, Callable]) – The expected format of the response.
- Returns:
The formatted response.
- Return type:
BaseModel
- class camel.schemas.OutlinesConverter(model_type: str, platform: Literal['vllm', 'transformers', 'mamba', 'llamacpp', 'mlx'] = 'transformers', **kwargs: Any)[source]#
Bases:
BaseConverter
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/
- convert(content: str, type: Literal['regex', 'json', 'type', 'choice', 'grammar'], **kwargs) Any [source]#
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.
"regex" (- For) – regex_pattern (str): The regex pattern to use for matching.
"pydantic" (- For) –
- output_schema (Type[BaseModel]): The schema to validate and
format the pydantic model.
"json" (- For) –
- output_schema (Union[str, Callable]): The schema to validate
and format the JSON object.
"type" (- For) – type_name (str): The target type name for the conversion.
"choice" (- For) – choices (List[str]): A list of valid choices to match against.
"grammar" (- For) –
- grammar (str): The grammar definition to use for content
conversion.
- convert_choice(content: str, choices: List[str]) str [source]#
Convert the content to the specified choice.
- Parameters:
content (str) – The content to be converted.
choices (List[str]) – The choices to be used.
- Returns:
The converted content.
- Return type:
str
- convert_grammar(content: str, grammar: str) str [source]#
Convert the content to the specified grammar.
- Parameters:
content (str) – The content to be converted.
grammar (str) – The grammar to be used.
- Returns:
The converted content.
- Return type:
str
- convert_json(content: str, output_schema: str | Callable) dict [source]#
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:
The converted content in JSON format.
- Return type:
dict
- convert_pydantic(content: str, output_schema: Type[BaseModel]) BaseModel [source]#
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:
The converted content in pydantic model format.
- Return type:
BaseModel
- convert_regex(content: str, regex_pattern: str) str [source]#
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:
The converted content.
- Return type:
str
- convert_type(content: str, type_name: type) str [source]#
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:
The converted content.
- Return type:
str