Data Classes
answerβ
ExtractedAnswerβ
to_dictβ
Serialize the object to a dictionary.
Returns:
dict[str, Any]β Serialized dictionary representation of the object.
from_dictβ
Deserialize the object from a dictionary.
Parameters:
- data (
dict[str, Any]) β Dictionary representation of the object.
Returns:
ExtractedAnswerβ Deserialized object.
GeneratedAnswerβ
to_dictβ
Serialize the object to a dictionary.
Returns:
dict[str, Any]β Serialized dictionary representation of the object.
from_dictβ
Deserialize the object from a dictionary.
Parameters:
- data (
dict[str, Any]) β Dictionary representation of the object.
Returns:
GeneratedAnswerβ Deserialized object.
breakpointsβ
Breakpointβ
A dataclass to hold a breakpoint for a component.
Parameters:
- component_name (
str) β The name of the component where the breakpoint is set. - visit_count (
int) β The number of times the component must be visited before the breakpoint is triggered. - snapshot_file_path (
str | None) β Optional path to store a snapshot of the pipeline when the breakpoint is hit. This is useful for debugging purposes, allowing you to inspect the state of the pipeline at the time of the breakpoint and to resume execution from that point.
to_dictβ
Convert the Breakpoint to a dictionary representation.
Returns:
dict[str, Any]β A dictionary containing the component name, visit count, and debug path.
from_dictβ
Populate the Breakpoint from a dictionary representation.
Parameters:
- data (
dict) β A dictionary containing the component name, visit count, and debug path.
Returns:
Breakpointβ An instance of Breakpoint.
ToolBreakpointβ
Bases: Breakpoint
A dataclass representing a breakpoint specific to tools used within an Agent component.
Inherits from Breakpoint and adds the ability to target individual tools. If tool_name is None,
the breakpoint applies to all tools within the Agent component.
Parameters:
- tool_name (
str | None) β The name of the tool to target within the Agent component. If None, applies to all tools.
AgentBreakpointβ
A dataclass representing a breakpoint tied to an Agentβs execution.
This allows for debugging either a specific component (e.g., the chat generator) or a tool used by the agent. It enforces constraints on which component names are valid for each breakpoint type.
Parameters:
- agent_name (
str) β The name of the agent component in a pipeline where the breakpoint is set. - break_point (
Breakpoint | ToolBreakpoint) β An instance of Breakpoint or ToolBreakpoint indicating where to break execution.
Raises:
ValueErrorβ If the component_name is invalid for the given breakpoint type:- Breakpoint must have component_name='chat_generator'.
- ToolBreakpoint must have component_name='tool_invoker'.
to_dictβ
Convert the AgentBreakpoint to a dictionary representation.
Returns:
dict[str, Any]β A dictionary containing the agent name and the breakpoint details.
from_dictβ
Populate the AgentBreakpoint from a dictionary representation.
Parameters:
- data (
dict) β A dictionary containing the agent name and the breakpoint details.
Returns:
AgentBreakpointβ An instance of AgentBreakpoint.
AgentSnapshotβ
to_dictβ
Convert the AgentSnapshot to a dictionary representation.
Returns:
dict[str, Any]β A dictionary containing the agent state, timestamp, and breakpoint.
from_dictβ
Populate the AgentSnapshot from a dictionary representation.
Parameters:
- data (
dict) β A dictionary containing the agent state, timestamp, and breakpoint.
Returns:
AgentSnapshotβ An instance of AgentSnapshot.
PipelineStateβ
A dataclass to hold the state of the pipeline at a specific point in time.
Parameters:
- component_visits (
dict[str, int]) β A dictionary mapping component names to their visit counts. - inputs (
dict[str, Any]) β The inputs processed by the pipeline at the time of the snapshot. - pipeline_outputs (
dict[str, Any]) β Dictionary containing the final outputs of the pipeline up to the breakpoint.
to_dictβ
Convert the PipelineState to a dictionary representation.
Returns:
dict[str, Any]β A dictionary containing the inputs, component visits, and pipeline outputs.
from_dictβ
Populate the PipelineState from a dictionary representation.
Parameters:
- data (
dict) β A dictionary containing the inputs, component visits, and pipeline outputs.
Returns:
PipelineStateβ An instance of PipelineState.
PipelineSnapshotβ
A dataclass to hold a snapshot of the pipeline at a specific point in time.
Parameters:
- original_input_data (
dict[str, Any]) β The original input data provided to the pipeline. - ordered_component_names (
list[str]) β A list of component names in the order they were visited. - pipeline_state (
PipelineState) β The state of the pipeline at the time of the snapshot. - break_point (
AgentBreakpoint | Breakpoint) β The breakpoint that triggered the snapshot. - agent_snapshot (
AgentSnapshot | None) β Optional agent snapshot if the breakpoint is an agent breakpoint. - timestamp (
datetime | None) β A timestamp indicating when the snapshot was taken. - include_outputs_from (
set[str]) β Set of component names whose outputs should be included in the pipeline results.
to_dictβ
Convert the PipelineSnapshot to a dictionary representation.
Returns:
dict[str, Any]β A dictionary containing the pipeline state, timestamp, breakpoint, agent snapshot, original input data, ordered component names, include_outputs_from, and pipeline outputs.
from_dictβ
Populate the PipelineSnapshot from a dictionary representation.
Parameters:
- data (
dict) β A dictionary containing the pipeline state, timestamp, breakpoint, agent snapshot, original input data, ordered component names, include_outputs_from, and pipeline outputs.
byte_streamβ
ByteStreamβ
Base data class representing a binary object in the Haystack API.
Parameters:
- data (
bytes) β The binary data stored in Bytestream. - meta (
dict[str, Any]) β Additional metadata to be stored with the ByteStream. - mime_type (
str | None) β The mime type of the binary data.
to_fileβ
Write the ByteStream to a file. Note: the metadata will be lost.
Parameters:
- destination_path (
Path) β The path to write the ByteStream to.
from_file_pathβ
from_file_path(
filepath: Path,
mime_type: str | None = None,
meta: dict[str, Any] | None = None,
guess_mime_type: bool = False,
) -> ByteStream
Create a ByteStream from the contents read from a file.
Parameters:
- filepath (
Path) β A valid path to a file. - mime_type (
str | None) β The mime type of the file. - meta (
dict[str, Any] | None) β Additional metadata to be stored with the ByteStream. - guess_mime_type (
bool) β Whether to guess the mime type from the file.
from_stringβ
from_string(
text: str,
encoding: str = "utf-8",
mime_type: str | None = None,
meta: dict[str, Any] | None = None,
) -> ByteStream
Create a ByteStream encoding a string.
Parameters:
- text (
str) β The string to encode - encoding (
str) β The encoding used to convert the string into bytes - mime_type (
str | None) β The mime type of the file. - meta (
dict[str, Any] | None) β Additional metadata to be stored with the ByteStream.
to_stringβ
Convert the ByteStream to a string, metadata will not be included.
Parameters:
- encoding (
str) β The encoding used to convert the bytes to a string. Defaults to "utf-8".
Returns:
strβ The string representation of the ByteStream.
Raises:
UnicodeDecodeErrorβ If the ByteStream data cannot be decoded with the specified encoding.
to_dictβ
Convert the ByteStream to a dictionary representation.
Returns:
dict[str, Any]β A dictionary with keys 'data', 'meta', and 'mime_type'.
from_dictβ
Create a ByteStream from a dictionary representation.
Parameters:
- data (
dict[str, Any]) β A dictionary with keys 'data', 'meta', and 'mime_type'.
Returns:
ByteStreamβ A ByteStream instance.
chat_messageβ
ChatRoleβ
Bases: str, Enum
Enumeration representing the roles within a chat.
from_strβ
Convert a string to a ChatRole enum.
TextContentβ
The textual content of a chat message.
Parameters:
- text (
str) β The text content of the message.
to_dictβ
Convert TextContent into a dictionary.
from_dictβ
Create a TextContent from a dictionary.
ToolCallβ
Represents a Tool call prepared by the model, usually contained in an assistant message.
Parameters:
- id (
str | None) β The ID of the Tool call. - tool_name (
str) β The name of the Tool to call. - arguments (
dict[str, Any]) β The arguments to call the Tool with. - extra (
dict[str, Any] | None) β Dictionary of extra information about the Tool call. Use to store provider-specific information. To avoid serialization issues, values should be JSON serializable.
to_dictβ
Convert ToolCall into a dictionary.
Returns:
dict[str, Any]β A dictionary with keys 'tool_name', 'arguments', 'id', and 'extra'.
from_dictβ
Creates a new ToolCall object from a dictionary.
Parameters:
- data (
dict[str, Any]) β The dictionary to build the ToolCall object.
Returns:
ToolCallβ The created object.
ToolCallResultβ
Represents the result of a Tool invocation.
Parameters:
- result (
ToolCallResultContentT) β The result of the Tool invocation. - origin (
ToolCall) β The Tool call that produced this result. - error (
bool) β Whether the Tool invocation resulted in an error.
to_dictβ
Converts ToolCallResult into a dictionary.
Returns:
dict[str, Any]β A dictionary with keys 'result', 'origin', and 'error'.
from_dictβ
Creates a ToolCallResult from a dictionary.
Parameters:
- data (
dict[str, Any]) β The dictionary to build the ToolCallResult object.
Returns:
ToolCallResultβ The created object.
ReasoningContentβ
Represents the optional reasoning content prepared by the model, usually contained in an assistant message.
Parameters:
- reasoning_text (
str) β The reasoning text produced by the model. - extra (
dict[str, Any]) β Dictionary of extra information about the reasoning content. Use to store provider-specific information. To avoid serialization issues, values should be JSON serializable.
to_dictβ
Convert ReasoningContent into a dictionary.
Returns:
dict[str, Any]β A dictionary with keys 'reasoning_text', and 'extra'.
from_dictβ
Creates a new ReasoningContent object from a dictionary.
Parameters:
- data (
dict[str, Any]) β The dictionary to build the ReasoningContent object.
Returns:
ReasoningContentβ The created object.
ChatMessageβ
Represents a message in a LLM chat conversation.
Use the from_assistant, from_user, from_system, and from_tool class methods to create a ChatMessage.
roleβ
Returns the role of the entity sending the message.
metaβ
Returns the metadata associated with the message.
nameβ
Returns the name associated with the message.
textsβ
Returns the list of all texts contained in the message.
textβ
Returns the first text contained in the message.
tool_callsβ
Returns the list of all Tool calls contained in the message.
tool_callβ
Returns the first Tool call contained in the message.
tool_call_resultsβ
Returns the list of all Tool call results contained in the message.
tool_call_resultβ
Returns the first Tool call result contained in the message.
imagesβ
Returns the list of all images contained in the message.
imageβ
Returns the first image contained in the message.
filesβ
Returns the list of all files contained in the message.
fileβ
Returns the first file contained in the message.
reasoningsβ
Returns the list of all reasoning contents contained in the message.
reasoningβ
Returns the first reasoning content contained in the message.
is_fromβ
Check if the message is from a specific role.
Parameters:
- role (
ChatRole | str) β The role to check against.
Returns:
boolβ True if the message is from the specified role, False otherwise.
from_userβ
from_user(
text: str | None = None,
meta: dict[str, Any] | None = None,
name: str | None = None,
*,
content_parts: (
Sequence[TextContent | str | ImageContent | FileContent] | None
) = None
) -> ChatMessage
Create a message from the user.
Parameters:
- text (
str | None) β The text content of the message. Specify this or content_parts. - meta (
dict[str, Any] | None) β Additional metadata associated with the message. - name (
str | None) β An optional name for the participant. This field is only supported by OpenAI. - content_parts (
Sequence[TextContent | str | ImageContent | FileContent] | None) β A list of content parts to include in the message. Specify this or text.
Returns:
ChatMessageβ A new ChatMessage instance.
from_systemβ
from_system(
text: str, meta: dict[str, Any] | None = None, name: str | None = None
) -> ChatMessage
Create a message from the system.
Parameters:
- text (
str) β The text content of the message. - meta (
dict[str, Any] | None) β Additional metadata associated with the message. - name (
str | None) β An optional name for the participant. This field is only supported by OpenAI.
Returns:
ChatMessageβ A new ChatMessage instance.
from_assistantβ
from_assistant(
text: str | None = None,
meta: dict[str, Any] | None = None,
name: str | None = None,
tool_calls: list[ToolCall] | None = None,
*,
reasoning: str | ReasoningContent | None = None
) -> ChatMessage
Create a message from the assistant.
Parameters:
- text (
str | None) β The text content of the message. - meta (
dict[str, Any] | None) β Additional metadata associated with the message. - name (
str | None) β An optional name for the participant. This field is only supported by OpenAI. - tool_calls (
list[ToolCall] | None) β The Tool calls to include in the message. - reasoning (
str | ReasoningContent | None) β The reasoning content to include in the message.
Returns:
ChatMessageβ A new ChatMessage instance.
from_toolβ
from_tool(
tool_result: ToolCallResultContentT,
origin: ToolCall,
error: bool = False,
meta: dict[str, Any] | None = None,
) -> ChatMessage
Create a message from a Tool.
Parameters:
- tool_result (
ToolCallResultContentT) β The result of the Tool invocation. - origin (
ToolCall) β The Tool call that produced this result. - error (
bool) β Whether the Tool invocation resulted in an error. - meta (
dict[str, Any] | None) β Additional metadata associated with the message.
Returns:
ChatMessageβ A new ChatMessage instance.
to_dictβ
Converts ChatMessage into a dictionary.
Returns:
dict[str, Any]β Serialized version of the object.
from_dictβ
Creates a new ChatMessage object from a dictionary.
Parameters:
- data (
dict[str, Any]) β The dictionary to build the ChatMessage object.
Returns:
ChatMessageβ The created object.
to_openai_dict_formatβ
Convert a ChatMessage to the dictionary format expected by OpenAI's Chat Completions API.
Parameters:
- require_tool_call_ids (
bool) β If True (default), enforces that each Tool Call includes a non-nullidattribute. Set to False to allow Tool Calls withoutid, which may be suitable for shallow OpenAI-compatible APIs.
Returns:
dict[str, Any]β The ChatMessage in the format expected by OpenAI's Chat Completions API.
Raises:
ValueErrorβ If the message format is invalid, or ifrequire_tool_call_idsis True and any Tool Call is missing anidattribute.
from_openai_dict_formatβ
Create a ChatMessage from a dictionary in the format expected by OpenAI's Chat API.
NOTE: While OpenAI's API requires tool_call_id in both tool calls and tool messages, this method
accepts messages without it to support shallow OpenAI-compatible APIs.
If you plan to use the resulting ChatMessage with OpenAI, you must include tool_call_id or you'll
encounter validation errors.
Parameters:
- message (
dict[str, Any]) β The OpenAI dictionary to build the ChatMessage object.
Returns:
ChatMessageβ The created ChatMessage object.
Raises:
ValueErrorβ If the message dictionary is missing required fields.
documentβ
Documentβ
Base data class containing some data to be queried.
Can contain text snippets and file paths to images or audios. Documents can be sorted by score and saved to/from dictionary and JSON.
Parameters:
- id (
str) β Unique identifier for the document. When not set, it's generated based on the Document fields' values. - content (
str | None) β Text of the document, if the document contains text. - blob (
ByteStream | None) β Binary data associated with the document, if the document has any binary data associated with it. - meta (
dict[str, Any]) β Additional custom metadata for the document. Must be JSON-serializable. - score (
float | None) β Score of the document. Used for ranking, usually assigned by retrievers. - embedding (
list[float] | None) β dense vector representation of the document. - sparse_embedding (
SparseEmbedding | None) β sparse vector representation of the document.
to_dictβ
Converts Document into a dictionary.
blob field is converted to a JSON-serializable type.
Parameters:
- flatten (
bool) β Whether to flattenmetafield or not. Defaults toTrueto be backward-compatible with Haystack 1.x.
from_dictβ
Creates a new Document object from a dictionary.
The blob field is converted to its original type.
content_typeβ
Returns the type of the content for the document.
This is necessary to keep backward compatibility with 1.x.
file_contentβ
FileContentβ
The file content of a chat message.
Parameters:
- base64_data (
str) β A base64 string representing the file. - mime_type (
str | None) β The MIME type of the file (e.g. "application/pdf"). Providing this value is recommended, as most LLM providers require it. If not provided, the MIME type is guessed from the base64 string, which can be slow and not always reliable. - filename (
str | None) β Optional filename of the file. Some LLM providers use this information. - extra (
dict[str, Any]) β Dictionary of extra information about the file. Can be used to store provider-specific information. To avoid serialization issues, values should be JSON serializable. - validation (
bool) β If True (default), a validation process is performed: - Check whether the base64 string is valid;
- Guess the MIME type if not provided. Set to False to skip validation and speed up initialization.
to_dictβ
Convert FileContent into a dictionary.
from_dictβ
Create an FileContent from a dictionary.
from_file_pathβ
from_file_path(
file_path: str | Path,
*,
filename: str | None = None,
extra: dict[str, Any] | None = None
) -> FileContent
Create an FileContent object from a file path.
Parameters:
- file_path (
str | Path) β The path to the file. - filename (
str | None) β Optional file name. Some LLM providers use this information. If not provided, the filename is extracted from the file path. - extra (
dict[str, Any] | None) β Dictionary of extra information about the file. Can be used to store provider-specific information. To avoid serialization issues, values should be JSON serializable.
Returns:
FileContentβ An FileContent object.
from_urlβ
from_url(
url: str,
*,
retry_attempts: int = 2,
timeout: int = 10,
filename: str | None = None,
extra: dict[str, Any] | None = None
) -> FileContent
Create an FileContent object from a URL. The file is downloaded and converted to a base64 string.
Parameters:
- url (
str) β The URL of the file. - retry_attempts (
int) β The number of times to retry to fetch the URL's content. - timeout (
int) β Timeout in seconds for the request. - filename (
str | None) β Optional filename of the file. Some LLM providers use this information. If not provided, the filename is extracted from the URL. - extra (
dict[str, Any] | None) β Dictionary of extra information about the file. Can be used to store provider-specific information. To avoid serialization issues, values should be JSON serializable.
Returns:
FileContentβ An FileContent object.
image_contentβ
ImageContentβ
The image content of a chat message.
Parameters:
- base64_image (
str) β A base64 string representing the image. - mime_type (
str | None) β The MIME type of the image (e.g. "image/png", "image/jpeg"). Providing this value is recommended, as most LLM providers require it. If not provided, the MIME type is guessed from the base64 string, which can be slow and not always reliable. - detail (
Literal['auto', 'high', 'low'] | None) β Optional detail level of the image (only supported by OpenAI). One of "auto", "high", or "low". - meta (
dict[str, Any]) β Optional metadata for the image. - validation (
bool) β If True (default), a validation process is performed: - Check whether the base64 string is valid;
- Guess the MIME type if not provided;
- Check if the MIME type is a valid image MIME type. Set to False to skip validation and speed up initialization.
showβ
Shows the image.
to_dictβ
Convert ImageContent into a dictionary.
from_dictβ
Create an ImageContent from a dictionary.
from_file_pathβ
from_file_path(
file_path: str | Path,
*,
size: tuple[int, int] | None = None,
detail: Literal["auto", "high", "low"] | None = None,
meta: dict[str, Any] | None = None
) -> ImageContent
Create an ImageContent object from a file path.
It exposes similar functionality as the ImageFileToImageContent component. For PDF to ImageContent conversion,
use the PDFToImageContent component.
Parameters:
- file_path (
str | Path) β The path to the image file. PDF files are not supported. For PDF to ImageContent conversion, use thePDFToImageContentcomponent. - size (
tuple[int, int] | None) β If provided, resizes the image to fit within the specified dimensions (width, height) while maintaining aspect ratio. This reduces file size, memory usage, and processing time, which is beneficial when working with models that have resolution constraints or when transmitting images to remote services. - detail (
Literal['auto', 'high', 'low'] | None) β Optional detail level of the image (only supported by OpenAI). One of "auto", "high", or "low". - meta (
dict[str, Any] | None) β Additional metadata for the image.
Returns:
ImageContentβ An ImageContent object.
from_urlβ
from_url(
url: str,
*,
retry_attempts: int = 2,
timeout: int = 10,
size: tuple[int, int] | None = None,
detail: Literal["auto", "high", "low"] | None = None,
meta: dict[str, Any] | None = None
) -> ImageContent
Create an ImageContent object from a URL. The image is downloaded and converted to a base64 string.
For PDF to ImageContent conversion, use the PDFToImageContent component.
Parameters:
- url (
str) β The URL of the image. PDF files are not supported. For PDF to ImageContent conversion, use thePDFToImageContentcomponent. - retry_attempts (
int) β The number of times to retry to fetch the URL's content. - timeout (
int) β Timeout in seconds for the request. - size (
tuple[int, int] | None) β If provided, resizes the image to fit within the specified dimensions (width, height) while maintaining aspect ratio. This reduces file size, memory usage, and processing time, which is beneficial when working with models that have resolution constraints or when transmitting images to remote services. - detail (
Literal['auto', 'high', 'low'] | None) β Optional detail level of the image (only supported by OpenAI). One of "auto", "high", or "low". - meta (
dict[str, Any] | None) β Additional metadata for the image.
Returns:
ImageContentβ An ImageContent object.
Raises:
ValueErrorβ If the URL does not point to an image or if it points to a PDF file.
sparse_embeddingβ
SparseEmbeddingβ
Class representing a sparse embedding.
Parameters:
- indices (
list[int]) β List of indices of non-zero elements in the embedding. - values (
list[float]) β List of values of non-zero elements in the embedding.
to_dictβ
Convert the SparseEmbedding object to a dictionary.
Returns:
dict[str, Any]β Serialized sparse embedding.
from_dictβ
Deserializes the sparse embedding from a dictionary.
Parameters:
- sparse_embedding_dict (
dict[str, Any]) β Dictionary to deserialize from.
Returns:
SparseEmbeddingβ Deserialized sparse embedding.
streaming_chunkβ
ToolCallDeltaβ
Represents a Tool call prepared by the model, usually contained in an assistant message.
Parameters:
- index (
int) β The index of the Tool call in the list of Tool calls. - tool_name (
str | None) β The name of the Tool to call. - arguments (
str | None) β Either the full arguments in JSON format or a delta of the arguments. - id (
str | None) β The ID of the Tool call. - extra (
dict[str, Any] | None) β Dictionary of extra information about the Tool call. Use to store provider-specific information. To avoid serialization issues, values should be JSON serializable.
to_dictβ
Returns a dictionary representation of the ToolCallDelta.
Returns:
dict[str, Any]β A dictionary with keys 'index', 'tool_name', 'arguments', 'id', and 'extra'.
from_dictβ
Creates a ToolCallDelta from a serialized representation.
Parameters:
- data (
dict[str, Any]) β Dictionary containing ToolCallDelta's attributes.
Returns:
ToolCallDeltaβ A ToolCallDelta instance.
ComponentInfoβ
The ComponentInfo class encapsulates information about a component.
Parameters:
- type (
str) β The type of the component. - name (
str | None) β The name of the component assigned when adding it to a pipeline.
from_componentβ
Create a ComponentInfo object from a Component instance.
Parameters:
- component (
Component) β TheComponentinstance.
Returns:
ComponentInfoβ TheComponentInfoobject with the type and name of the given component.
to_dictβ
Returns a dictionary representation of ComponentInfo.
Returns:
dict[str, Any]β A dictionary with keys 'type' and 'name'.
from_dictβ
Creates a ComponentInfo from a serialized representation.
Parameters:
- data (
dict[str, Any]) β Dictionary containing ComponentInfo's attributes.
Returns:
ComponentInfoβ A ComponentInfo instance.
StreamingChunkβ
The StreamingChunk class encapsulates a segment of streamed content along with associated metadata.
This structure facilitates the handling and processing of streamed data in a systematic manner.
Parameters:
- content (
str) β The content of the message chunk as a string. - meta (
dict[str, Any]) β A dictionary containing metadata related to the message chunk. - component_info (
ComponentInfo | None) β AComponentInfoobject containing information about the component that generated the chunk, such as the component name and type. - index (
int | None) β An optional integer index representing which content block this chunk belongs to. - tool_calls (
list[ToolCallDelta] | None) β An optional list of ToolCallDelta object representing a tool call associated with the message chunk. - tool_call_result (
ToolCallResult | None) β An optional ToolCallResult object representing the result of a tool call. - start (
bool) β A boolean indicating whether this chunk marks the start of a content block. - finish_reason (
FinishReason | None) β An optional value indicating the reason the generation finished. Standard values follow OpenAI's convention: "stop", "length", "tool_calls", "content_filter", plus Haystack-specific value "tool_call_results". - reasoning (
ReasoningContent | None) β An optional ReasoningContent object representing the reasoning content associated with the message chunk.
to_dictβ
Returns a dictionary representation of the StreamingChunk.
Returns:
dict[str, Any]β Serialized dictionary representation of the calling object.
from_dictβ
Creates a deserialized StreamingChunk instance from a serialized representation.
Parameters:
- data (
dict[str, Any]) β Dictionary containing the StreamingChunk's attributes.
Returns:
StreamingChunkβ A StreamingChunk instance.
select_streaming_callbackβ
select_streaming_callback(
init_callback: StreamingCallbackT | None,
runtime_callback: StreamingCallbackT | None,
requires_async: bool,
) -> StreamingCallbackT | None
Picks the correct streaming callback given an optional initial and runtime callback.
The runtime callback takes precedence over the initial callback.
Parameters:
- init_callback (
StreamingCallbackT | None) β The initial callback. - runtime_callback (
StreamingCallbackT | None) β The runtime callback. - requires_async (
bool) β Whether the selected callback must be async compatible.
Returns:
StreamingCallbackT | Noneβ The selected callback.