camel.messages package

Contents

camel.messages package#

Submodules#

camel.messages.base module#

class camel.messages.base.BaseMessage(role_name: str, role_type: RoleType, meta_dict: Dict[str, str] | None, content: str, video_bytes: bytes | None = None, image_list: List[Image] | None = None, image_detail: Literal['auto', 'low', 'high'] = 'auto', video_detail: Literal['auto', 'low', 'high'] = 'low')[source]#

Bases: object

Base class for message objects used in CAMEL chat system.

Parameters:
  • role_name (str) – The name of the user or assistant role.

  • role_type (RoleType) – The type of role, either RoleType. ASSISTANT or RoleType.USER.

  • meta_dict (Optional[Dict[str, str]]) – Additional metadata dictionary for the message.

  • content (str) – The content of the message.

  • video_bytes (Optional[bytes]) – Optional bytes of a video associated with the message. Default is None.

  • image_list (Optional[List[Image.Image]]) – Optional list of PIL Image objects associated with the message. Default is None.

  • image_detail (Literal["auto", "low", "high"]) – Detail level of the images associated with the message. Default is “auto”.

  • video_detail (Literal["auto", "low", "high"]) – Detail level of the videos associated with the message. Default is “low”.

content: str#
create_new_instance(content: str) BaseMessage[source]#

Create a new instance of the BaseMessage with updated content.

Parameters:

content (str) – The new content value.

Returns:

The new instance of BaseMessage.

Return type:

BaseMessage

extract_text_and_code_prompts() Tuple[List[TextPrompt], List[CodePrompt]][source]#

Extract text and code prompts from the message content.

Returns:

A tuple containing a

list of text prompts and a list of code prompts extracted from the content.

Return type:

Tuple[List[TextPrompt], List[CodePrompt]]

image_detail: Literal['auto', 'low', 'high'] = 'auto'#
image_list: List[Image] | None = None#
classmethod make_assistant_message(role_name: str, content: str, meta_dict: Dict[str, str] | None = None, video_bytes: bytes | None = None, image_list: List[Image] | None = None, image_detail: OpenAIVisionDetailType | str = OpenAIVisionDetailType.AUTO, video_detail: OpenAIVisionDetailType | str = OpenAIVisionDetailType.LOW) BaseMessage[source]#
classmethod make_user_message(role_name: str, content: str, meta_dict: Dict[str, str] | None = None, video_bytes: bytes | None = None, image_list: List[Image] | None = None, image_detail: OpenAIVisionDetailType | str = OpenAIVisionDetailType.AUTO, video_detail: OpenAIVisionDetailType | str = OpenAIVisionDetailType.LOW) BaseMessage[source]#
meta_dict: Dict[str, str] | None#
role_name: str#
role_type: RoleType#
to_dict() Dict[source]#

Converts the message to a dictionary.

Returns:

The converted dictionary.

Return type:

dict

to_openai_assistant_message() ChatCompletionAssistantMessageParam[source]#

Converts the message to an OpenAIAssistantMessage object.

Returns:

The converted OpenAIAssistantMessage

object.

Return type:

OpenAIAssistantMessage

to_openai_message(role_at_backend: OpenAIBackendRole) ChatCompletionSystemMessageParam | ChatCompletionUserMessageParam | ChatCompletionAssistantMessageParam | ChatCompletionToolMessageParam | ChatCompletionFunctionMessageParam[source]#

Converts the message to an OpenAIMessage object.

Parameters:

role_at_backend (OpenAIBackendRole) – The role of the message in OpenAI chat system.

Returns:

The converted OpenAIMessage object.

Return type:

OpenAIMessage

to_openai_system_message() ChatCompletionSystemMessageParam[source]#

Converts the message to an OpenAISystemMessage object.

Returns:

The converted OpenAISystemMessage

object.

Return type:

OpenAISystemMessage

to_openai_user_message() ChatCompletionUserMessageParam[source]#

Converts the message to an OpenAIUserMessage object.

Returns:

The converted OpenAIUserMessage object.

Return type:

OpenAIUserMessage

