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)[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
orRoleType.USER
.meta_dict (Optional[Dict[str, str]]) – Additional metadata dictionary for the message.
role (str) – The role of the message in OpenAI chat system, either
"system"
,"user"
, or"assistant"
.content (str) – The content of the message.
- 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:
- 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]]
- classmethod make_assistant_message(role_name: str, content: str, meta_dict: Dict[str, str] | None = None) BaseMessage [source]#
- classmethod make_user_message(role_name: str, content: str, meta_dict: Dict[str, str] | None = None) BaseMessage [source]#
- meta_dict: Dict[str, str] | None#
- role_name: str#
- to_dict() Dict [source]#
Converts the message to a dictionary.
- Returns:
The converted dictionary.
- Return type:
dict
- to_openai_assistant_message() Dict[str, str] [source]#
Converts the message to an
OpenAIAssistantMessage
object.- Returns:
- The converted
OpenAIAssistantMessage
object.
- The converted
- Return type:
OpenAIAssistantMessage
- to_openai_message(role_at_backend: str) Dict[str, str] [source]#
Converts the message to an
OpenAIMessage
object.- Parameters:
role_at_backend (str) – The role of the message in OpenAI chat system, either
"system"
,"user"
, or obj:”assistant”.- Returns:
The converted
OpenAIMessage
object.- Return type:
OpenAIMessage
camel.messages.chat_messages module#
camel.messages.system_messages module#
Module contents#
- class camel.messages.BaseMessage(role_name: str, role_type: RoleType, meta_dict: Dict[str, str] | None, content: str)[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
orRoleType.USER
.meta_dict (Optional[Dict[str, str]]) – Additional metadata dictionary for the message.
role (str) – The role of the message in OpenAI chat system, either
"system"
,"user"
, or"assistant"
.content (str) – The content of the message.
- 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:
- 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]]
- classmethod make_assistant_message(role_name: str, content: str, meta_dict: Dict[str, str] | None = None) BaseMessage [source]#
- classmethod make_user_message(role_name: str, content: str, meta_dict: Dict[str, str] | None = None) BaseMessage [source]#
- meta_dict: Dict[str, str] | None#
- role_name: str#
- to_dict() Dict [source]#
Converts the message to a dictionary.
- Returns:
The converted dictionary.
- Return type:
dict
- to_openai_assistant_message() Dict[str, str] [source]#
Converts the message to an
OpenAIAssistantMessage
object.- Returns:
- The converted
OpenAIAssistantMessage
object.
- The converted
- Return type:
OpenAIAssistantMessage
- to_openai_message(role_at_backend: str) Dict[str, str] [source]#
Converts the message to an
OpenAIMessage
object.- Parameters:
role_at_backend (str) – The role of the message in OpenAI chat system, either
"system"
,"user"
, or obj:”assistant”.- Returns:
The converted
OpenAIMessage
object.- Return type:
OpenAIMessage
- class camel.messages.FunctionCallingMessage(role_name: str, role_type: RoleType, meta_dict: Dict[str, str] | None, content: str, 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#
- to_openai_assistant_message() Dict[str, str] [source]#
Converts the message to an
OpenAIAssistantMessage
object.- Returns:
- The converted
OpenAIAssistantMessage
object.
- The converted
- Return type:
OpenAIAssistantMessage
- to_openai_function_message() Dict[str, str] [source]#
Converts the message to an
OpenAIMessage
object with the role being “function”.- Returns:
- The converted
OpenAIMessage
object with its role being “function”.
- The converted
- Return type:
OpenAIMessage
- to_openai_message(role_at_backend: str) Dict[str, str] [source]#
Converts the message to an
OpenAIMessage
object.- Parameters:
role_at_backend (str) – The role of the message in OpenAI chat system, either
"system"
,"user"
, or obj:”assistant”.- Returns:
The converted
OpenAIMessage
object.- Return type:
OpenAIMessage