core
¶
    
            ASSISTANT_ROLE
  
      module-attribute
  
¶
ASSISTANT_ROLE = MessageRole(ASSISTANT)
The assistant role with name not specified.
            SYSTEM_ROLE
  
      module-attribute
  
¶
SYSTEM_ROLE = MessageRole(SYSTEM)
The system role with name not specified.
            String
  
      module-attribute
  
¶
String: TypeAlias = Union[StringFuture, str]
String is a type alias for StringFuture or str.
            AIMessage
¶
AIMessage(
    content: Any = None,
    *,
    role: Optional[MessageRole] = None,
    tool_calls: Optional[List[ToolCall]] = None,
    **kwargs: Any
)
              Bases: BaseMessage
An assistant message in the conversation.
Source code in src/appl/core/message.py
                    
            get_content
¶
    Get the content of the message.
Materialize the content if it is a FutureValue.
Source code in src/appl/core/message.py
              
            get_dict
¶
get_dict(
    default_role: Optional[MessageRole] = None,
) -> Dict[str, Any]
Return a dict representation of the message.
Source code in src/appl/core/message.py
              
            
            merge
¶
merge(other: 'BaseMessage') -> Optional['Message']
Merge the message with another message.
Source code in src/appl/core/message.py
              
            should_merge
¶
should_merge(other: 'BaseMessage') -> bool
Whether the message should be merged with the other message.
Source code in src/appl/core/message.py
              
            str_with_default_role
¶
str_with_default_role(
    default_role: Optional[MessageRole] = None,
) -> str
Return the string representation of the message with default role.
            validate_role
¶
validate_role(target_role: MessageRole) -> None
Validate the role of the message, fill the role if not provided.
Source code in src/appl/core/message.py
              
            BaseMessage
¶
    
              Bases: BaseModel, ABC
The base class for messages.
Provides a more flexible way to create a message.
Source code in src/appl/core/message.py
                    
                  
            get_content
¶
    Get the content of the message.
Materialize the content if it is a FutureValue.
Source code in src/appl/core/message.py
              
            get_dict
¶
get_dict(
    default_role: Optional[MessageRole] = None,
) -> Dict[str, Any]
Return a dict representation of the message.
Source code in src/appl/core/message.py
              
            merge
¶
merge(other: 'BaseMessage') -> Optional['Message']
Merge the message with another message.
Source code in src/appl/core/message.py
              
            should_merge
¶
should_merge(other: 'BaseMessage') -> bool
Whether the message should be merged with the other message.
Source code in src/appl/core/message.py
              
            str_with_default_role
¶
str_with_default_role(
    default_role: Optional[MessageRole] = None,
) -> str
Return the string representation of the message with default role.
            validate_role
¶
validate_role(target_role: MessageRole) -> None
Validate the role of the message, fill the role if not provided.
Source code in src/appl/core/message.py
              
            ChatMessage
¶
ChatMessage(
    content: Any = None,
    *,
    role: Optional[MessageRole] = None,
    **kwargs: Any
)
              Bases: BaseMessage
A message in the chat conversation.
Source code in src/appl/core/message.py
                    
                  
            get_content
¶
    Get the content of the message.
Materialize the content if it is a FutureValue.
Source code in src/appl/core/message.py
              
            get_dict
¶
get_dict(
    default_role: Optional[MessageRole] = None,
) -> Dict[str, Any]
Return a dict representation of the message.
Source code in src/appl/core/message.py
              
            merge
¶
merge(other: 'BaseMessage') -> Optional['Message']
Merge the message with another message.
Source code in src/appl/core/message.py
              
            should_merge
¶
should_merge(other: 'BaseMessage') -> bool
Whether the message should be merged with the other message.
Source code in src/appl/core/message.py
              
            str_with_default_role
¶
str_with_default_role(
    default_role: Optional[MessageRole] = None,
) -> str
Return the string representation of the message with default role.
            validate_role
¶
validate_role(target_role: MessageRole) -> None
Validate the role of the message, fill the role if not provided.
Source code in src/appl/core/message.py
              
            ContentList