video_bytes: bytes | None = None#
video_detail: Literal['auto', 'low', 'high'] = 'low'#

camel.messages.func_message module#

class camel.messages.func_message.FunctionCallingMessage(role_name: str, role_type: RoleType, meta_dict: Dict[str, str] | None, content: str, video_bytes: bytes | None = None, image_list: List[Image] | None = None, image_detail: Literal['auto', 'low', 'high'] = 'auto', video_detail: Literal['auto', 'low', 'high'] = 'low', func_name: str | None = None, args: Dict | None = None, result: Any | None = None)[source]#

Bases: BaseMessage

Class for message objects used specifically for function-related messages.

Parameters:
  • func_name (Optional[str]) – The name of the function used. (default: None)

  • args (Optional[Dict]) – The dictionary of arguments passed to the function. (default: None)

  • result (Optional[Any]) – The result of function execution. (default: None)

args: Dict | None = None#
func_name: str | None = None#
result: Any | None = None#
to_openai_assistant_message() ChatCompletionAssistantMessageParam[source]#

Converts the message to an OpenAIAssistantMessage object.

Returns:

The converted OpenAIAssistantMessage

object.

Return type:

OpenAIAssistantMessage

to_openai_function_message() ChatCompletionFunctionMessageParam[source]#

Converts the message to an OpenAIMessage object with the role being “function”.

Returns:

The converted OpenAIMessage object

with its role being “function”.

Return type:

OpenAIMessage

to_openai_message(role_at_backend: OpenAIBackendRole) ChatCompletionSystemMessageParam | ChatCompletionUserMessageParam | ChatCompletionAssistantMessageParam | ChatCompletionToolMessageParam | ChatCompletionFunctionMessageParam[source]#

Converts the message to an OpenAIMessage object.

Parameters:

role_at_backend (OpenAIBackendRole) – The role of the message in OpenAI chat system.

Returns:

The converted OpenAIMessage object.

Return type:

OpenAIMessage

Module contents#

class camel.messages.BaseMessage(role_name: str, role_type: RoleType, meta_dict: Dict[str, str] | None, content: str, video_bytes: bytes | None = None, image_list: List[Image] | None = None, image_detail: Literal['auto', 'low', 'high'] = 'auto', video_detail: Literal['auto', 'low', 'high'] = 'low')[source]#

Bases: object

Base class for message objects used in CAMEL chat system.

Parameters:
  • role_name (str) – The name of the user or assistant role.

  • role_type (RoleType) – The type of role, either RoleType. ASSISTANT or RoleType.USER.

  • meta_dict (Optional[Dict[str, str]]) – Additional metadata dictionary for the message.

  • content (str) – The content of the message.

  • video_bytes (Optional[bytes]) – Optional bytes of a video associated with the message. Default is None.

  • image_list (Optional[List[Image.Image]]) – Optional list of PIL Image objects associated with the message. Default is None.

  • image_detail (Literal["auto", "low", "high"]) – Detail level of the images associated with the message. Default is “auto”.

  • video_detail (Literal["auto", "low", "high"]) – Detail level of the videos associated with the message. Default is “low”.

content: str#
create_new_instance(content: str) BaseMessage[source]#

Create a new instance of the BaseMessage with updated content.

Parameters:

content (str) – The new content value.

Returns:

The new instance of BaseMessage.

Return type:

BaseMessage

extract_text_and_code_prompts() Tuple[List[TextPrompt], List[CodePrompt]][source]#

Extract text and code prompts from the message content.

Returns:

A tuple containing a

list of text prompts and a list of code prompts extracted from the content.

Return type:

Tuple[List[TextPrompt], List[CodePrompt]]

