Model io
Contains model input and output related schemas used throughout the gllm_inference package.
References
NONE
Attachment
Bases: BaseModel
Defines a file attachment schema.
Attributes:
Name | Type | Description |
---|---|---|
data |
bytes
|
The content data of the file attachment. |
filename |
str
|
The filename of the file attachment. |
mime_type |
str
|
The mime type of the file attachment. |
url |
str | None
|
The URL of the file attachment. Defaults to None. |
__repr__()
Return string representation of the Attachment.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The string representation of the Attachment. |
__str__()
Return string representation of the Attachment.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The string representation of the Attachment. |
from_bytes(bytes, filename=None)
classmethod
Creates an Attachment from bytes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
bytes |
bytes
|
The bytes of the file. |
required |
filename |
str | None
|
The filename of the file. Defaults to None, in which case the filename will be derived from the mime type. |
None
|
Returns:
Name | Type | Description |
---|---|---|
Attachment |
Attachment
|
The instantiated Attachment. |
from_data_url(data_url, filename=None)
classmethod
Creates an Attachment from a data URL (data:[mime/type];base64,[bytes]).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_url |
str
|
The data URL of the file. |
required |
filename |
str | None
|
The filename of the file. Defaults to None, in which case the filename will be derived from the mime type. |
None
|
Returns:
Name | Type | Description |
---|---|---|
Attachment |
Attachment
|
The instantiated Attachment. |
from_path(path, filename=None)
classmethod
Creates an Attachment from a path.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
str
|
The path to the file. |
required |
filename |
str | None
|
The filename of the file. Defaults to None, in which case the filename will be derived from the path. |
None
|
Returns:
Name | Type | Description |
---|---|---|
Attachment |
Attachment
|
The instantiated Attachment. |
from_url(url, filename=None)
classmethod
Creates an Attachment from a URL.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
url |
str
|
The URL of the file. |
required |
filename |
str | None
|
The filename of the file. Defaults to None, in which case the filename will be derived from the URL. |
None
|
Returns:
Name | Type | Description |
---|---|---|
Attachment |
Attachment
|
The instantiated Attachment. |
write_to_file(path=None)
Writes the Attachment to a file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
str | None
|
The path to the file. Defaults to None, in which case the filename will be used as the path. |
None
|
CodeExecResult
Bases: BaseModel
Defines a code execution result when a language model is configured to execute code.
Attributes:
Name | Type | Description |
---|---|---|
id |
str
|
The ID of the code execution. Defaults to an empty string. |
code |
str
|
The executed code. Defaults to an empty string. |
output |
list[str | Attachment]
|
The output of the executed code. Defaults to an empty list. |
ContentPlaceholder
Bases: BaseModel
Defines a content placeholder schema.
The ContentPlaceholder
represents a lazy-loaded content to be sent to the language model.
The content must be converted into a supported content type before being sent to the language model.
Attributes:
Name | Type | Description |
---|---|---|
type |
str
|
The type of the content placeholder. |
metadata |
dict[str, Any]
|
The metadata of the content placeholder. |
LMOutput
Bases: BaseModel
Defines the output of a language model.
Attributes:
Name | Type | Description |
---|---|---|
response |
str
|
The text response. Defaults to an empty string. |
tool_calls |
list[ToolCall]
|
The tool calls, if the language model decides to invoke tools. Defaults to an empty list. |
structured_output |
dict[str, Any] | BaseModel | None
|
The structured output, if a response schema is defined for the language model. Defaults to None. |
token_usage |
TokenUsage | None
|
The token usage analytics, if requested. Defaults to None. |
duration |
float | None
|
The duration of the invocation in seconds, if requested. Defaults to None. |
finish_details |
dict[str, Any]
|
The details about how the generation finished, if requested. Defaults to an empty dictionary. |
reasoning |
list[Reasoning]
|
The reasoning, if the language model is configured to output reasoning. Defaults to an empty list. |
citations |
list[Chunk]
|
The citations, if the language model outputs citations. Defaults to an empty list. |
code_exec_results |
list[CodeExecResult]
|
The code execution results, if the language model decides to execute code. Defaults to an empty list. |
__repr__()
Return string representation of the LMOutput.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The string representation of the LMOutput. |
__str__()
Return string representation of the LMOutput.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The string representation of the LMOutput. |
Reasoning
Bases: BaseModel
Defines a reasoning output when a language model is configured to use reasoning.
Attributes:
Name | Type | Description |
---|---|---|
id |
str
|
The ID of the reasoning output. Defaults to an empty string. |
reasoning |
str
|
The reasoning text. Defaults to an empty string. |
type |
str
|
The type of the reasoning output. Defaults to an empty string. |
data |
str
|
The additional data of the reasoning output. Defaults to an empty string. |
TokenUsage
Bases: BaseModel
Defines the token usage data structure of a language model.
Attributes:
Name | Type | Description |
---|---|---|
input_tokens |
int
|
The number of input tokens. |
output_tokens |
int
|
The number of output tokens. |
ToolCall
Bases: BaseModel
Defines a tool call request when a language model decides to invoke a tool.
Attributes:
Name | Type | Description |
---|---|---|
id |
str
|
The ID of the tool call. |
name |
str
|
The name of the tool. |
args |
dict[str, Any]
|
The arguments of the tool call. |
ToolResult
Bases: BaseModel
Defines a tool result to be sent back to the language model.
Attributes:
Name | Type | Description |
---|---|---|
id |
str
|
The ID of the tool call. |
output |
str
|
The output of the tool call. |