¶
    
              Bases: BaseModel
Represent a list of contents containing text, images and audio.
Source code in src/appl/core/types/content.py
                    
            append
¶
append(content: ContentPart) -> None
Append a content to the list.
If the last content is a string, it will be concatenated with the new content.
Source code in src/appl/core/types/content.py
              
            extend
¶
extend(contents: list[ContentPart]) -> None
            get_contents
¶
    
            ContentPart
¶
    
            Conversation
¶
Conversation(
    messages: Optional[
        Union[Iterable[BaseMessage], Iterable[Dict]]
    ] = None,
    *,
    system_messages: Optional[
        Iterable[SystemMessage]
    ] = None
)
              Bases: BaseModel
A conversation containing messages.
Source code in src/appl/core/message.py
                    
            append
¶
    Append a message to the conversation.
Source code in src/appl/core/message.py
              
            as_list
¶
    Return a list of dict representation of the conversation.
Source code in src/appl/core/message.py
              
            collapse
¶
    Collapse the messages in the conversation.
Source code in src/appl/core/message.py
              
            extend
¶
    Extend the conversation with another conversation.
            make_copy
¶
    
            materialize
¶
    
            pop
¶
pop() -> BaseMessage
            set_system_messages
¶
set_system_messages(messages: List[SystemMessage]) -> None
            FutureValue
¶
    
            MessageRole
¶
    
              Bases: BaseModel
The role of the message owner.
Parameters:
- 
          
type(Optional[Union[str, MessageRoleType]], default:None) –The type of the role.
 - 
          
name(Optional[str], default:None) –An optional name for the role, differentiate between roles of the same type."
 
Source code in src/appl/core/types/role.py
                    
            SystemMessage
¶
SystemMessage(
    content: Any = None,
    *,
    role: Optional[MessageRole] = None,
    **kwargs: Any
)
              Bases: BaseMessage
A system message in the conversation.
Source code in src/appl/core/message.py
                    
                  
            get_content
¶
    Get the content of the message.
Materialize the content if it is a FutureValue.
Source code in src/appl/core/message.py
              
            get_dict
¶
get_dict(
    default_role: Optional[MessageRole] = None,
) -> Dict[str, Any]
Return a dict representation of the message.
Source code in src/appl/core/message.py
              
            merge
¶
merge(other: 'BaseMessage') -> Optional['Message']
Merge the message with another message.
Source code in src/appl/core/message.py
              
            should_merge
¶
should_merge(other: 'BaseMessage') -> bool
Whether the message should be merged with the other message.
Source code in src/appl/core/message.py
              
            str_with_default_role
¶
str_with_default_role(
    default_role: Optional[MessageRole] = None,
) -> str
Return the string representation of the message with default role.
            validate_role
¶
validate_role(target_role: MessageRole) -> None
Validate the role of the message, fill the role if not provided.
Source code in src/appl/core/message.py
              
            TextContent
¶
TextContent(text: String)
              Bases: ContentPart
Represent a text in the message.
Source code in src/appl/core/types/content.py
                    
                  
            get_dict
¶
    
            ToolCall
¶
ToolCall(**kwargs: Any)
              Bases: BaseModel
The class representing a tool call.
Source code in src/appl/core/tool.py
                    
            args
  
      class-attribute
      instance-attribute
  
¶
args: str = Field(
    ...,
    description="The arguments to call the function with.",
)
The arguments to call the function with.
            id
  
      class-attribute
      instance-attribute
  
¶
id: str = Field(..., description="The ID of the tool call.")
The ID of the tool call.
            name
  
      class-attribute
      instance-attribute
  
¶
name: str = Field(
    ..., description="The name of the function to call."
)
The name of the function to call.
            from_dict
  
      classmethod
  
¶
    Create a ToolCall from a dictionary in the OpenAI format.
Source code in src/appl/core/tool.py
              
            
            from_openai_tool_call
  
      classmethod
  
¶
from_openai_tool_call(
    call: ChatCompletionMessageToolCall,
) -> ToolCall
Create a ToolCall from an OpenAI tool call.
            get_dict
