camel.schemas 包#
子模块#
camel.schemas.base 模块#
camel.schemas.openai_converter 模块#
- 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)[来源]#
-
OpenAISchemaConverter 是一个将字符串或函数转换为 BaseModel 模式的类。
- Parameters:
model_type (ModelType, optional) – 要使用的模型类型。 (default: ModelType.GPT_4O_MINI)
model_config_dict (Optional[Dict[str, Any]], optional) - 一个字典, 该字典将被传入:obj:openai.ChatCompletion.create()。如果
None,将使用ChatGPTConfig().as_dict()。 (默认值:None)api_key (Optional[str], optional) – 用于OpenAI服务身份验证的API密钥。(默认:
None)output_schema (Optional[Type[BaseModel]], optional) – 预期的响应格式。(默认:
None)prompt (可选[str], optional) – 要使用的提示文本。 (默认值:
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[来源]#
将输入内容格式化为预期的BaseModel
- Parameters:
content (str) – 需要格式化的内容。
output_schema (Union[Type[BaseModel], str, Callable]) – 预期的响应格式。
- Returns:
格式化后的响应。
- Return type:
BaseModel
camel.schemas.outlines_converter 模块#
- class camel.schemas.outlines_converter.OutlinesConverter(model_type: str, platform: Literal['vllm', 'transformers', 'mamba', 'llamacpp', 'mlx'] = 'transformers', **kwargs: Any)[来源]#
-
OutlinesConverter 是一个将字符串或函数转换为 BaseModel 模式的类。
- Parameters:
model_type (str, optional) – 要使用的模型类型。
platform (str, optional) – 要使用的平台。 1. transformers 2. mamba 3. vllm 4. llamacpp 5. mlx (默认值:"transformers")
**kwargs – 要使用的关键字参数。详情请参阅outlines文档。参见 https://dottxt-ai.github.io/outlines/latest/reference/models/models/
- convert(content: str, type: Literal['regex', 'json', 'type', 'choice', 'grammar'], **kwargs) Any[来源]#
将输入内容格式化为预期的BaseModel。
- Parameters:
type (Literal["regex", "json", "type", "choice", "grammar"]) –
- 要执行的转换类型。选项包括:
"regex":将内容与正则表达式模式匹配。
"pydantic":将内容转换为pydantic模型。
"json":基于模式将内容转换为JSON。
"type":将内容转换为指定类型。
"choice":将内容与有效选项列表匹配。
"grammar":使用指定语法转换内容。
content (str) – 需要格式化的内容。
**kwargs – 特定于转换类型的额外关键字参数。
"regex" (- 用于) – regex_pattern (str): 用于匹配的正则表达式模式。
"pydantic" (- 用于) –
- output_schema (Type[BaseModel]): 用于验证和
格式化pydantic模型的模式。
"json" (- 用于) –
- output_schema (Union[str, Callable]): 用于验证
并格式化JSON对象的模式。
"type" (- 用于) – type_name (str): 转换的目标类型名称。
"choice" (- For) – 选项 (List[str]): 一个用于匹配的有效选项列表。
"grammar" (- For) –
- grammar (str): 用于内容转换的语法定义
转换。
- convert_choice(content: str, choices: List[str]) str[来源]#
将内容转换为指定的选项。
- Parameters:
content (str) – 需要被转换的内容。
choices (List[str]) – 要使用的选项列表。
- Returns:
转换后的内容。
- Return type:
字符串
- convert_grammar(content: str, grammar: str) str[来源]#
将内容转换为指定的语法。
- Parameters:
content (str) – 需要被转换的内容。
grammar (str) – 要使用的语法。
- Returns:
转换后的内容。
- Return type:
字符串
- convert_json(content: str, output_schema: str | Callable) dict[来源]#
将内容转换为由output_schema指定的JSON格式。
- Parameters:
content (str) – 需要被转换的内容。
output_schema (Union[str, Callable]) – 响应的预期格式。
- Returns:
转换后的内容为JSON格式。
- Return type:
字典
- convert_pydantic(content: str, output_schema: Type[BaseModel]) BaseModel[来源]#
将内容转换为指定的Pydantic模式。
- Parameters:
content (str) – 需要被转换的内容。
output_schema (Type[BaseModel]) – 响应的预期格式。
- Returns:
转换后的内容以pydantic模型格式呈现。
- Return type:
BaseModel
- convert_regex(content: str, regex_pattern: str) str[来源]#
将内容转换为指定的正则表达式模式。
- Parameters:
content (str) – 需要被转换的内容。
regex_pattern (str) – 要使用的正则表达式模式。
- Returns:
转换后的内容。
- Return type:
字符串
- convert_type(content: str, type_name: type) str[来源]#
将内容转换为指定类型。
- The following types are currently available:
整数
浮点数
布尔值
datetime.date
datetime.time
datetime.datetime
自定义类型 (https://dottxt-ai.github.io/outlines/latest/reference/generation/types/)
- Parameters:
content (str) – 需要被转换的内容。
type_name (type) – 要使用的类型。
- Returns:
转换后的内容。
- Return type:
字符串
模块内容#
- 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)[来源]#
-
OpenAISchemaConverter 是一个将字符串或函数转换为 BaseModel 模式的类。
- Parameters:
model_type (ModelType, optional) – 要使用的模型类型。 (default: ModelType.GPT_4O_MINI)
model_config_dict (Optional[Dict[str, Any]], optional) - 一个字典, 该字典将被传入:obj:openai.ChatCompletion.create()。如果
None,将使用ChatGPTConfig().as_dict()。 (默认值:None)api_key (Optional[str], optional) – 用于OpenAI服务身份验证的API密钥。(默认:
None)output_schema (Optional[Type[BaseModel]], optional) – 预期的响应格式。(默认:
None)prompt (可选[str], optional) – 要使用的提示文本。 (默认值:
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[来源]#
将输入内容格式化为预期的BaseModel
- Parameters:
content (str) – 需要格式化的内容。
output_schema (Union[Type[BaseModel], str, Callable]) – 预期的响应格式。
- Returns:
格式化后的响应。
- Return type:
BaseModel
- class camel.schemas.OutlinesConverter(model_type: str, platform: Literal['vllm', 'transformers', 'mamba', 'llamacpp', 'mlx'] = 'transformers', **kwargs: Any)[来源]#
-
OutlinesConverter 是一个将字符串或函数转换为 BaseModel 模式的类。
- Parameters:
model_type (str, optional) – 要使用的模型类型。
platform (str, optional) – 要使用的平台。 1. transformers 2. mamba 3. vllm 4. llamacpp 5. mlx (默认值:"transformers")
**kwargs – 要使用的关键字参数。详情请参阅outlines文档。参见 https://dottxt-ai.github.io/outlines/latest/reference/models/models/
- convert(content: str, type: Literal['regex', 'json', 'type', 'choice', 'grammar'], **kwargs) Any[来源]#
将输入内容格式化为预期的BaseModel。
- Parameters:
type (Literal["regex", "json", "type", "choice", "grammar"]) –
- 要执行的转换类型。选项包括:
"regex":根据正则表达式模式匹配内容。
"pydantic":将内容转换为pydantic模型。
"json":基于模式将内容转换为JSON。
"type":将内容转换为指定类型。
"choice":根据有效选项列表匹配内容。
"grammar":使用指定语法转换内容。
content (str) – 需要格式化的内容。
**kwargs – 特定于转换类型的额外关键字参数。
"regex" (- 用于) – regex_pattern (str): 用于匹配的正则表达式模式。
"pydantic" (- 用于) –
- output_schema (Type[BaseModel]): 用于验证和
格式化pydantic模型的模式。
"json" (- 用于) –
- output_schema (Union[str, Callable]): 用于验证
并格式化JSON对象的模式。
"type" (- 用于) – type_name (str): 转换的目标类型名称。
"choice" (- For) – 选项 (List[str]): 一个用于匹配的有效选项列表。
"grammar" (- For) –
- grammar (str): 用于内容转换的语法定义
转换。
- convert_choice(content: str, choices: List[str]) str[来源]#
将内容转换为指定的选项。
- Parameters:
content (str) – 需要被转换的内容。
choices (List[str]) – 要使用的选项列表。
- Returns:
转换后的内容。
- Return type:
字符串
- convert_grammar(content: str, grammar: str) str[来源]#
将内容转换为指定的语法。
- Parameters:
content (str) – 需要被转换的内容。
grammar (str) – 要使用的语法。
- Returns:
转换后的内容。
- Return type:
字符串
- convert_json(content: str, output_schema: str | Callable) dict[来源]#
将内容转换为由output_schema指定的JSON格式。
- Parameters:
content (str) – 需要被转换的内容。
output_schema (Union[str, Callable]) – 预期的响应格式。
- Returns:
转换后的内容为JSON格式。
- Return type:
字典
- convert_pydantic(content: str, output_schema: Type[BaseModel]) BaseModel[来源]#
将内容转换为指定的Pydantic模式。
- Parameters:
content (str) – 需要被转换的内容。
output_schema (Type[BaseModel]) – 预期的响应格式。
- Returns:
转换后的内容以pydantic模型格式呈现。
- Return type:
BaseModel
- convert_regex(content: str, regex_pattern: str) str[来源]#
将内容转换为指定的正则表达式模式。
- Parameters:
content (str) – 需要被转换的内容。
regex_pattern (str) – 要使用的正则表达式模式。
- Returns:
转换后的内容。
- Return type:
字符串
- convert_type(content: str, type_name: type) str[来源]#
将内容转换为指定类型。
- The following types are currently available:
整数
浮点数
布尔值
datetime.date
datetime.time
datetime.datetime
自定义类型 (https://dottxt-ai.github.io/outlines/latest/reference/generation/types/)
- Parameters:
content (str) – 需要被转换的内容。
type_name (type) – 要使用的类型。
- Returns:
转换后的内容。
- Return type:
字符串