core
¶
ASSISTANT_ROLE
module-attribute
¶
ASSISTANT_ROLE = MessageRole(ASSISTANT)
The assistant role with name not specified.
MaybeOneOrMany
module-attribute
¶
A type that can be either a single item, a sequence of items, or None.
OneOrMany
module-attribute
¶
A type that can be either a single item or a sequence of items.
SYSTEM_ROLE
module-attribute
¶
SYSTEM_ROLE = MessageRole(SYSTEM)
The system role with name not specified.
StrOrImg
module-attribute
¶
A type that can be either a string or an image.
String
module-attribute
¶
String = 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_content(as_str: bool = False) -> Any
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 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_content(as_str: bool = False) -> Any
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 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
CallFuture
¶
CallFuture(
func: Callable,
*args: Any,
use_process: bool = False,
lazy_eval: bool = False,
**kwargs: Any
)
Bases: FutureValue
Represent a function call that may not be ready yet.
Parameters:
-
func
(Callable
) –The function to call.
-
*args
(Any
, default:()
) –The arguments of the function.
-
use_process
(bool
, default:False
) –Whether to use a process pool executor.
-
lazy_eval
(bool
, default:False
) –Whether to delay the start of the call until needed.
-
**kwargs
(Any
, default:{}
) –The keyword arguments of the function.
Source code in src/appl/core/types/futures.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_content(as_str: bool = False) -> Any
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 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
CmpStringFuture
¶
CmpStringFuture(
a: StringFuture,
b: StringFuture,
op: Callable[[str, str], bool],
)
Bases: FutureValue
Represent a comparison between a StringFuture and another value.
Source code in src/appl/core/types/futures.py
ContentList
¶
Bases: BaseModel
Represent a list of contents containing text and images.
append
¶
append(content: StrOrImg) -> 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
¶
get_contents
¶
get_contents() -> List[Dict[str, Any]]
Return the contents as a list of dictionaries.
Source code in src/appl/core/types/content.py
Conversation
¶
Bases: BaseModel
A conversation containing messages.
append
¶
Append a message to the conversation.
Source code in src/appl/core/message.py
as_list
¶
as_list(
default_role: Optional[MessageRole] = USER_ROLE,
) -> List[Dict[str, str]]
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
¶
set_system_messages
¶
set_system_messages(messages: List[SystemMessage]) -> None
FutureValue
¶
Bases: ABC
Represents a value that may not be ready yet.
Image
¶
Bases: BaseModel
Represent an image in the message.
See the guide for more information about the detail level.
Source code in src/appl/core/types/content.py
from_file
classmethod
¶
Construct an image prompt from an image file.
from_image
classmethod
¶
Construct an image prompt from a PIL ImageFile.
Source code in src/appl/core/types/content.py
MessageRole
¶
ResponseType
¶
The type of generation response.
UNFINISHED
class-attribute
instance-attribute
¶
The response is not finished.
StringFuture
¶
StringFuture(content: Any = '', set_value: bool = False)
Bases: FutureValue
, BaseModel
StringFuture is a string that may not be ready yet.
Source code in src/appl/core/types/futures.py
from_list
classmethod
¶
from_list(content: List[Any]) -> StringFuture
join
¶
join(iterable: Iterable[StringFuture]) -> StringFuture
Concatenate any number of strings.
The StringFuture whose method is called is inserted in between each given StringFuture. The result is returned as a new StringFuture.
Source code in src/appl/core/types/futures.py
materialized
¶
materialized() -> StringFuture
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_content(as_str: bool = False) -> Any
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 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
ToolCall
¶
Bases: BaseModel
The class representing a tool call.
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
¶
from_dict(call: Dict) -> ToolCall
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_content(as_str: bool = False) -> Any
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(*args: Any, **kwargs: Any) -> Dict[str, Any]
Return a dict representation of the message.
merge
¶
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_content(as_str: bool = False) -> Any
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 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[MessageRole],
content: StrOrImg,
*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
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.
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.