¶
    Get the OpenAI format dictionary representation of the tool call.
            ToolMessage
¶
ToolMessage(
    content: Any = None,
    *,
    role: Optional[MessageRole] = None,
    tool_call_id: str = "",
    **kwargs: Any
)
              Bases: BaseMessage
A tool message in the conversation.
Source code in src/appl/core/message.py
                    
            get_content
¶
    Get the content of the message.
Materialize the content if it is a FutureValue.
Source code in src/appl/core/message.py
              
            get_dict
¶
    Return a dict representation of the message.
            merge
¶
merge(other: 'BaseMessage') -> Optional['Message']
Merge the message with another message.
Source code in src/appl/core/message.py
              
            should_merge
¶
should_merge(other: 'BaseMessage') -> bool
Whether the message should be merged with the other message.
Source code in src/appl/core/message.py
              
            str_with_default_role
¶
str_with_default_role(
    default_role: Optional[MessageRole] = None,
) -> str
Return the string representation of the message with default role.
            validate_role
¶
validate_role(target_role: MessageRole) -> None
Validate the role of the message, fill the role if not provided.
Source code in src/appl/core/message.py
              
            UserMessage
¶
UserMessage(
    content: Any = None,
    *,
    role: Optional[MessageRole] = None,
    **kwargs: Any
)
              Bases: BaseMessage
A user message in the conversation.
Source code in src/appl/core/message.py
                    
                  
            get_content
¶
    Get the content of the message.
Materialize the content if it is a FutureValue.
Source code in src/appl/core/message.py
              
            get_dict
¶
get_dict(
    default_role: Optional[MessageRole] = None,
) -> Dict[str, Any]
Return a dict representation of the message.
Source code in src/appl/core/message.py
              
            merge
¶
merge(other: 'BaseMessage') -> Optional['Message']
Merge the message with another message.
Source code in src/appl/core/message.py
              
            should_merge
¶
should_merge(other: 'BaseMessage') -> bool
Whether the message should be merged with the other message.
Source code in src/appl/core/message.py
              
            str_with_default_role
¶
str_with_default_role(
    default_role: Optional[MessageRole] = None,
) -> str
Return the string representation of the message with default role.
            validate_role
¶
validate_role(target_role: MessageRole) -> None
Validate the role of the message, fill the role if not provided.
Source code in src/appl/core/message.py
              
            as_message
¶
as_message(
    role: Optional[Union[MessageRole, str]],
    content: Union[
        ContentPart,
        String,
        Dict,
        Iterable[Dict[str, Any]],
        None,
    ] = None,
    *args: Any,
    **kwargs: Any
) -> BaseMessage
Create a message with role, content and extra arguments.
Source code in src/appl/core/message.py
              
            collapse_messages
¶
    Collapse a list of the messages by merging the messages with the same sender.
Source code in src/appl/core/message.py
              
            convert_to_message
¶
convert_to_message(
    m: Union[BaseMessage, Dict]
) -> BaseMessage
Convert a message in different formats to a BaseMessage.
Source code in src/appl/core/message.py
              
            
            dump_file
¶
dump_file(
    data: Any,
    file: str,
    mode: str = "w",
    ensure_folder_exists: bool = True,
    file_type: Optional[str] = None,
    *args: Any,
    **kwargs: Any
) -> None
Write the data to a file based on the file extension.
Source code in src/appl/core/io.py
              
            get_colored_role_text
¶
get_colored_role_text(
    role: Optional[MessageRole], content: str
) -> str
Get the colored text based on the role.
Source code in src/appl/core/message.py
              
            
            get_ext
¶
    
            get_role_color
¶
get_role_color(role: MessageRole) -> Optional[str]
Get the color of the message based on the role.
Source code in src/appl/core/message.py
              
            
            load_file
¶
load_file(
    file: str,
    mode: str = "r",
    file_type: Optional[str] = None,
    open_kwargs: Optional[Dict[str, Any]] = None,
    *args: Any,
    **kwargs: Any
) -> Any
Load a file based on the file extension and return the data.