camel.messages.conversion package#
Subpackages#
Submodules#
camel.messages.conversion.alpaca module#
- class camel.messages.conversion.alpaca.AlpacaItem(*, instruction: str, input: str, output: str)[source]#
Bases:
BaseModel
Represents an instruction-response item in the Alpaca format.
Appropripate for both cases where input field is empty, or populated. Provides parsing from string format using the class method from_string().
- Parameters:
instruction (str) – The instruction/question/prompt
input (str) – Input context or examples (put empty string if none)
output (str) – The response/answer to the instruction
- classmethod from_string(text: str) AlpacaItem [source]#
Creates an AlpacaItem from a formatted string.
- Parameters:
text –
String in either of these formats: With input: ### Instruction: {instruction} ### Input: {input} ### Response: {response}
Without input: ### Instruction: {instruction} ### Response: {response}
- Returns:
Parsed instance
- Return type:
- Raises:
ValueError – text doesn’t match expected format or sections missing
- input: str#
- instruction: str#
- model_config: ClassVar[ConfigDict] = {}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- classmethod no_section_markers(value: str) str [source]#
Ensures fields don’t contain section markers like ‘### Response:’
- output: str#
camel.messages.conversion.conversation_models module#
Bases:
RootModel
A full conversation in ShareGPT format with validation
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- !!! abstract “Usage Documentation”
[model_dump](../concepts/serialization.md#modelmodel_dump)
Generate a dictionary representation of the model, optionally specifying which fields to include or exclude.
- Parameters:
mode – The mode in which to_python should run. If mode is ‘json’, the output will only contain JSON serializable types. If mode is ‘python’, the output may contain non-JSON-serializable Python objects.
include – A set of fields to include in the output.
exclude – A set of fields to exclude from the output.
context – Additional context to pass to the serializer.
by_alias – Whether to use the field’s alias in the dictionary key if defined.
exclude_unset – Whether to exclude fields that have not been explicitly set.
exclude_defaults – Whether to exclude fields that are set to their default value.
exclude_none – Whether to exclude fields that have a value of None.
round_trip – If True, dumped values should be valid as input for non-idempotent types such as Json[T].
warnings – How to handle serialization errors. False/”none” ignores them, True/”warn” logs errors, “error” raises a [PydanticSerializationError][pydantic_core.PydanticSerializationError].
fallback – A function to call when an unknown value is encountered. If not provided, a [PydanticSerializationError][pydantic_core.PydanticSerializationError] error is raised.
serialize_as_any – Whether to serialize fields with duck-typing serialization behavior.
- Returns:
A dictionary representation of the model.
Validate the conversation follows logical message order
Bases:
BaseModel
A single message in ShareGPT format with enhanced validation
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class camel.messages.conversion.conversation_models.ToolCall(*, name: str, arguments: Dict[str, Any])[source]#
Bases:
BaseModel
Represents a single tool/function call with validation
- arguments: Dict[str, Any]#
- model_config: ClassVar[ConfigDict] = {'extra': 'forbid', 'json_schema_extra': {'examples': [{'arguments': {'city': 'London', 'units': 'celsius'}, 'name': 'get_weather'}]}}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- name: str#
- class camel.messages.conversion.conversation_models.ToolResponse(*, name: str, content: Any)[source]#
Bases:
BaseModel
Represents a tool/function response with validation. This is a base class and default implementation for tool responses, for the purpose of converting between different formats.
- content: Any#
- model_config: ClassVar[ConfigDict] = {'extra': 'forbid', 'json_schema_extra': {'examples': [{'content': {'conditions': 'sunny', 'humidity': 65, 'temperature': 20}, 'name': 'get_weather'}]}}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- name: str#
Module contents#
- class camel.messages.conversion.AlpacaItem(*, instruction: str, input: str, output: str)[source]#
Bases:
BaseModel
Represents an instruction-response item in the Alpaca format.
Appropripate for both cases where input field is empty, or populated. Provides parsing from string format using the class method from_string().
- Parameters:
instruction (str) – The instruction/question/prompt
input (str) – Input context or examples (put empty string if none)
output (str) – The response/answer to the instruction
- classmethod from_string(text: str) AlpacaItem [source]#
Creates an AlpacaItem from a formatted string.
- Parameters:
text –
String in either of these formats: With input: ### Instruction: {instruction} ### Input: {input} ### Response: {response}
Without input: ### Instruction: {instruction} ### Response: {response}
- Returns:
Parsed instance
- Return type:
- Raises:
ValueError – text doesn’t match expected format or sections missing
- input: str#
- instruction: str#
- model_config: ClassVar[ConfigDict] = {}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- classmethod no_section_markers(value: str) str [source]#
Ensures fields don’t contain section markers like ‘### Response:’
- output: str#
- class camel.messages.conversion.HermesFunctionFormatter[source]#
Bases:
FunctionCallFormatter
[HermesToolCall
,HermesToolResponse
]Hermes-style function calling format implementation with validation
- extract_tool_calls(message: str) List[HermesToolCall] [source]#
Extracts all tool calls from the provided message string.
- Parameters:
message (str) – The input message string containing potential tool calls.
- Returns:
A list of parsed HermesToolCall objects.
- Return type:
List[HermesToolCall]
- extract_tool_response(message: str) HermesToolResponse | None [source]#
Extracts a single tool response from the provided message string.
- Parameters:
message (str) – The input message string containing a potential tool response.
- Returns:
- A parsed HermesToolResponse object,
or None if no valid response is found.
- Return type:
Optional[HermesToolResponse]
- format_tool_call(content: str, func_name: str, args: Dict[str, Any]) str [source]#
Formats a tool call message with the given content, function name, and arguments.
- Parameters:
content (str) – The content or message to be included in the tool call.
func_name (str) – The name of the function being called.
args (Dict[str, Any]) – A dictionary of arguments to be passed to the function.
- Returns:
- A formatted string representing the tool call in Hermes
format.
- Return type:
str
- format_tool_response(func_name: str, result: Any) str [source]#
Formats a tool response message with the given function name and result.
- Parameters:
func_name (str) – The name of the function whose result is being returned.
result (Any) – The result to be included in the tool response.
- Returns:
- A formatted string representing the tool response in Hermes
format.
- Return type:
str
Bases:
RootModel
A full conversation in ShareGPT format with validation
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- !!! abstract “Usage Documentation”
[model_dump](../concepts/serialization.md#modelmodel_dump)
Generate a dictionary representation of the model, optionally specifying which fields to include or exclude.
- Parameters:
mode – The mode in which to_python should run. If mode is ‘json’, the output will only contain JSON serializable types. If mode is ‘python’, the output may contain non-JSON-serializable Python objects.
include – A set of fields to include in the output.
exclude – A set of fields to exclude from the output.
context – Additional context to pass to the serializer.
by_alias – Whether to use the field’s alias in the dictionary key if defined.
exclude_unset – Whether to exclude fields that have not been explicitly set.
exclude_defaults – Whether to exclude fields that are set to their default value.
exclude_none – Whether to exclude fields that have a value of None.
round_trip – If True, dumped values should be valid as input for non-idempotent types such as Json[T].
warnings – How to handle serialization errors. False/”none” ignores them, True/”warn” logs errors, “error” raises a [PydanticSerializationError][pydantic_core.PydanticSerializationError].
fallback – A function to call when an unknown value is encountered. If not provided, a [PydanticSerializationError][pydantic_core.PydanticSerializationError] error is raised.
serialize_as_any – Whether to serialize fields with duck-typing serialization behavior.
- Returns:
A dictionary representation of the model.
Validate the conversation follows logical message order
Bases:
BaseModel
A single message in ShareGPT format with enhanced validation
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class camel.messages.conversion.ToolCall(*, name: str, arguments: Dict[str, Any])[source]#
Bases:
BaseModel
Represents a single tool/function call with validation
- arguments: Dict[str, Any]#
- model_config: ClassVar[ConfigDict] = {'extra': 'forbid', 'json_schema_extra': {'examples': [{'arguments': {'city': 'London', 'units': 'celsius'}, 'name': 'get_weather'}]}}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- name: str#
- class camel.messages.conversion.ToolResponse(*, name: str, content: Any)[source]#
Bases:
BaseModel
Represents a tool/function response with validation. This is a base class and default implementation for tool responses, for the purpose of converting between different formats.
- content: Any#
- model_config: ClassVar[ConfigDict] = {'extra': 'forbid', 'json_schema_extra': {'examples': [{'content': {'conditions': 'sunny', 'humidity': 65, 'temperature': 20}, 'name': 'get_weather'}]}}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- name: str#