response
¶
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.
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
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
CompletionResponse
¶
Bases: BaseModel
A class wrapping the response from the LLM model.
For a streaming response, it tracks the chunks of the response and builds the complete response when the streaming is finished.
chunks
class-attribute
instance-attribute
¶
chunks: List[Union[ModelResponse, ChatCompletionChunk]] = (
Field(
[],
description="The chunks of the response when streaming",
)
)
The chunks of the response when streaming.
complete_response
property
¶
The complete response from the model. This will block until the response is finished.
cost
class-attribute
instance-attribute
¶
cost: Optional[float] = Field(
None, description="The cost of the completion"
)
The cost of the completion.
is_finished
class-attribute
instance-attribute
¶
is_finished: bool = Field(
False,
description="Whether the response stream is finished",
)
Whether the response stream is finished.
is_stream
class-attribute
instance-attribute
¶
is_stream: bool = Field(
False, description="Whether the response is a stream"
)
Whether the response is a stream.
message
class-attribute
instance-attribute
¶
message: Optional[str] = Field(
None,
description="The top-choice message from the completion",
)
The top-choice message from the completion.
post_finish_callbacks
class-attribute
instance-attribute
¶
The post finish callbacks.
raw_response
class-attribute
instance-attribute
¶
The raw response from the model.
response_model
class-attribute
instance-attribute
¶
response_model: Any = Field(
None,
description="The BaseModel's subclass specifying the response format.",
)
The BaseModel's subclass specifying the response format.
response_obj
class-attribute
instance-attribute
¶
response_obj: Any = Field(
None,
description="The response object of response model, could be a stream",
)
The response object of response model, could be a stream.
results
property
¶
tool_calls
class-attribute
instance-attribute
¶
tool_calls: List[ToolCall] = Field(
[], description="The tool calls"
)
The tool calls.
usage
class-attribute
instance-attribute
¶
The usage of the completion.
format_stream
¶
Format the stream response as a text generator.
Source code in src/appl/core/response.py
register_post_finish_callback
¶
Register a post finish callback.
The callback will be called after the response is finished.
Source code in src/appl/core/response.py
set_response_obj
¶
streaming
¶
streaming(
display: bool = True, title: str = "APPL Streaming"
) -> CompletionResponse
Stream the response object and finish the response.
Source code in src/appl/core/response.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
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