image_detail: Literal['auto', 'low', 'high'] = 'auto'#
image_list: List[Image] | None = None#
classmethod make_assistant_message(role_name: str, content: str, meta_dict: Dict[str, str] | None = None, video_bytes: bytes | None = None, image_list: List[Image] | None = None, image_detail: OpenAIVisionDetailType | str = OpenAIVisionDetailType.AUTO, video_detail: OpenAIVisionDetailType | str = OpenAIVisionDetailType.LOW) BaseMessage[source]#
classmethod make_user_message(role_name: str, content: str, meta_dict: Dict[str, str] | None = None, video_bytes: bytes | None = None, image_list: List[Image] | None = None, image_detail: OpenAIVisionDetailType | str = OpenAIVisionDetailType.AUTO, video_detail: OpenAIVisionDetailType | str = OpenAIVisionDetailType.LOW) BaseMessage[source]#
meta_dict: Dict[str, str] | None#
role_name: str#
role_type: RoleType#
to_dict() Dict[source]#

Converts the message to a dictionary.

Returns:

The converted dictionary.

Return type:

dict

to_openai_assistant_message() ChatCompletionAssistantMessageParam[source]#

Converts the message to an OpenAIAssistantMessage object.

Returns:

The converted OpenAIAssistantMessage

object.

Return type:

OpenAIAssistantMessage

to_openai_message(role_at_backend: OpenAIBackendRole) ChatCompletionSystemMessageParam | ChatCompletionUserMessageParam | ChatCompletionAssistantMessageParam | ChatCompletionToolMessageParam | ChatCompletionFunctionMessageParam[source]#

Converts the message to an OpenAIMessage object.

Parameters:

role_at_backend (OpenAIBackendRole) – The role of the message in OpenAI chat system.

Returns:

The converted OpenAIMessage object.

Return type:

OpenAIMessage

to_openai_system_message() ChatCompletionSystemMessageParam[source]#

Converts the message to an OpenAISystemMessage object.

Returns:

The converted OpenAISystemMessage

object.

Return type:

OpenAISystemMessage

to_openai_user_message() ChatCompletionUserMessageParam[source]#

Converts the message to an OpenAIUserMessage object.

Returns:

The converted OpenAIUserMessage object.

Return type:

OpenAIUserMessage

video_bytes: bytes | None = None#
video_detail: Literal['auto', 'low', 'high'] = 'low'#
class camel.messages.FunctionCallingMessage(role_name: str, role_type: RoleType, meta_dict: Dict[str, str] | None, content: str, video_bytes: bytes | None = None, image_list: List[Image] | None = None, image_detail: Literal['auto', 'low', 'high'] = 'auto', video_detail: Literal['auto', 'low', 'high'] = 'low', func_name: str | None = None, args: Dict | None = None, result: Any | None = None)[source]#

Bases: BaseMessage

Class for message objects used specifically for function-related messages.

Parameters:
  • func_name (Optional[str]) – The name of the function used. (default: None)

  • args (Optional[Dict]) – The dictionary of arguments passed to the function. (default: None)

  • result (Optional[Any]) – The result of function execution. (default: None)

args: Dict | None = None#
content: str#
func_name: str | None = None#
meta_dict: Dict[str, str] | None#
result: Any | None = None#
role_name: str#
role_type: RoleType#
to_openai_assistant_message() ChatCompletionAssistantMessageParam[source]#

Converts the message to an OpenAIAssistantMessage object.

Returns:

The converted OpenAIAssistantMessage

object.

Return type:

OpenAIAssistantMessage

to_openai_function_message() ChatCompletionFunctionMessageParam[source]#

Converts the message to an OpenAIMessage object with the role being “function”.

Returns:

The converted OpenAIMessage object

with its role being “function”.

Return type:

OpenAIMessage

to_openai_message(role_at_backend: OpenAIBackendRole) ChatCompletionSystemMessageParam | ChatCompletionUserMessageParam | ChatCompletionAssistantMessageParam | ChatCompletionToolMessageParam | ChatCompletionFunctionMessageParam[source]#

Converts the message to an OpenAIMessage object.

Parameters:

role_at_backend (OpenAIBackendRole) – The role of the message in OpenAI chat system.

Returns:

The converted OpenAIMessage object.

Return type:

OpenAIMessage

camel.messages.OpenAIAssistantMessage#

alias of ChatCompletionAssistantMessageParam

camel.messages.OpenAISystemMessage#

alias of ChatCompletionSystemMessageParam

camel.messages.OpenAIUserMessage#

alias of ChatCompletionUserMessageParam