Sync Haystack API reference on Docusaurus (#10275)

Co-authored-by: anakin87 <[email protected]>
This commit is contained in:
Haystack Bot
2025-12-19 15:55:24 +01:00
committed by GitHub
co-authored by anakin87
parent 7c6323b960
commit 2378b2bae1
30 changed files with 680 additions and 702 deletions
@@ -96,14 +96,14 @@ print(result["messages"][-1].text)
```python
def __init__(*,
chat_generator: ChatGenerator,
tools: Optional[ToolsType] = None,
system_prompt: Optional[str] = None,
exit_conditions: Optional[list[str]] = None,
state_schema: Optional[dict[str, Any]] = None,
tools: ToolsType | None = None,
system_prompt: str | None = None,
exit_conditions: list[str] | None = None,
state_schema: dict[str, Any] | None = None,
max_agent_steps: int = 100,
streaming_callback: Optional[StreamingCallbackT] = None,
streaming_callback: StreamingCallbackT | None = None,
raise_on_tool_invocation_failure: bool = False,
tool_invoker_kwargs: Optional[dict[str, Any]] = None) -> None
tool_invoker_kwargs: dict[str, Any] | None = None) -> None
```
Initialize the agent component.
@@ -179,13 +179,13 @@ Deserialized agent
```python
def run(messages: list[ChatMessage],
streaming_callback: Optional[StreamingCallbackT] = None,
streaming_callback: StreamingCallbackT | None = None,
*,
generation_kwargs: Optional[dict[str, Any]] = None,
break_point: Optional[AgentBreakpoint] = None,
snapshot: Optional[AgentSnapshot] = None,
system_prompt: Optional[str] = None,
tools: Optional[Union[ToolsType, list[str]]] = None,
generation_kwargs: dict[str, Any] | None = None,
break_point: AgentBreakpoint | None = None,
snapshot: AgentSnapshot | None = None,
system_prompt: str | None = None,
tools: ToolsType | list[str] | None = None,
**kwargs: Any) -> dict[str, Any]
```
@@ -225,13 +225,13 @@ A dictionary with the following keys:
```python
async def run_async(messages: list[ChatMessage],
streaming_callback: Optional[StreamingCallbackT] = None,
streaming_callback: StreamingCallbackT | None = None,
*,
generation_kwargs: Optional[dict[str, Any]] = None,
break_point: Optional[AgentBreakpoint] = None,
snapshot: Optional[AgentSnapshot] = None,
system_prompt: Optional[str] = None,
tools: Optional[Union[ToolsType, list[str]]] = None,
generation_kwargs: dict[str, Any] | None = None,
break_point: AgentBreakpoint | None = None,
snapshot: AgentSnapshot | None = None,
system_prompt: str | None = None,
tools: ToolsType | list[str] | None = None,
**kwargs: Any) -> dict[str, Any]
```
@@ -311,7 +311,7 @@ my_state = State(
#### State.\_\_init\_\_
```python
def __init__(schema: dict[str, Any], data: Optional[dict[str, Any]] = None)
def __init__(schema: dict[str, Any], data: dict[str, Any] | None = None)
```
Initialize a State object with a schema and optional data.
@@ -351,7 +351,7 @@ Value associated with key or default if not found
```python
def set(key: str,
value: Any,
handler_override: Optional[Callable[[Any, Any], Any]] = None) -> None
handler_override: Callable[[Any, Any], Any] | None = None) -> None
```
Set or merge a value in the state according to schema rules.
@@ -35,8 +35,8 @@ transcription = whisper.run(sources=["test/test_files/audio/answer.wav"])
```python
def __init__(model: WhisperLocalModel = "large",
device: Optional[ComponentDevice] = None,
whisper_params: Optional[dict[str, Any]] = None)
device: ComponentDevice | None = None,
whisper_params: dict[str, Any] | None = None)
```
Creates an instance of the LocalWhisperTranscriber component.
@@ -98,8 +98,8 @@ The deserialized component.
```python
@component.output_types(documents=list[Document])
def run(sources: list[Union[str, Path, ByteStream]],
whisper_params: Optional[dict[str, Any]] = None)
def run(sources: list[str | Path | ByteStream],
whisper_params: dict[str, Any] | None = None)
```
Transcribes a list of audio files into a list of documents.
@@ -124,7 +124,7 @@ for the transcription.
#### LocalWhisperTranscriber.transcribe
```python
def transcribe(sources: list[Union[str, Path, ByteStream]],
def transcribe(sources: list[str | Path | ByteStream],
**kwargs) -> list[Document]
```
@@ -173,9 +173,9 @@ transcription = whisper.run(sources=["test/test_files/audio/answer.wav"])
```python
def __init__(api_key: Secret = Secret.from_env_var("OPENAI_API_KEY"),
model: str = "whisper-1",
api_base_url: Optional[str] = None,
organization: Optional[str] = None,
http_client_kwargs: Optional[dict[str, Any]] = None,
api_base_url: str | None = None,
organization: str | None = None,
http_client_kwargs: dict[str, Any] | None = None,
**kwargs)
```
@@ -250,7 +250,7 @@ The deserialized component.
```python
@component.output_types(documents=list[Document])
def run(sources: list[Union[str, Path, ByteStream]])
def run(sources: list[str | Path | ByteStream])
```
Transcribes the list of audio files into a list of documents.
@@ -69,8 +69,8 @@ for doc in result.documents:
#### AnswerBuilder.\_\_init\_\_
```python
def __init__(pattern: Optional[str] = None,
reference_pattern: Optional[str] = None,
def __init__(pattern: str | None = None,
reference_pattern: str | None = None,
last_message_only: bool = False,
*,
return_only_referenced_documents: bool = True)
@@ -107,11 +107,11 @@ If `reference_pattern` is not provided, this parameter has no effect, and all do
```python
@component.output_types(answers=list[GeneratedAnswer])
def run(query: str,
replies: Union[list[str], list[ChatMessage]],
meta: Optional[list[dict[str, Any]]] = None,
documents: Optional[list[Document]] = None,
pattern: Optional[str] = None,
reference_pattern: Optional[str] = None)
replies: list[str] | list[ChatMessage],
meta: list[dict[str, Any]] | None = None,
documents: list[Document] | None = None,
pattern: str | None = None,
reference_pattern: str | None = None)
```
Turns the output of a Generator into `GeneratedAnswer` objects using regular expressions.
@@ -264,10 +264,9 @@ builder.run(user_name="John", images=images)
#### ChatPromptBuilder.\_\_init\_\_
```python
def __init__(template: Optional[Union[list[ChatMessage], str]] = None,
required_variables: Optional[Union[list[str],
Literal["*"]]] = None,
variables: Optional[list[str]] = None)
def __init__(template: list[ChatMessage] | str | None = None,
required_variables: list[str] | Literal["*"] | None = None,
variables: list[str] | None = None)
```
Constructs a ChatPromptBuilder component.
@@ -290,8 +289,8 @@ in the default template, you can provide them here.
```python
@component.output_types(prompt=list[ChatMessage])
def run(template: Optional[Union[list[ChatMessage], str]] = None,
template_variables: Optional[dict[str, Any]] = None,
def run(template: list[ChatMessage] | str | None = None,
template_variables: dict[str, Any] | None = None,
**kwargs)
```
@@ -484,9 +483,8 @@ Use `template_variables` to overwrite pipeline variables (such as documents) as
```python
def __init__(template: str,
required_variables: Optional[Union[list[str],
Literal["*"]]] = None,
variables: Optional[list[str]] = None)
required_variables: list[str] | Literal["*"] | None = None,
variables: list[str] | None = None)
```
Constructs a PromptBuilder component.
@@ -526,8 +524,8 @@ Serialized dictionary representation of the component.
```python
@component.output_types(prompt=str)
def run(template: Optional[str] = None,
template_variables: Optional[dict[str, Any]] = None,
def run(template: str | None = None,
template_variables: dict[str, Any] | None = None,
**kwargs)
```
@@ -61,7 +61,7 @@ assert written_docs[0] == Document(id="1", content="This is an English document"
#### DocumentLanguageClassifier.\_\_init\_\_
```python
def __init__(languages: Optional[list[str]] = None)
def __init__(languages: list[str] | None = None)
```
Initializes the DocumentLanguageClassifier component.
@@ -168,11 +168,11 @@ for idx, query in enumerate(queries):
def __init__(model: str,
labels: list[str],
multi_label: bool = False,
classification_field: Optional[str] = None,
device: Optional[ComponentDevice] = None,
token: Optional[Secret] = Secret.from_env_var(
classification_field: str | None = None,
device: ComponentDevice | None = None,
token: Secret | None = Secret.from_env_var(
["HF_API_TOKEN", "HF_TOKEN"], strict=False),
huggingface_pipeline_kwargs: Optional[dict[str, Any]] = None)
huggingface_pipeline_kwargs: dict[str, Any] | None = None)
```
Initializes the TransformersZeroShotDocumentClassifier.
@@ -49,8 +49,8 @@ response = connector.run(
```python
def __init__(openapi_spec: str,
credentials: Optional[Secret] = None,
service_kwargs: Optional[dict[str, Any]] = None)
credentials: Secret | None = None,
service_kwargs: dict[str, Any] | None = None)
```
Initialize the OpenAPIConnector with a specification and optional credentials.
@@ -90,7 +90,7 @@ Deserialize this component from a dictionary.
```python
@component.output_types(response=dict[str, Any])
def run(operation_id: str,
arguments: Optional[dict[str, Any]] = None) -> dict[str, Any]
arguments: dict[str, Any] | None = None) -> dict[str, Any]
```
Invokes a REST endpoint specified in the OpenAPI specification.
@@ -165,7 +165,7 @@ print(result)
#### OpenAPIServiceConnector.\_\_init\_\_
```python
def __init__(ssl_verify: Optional[Union[bool, str]] = None)
def __init__(ssl_verify: bool | str | None = None)
```
Initializes the OpenAPIServiceConnector instance
@@ -184,7 +184,7 @@ in case a string is passed, will be used as the CA.
def run(
messages: list[ChatMessage],
service_openapi_spec: dict[str, Any],
service_credentials: Optional[Union[dict, str]] = None
service_credentials: dict | str | None = None
) -> dict[str, list[ChatMessage]]
```
@@ -54,7 +54,7 @@ def __init__(endpoint: str,
following_context_len: int = 3,
merge_multiple_column_headers: bool = True,
page_layout: Literal["natural", "single_column"] = "natural",
threshold_y: Optional[float] = 0.05,
threshold_y: float | None = 0.05,
store_full_path: bool = False)
```
@@ -89,8 +89,8 @@ If False, only the file name is stored.
```python
@component.output_types(documents=list[Document],
raw_azure_response=list[dict])
def run(sources: list[Union[str, Path, ByteStream]],
meta: Optional[Union[dict[str, Any], list[dict[str, Any]]]] = None)
def run(sources: list[str | Path | ByteStream],
meta: dict[str, Any] | list[dict[str, Any]] | None = None)
```
Convert a list of files to Documents using Azure's Document Intelligence service.
@@ -201,10 +201,10 @@ If False, only the file name is stored.
```python
@component.output_types(documents=list[Document])
def run(sources: list[Union[str, Path, ByteStream]],
def run(sources: list[str | Path | ByteStream],
*,
content_column: Optional[str] = None,
meta: Optional[Union[dict[str, Any], list[dict[str, Any]]]] = None)
content_column: str | None = None,
meta: dict[str, Any] | list[dict[str, Any]] | None = None)
```
Converts CSV files to a Document (file mode) or to one Document per row (row mode).
@@ -314,8 +314,8 @@ print(documents[0].content)
#### DOCXToDocument.\_\_init\_\_
```python
def __init__(table_format: Union[str, DOCXTableFormat] = DOCXTableFormat.CSV,
link_format: Union[str, DOCXLinkFormat] = DOCXLinkFormat.NONE,
def __init__(table_format: str | DOCXTableFormat = DOCXTableFormat.CSV,
link_format: str | DOCXLinkFormat = DOCXLinkFormat.NONE,
store_full_path: bool = False)
```
@@ -371,8 +371,8 @@ The deserialized component.
```python
@component.output_types(documents=list[Document])
def run(sources: list[Union[str, Path, ByteStream]],
meta: Optional[Union[dict[str, Any], list[dict[str, Any]]]] = None)
def run(sources: list[str | Path | ByteStream],
meta: dict[str, Any] | list[dict[str, Any]] | None = None)
```
Converts DOCX files to Documents.
@@ -418,7 +418,7 @@ print(documents[0].content)
#### HTMLToDocument.\_\_init\_\_
```python
def __init__(extraction_kwargs: Optional[dict[str, Any]] = None,
def __init__(extraction_kwargs: dict[str, Any] | None = None,
store_full_path: bool = False)
```
@@ -471,9 +471,9 @@ The deserialized component.
```python
@component.output_types(documents=list[Document])
def run(sources: list[Union[str, Path, ByteStream]],
meta: Optional[Union[dict[str, Any], list[dict[str, Any]]]] = None,
extraction_kwargs: Optional[dict[str, Any]] = None)
def run(sources: list[str | Path | ByteStream],
meta: dict[str, Any] | list[dict[str, Any]] | None = None,
extraction_kwargs: dict[str, Any] | None = None)
```
Converts a list of HTML files to Documents.
@@ -573,9 +573,9 @@ print(documents[1].meta)
#### JSONConverter.\_\_init\_\_
```python
def __init__(jq_schema: Optional[str] = None,
content_key: Optional[str] = None,
extra_meta_fields: Optional[Union[set[str], Literal["*"]]] = None,
def __init__(jq_schema: str | None = None,
content_key: str | None = None,
extra_meta_fields: set[str] | Literal["*"] | None = None,
store_full_path: bool = False)
```
@@ -654,8 +654,8 @@ Deserialized component.
```python
@component.output_types(documents=list[Document])
def run(sources: list[Union[str, Path, ByteStream]],
meta: Optional[Union[dict[str, Any], list[dict[str, Any]]]] = None)
def run(sources: list[str | Path | ByteStream],
meta: dict[str, Any] | list[dict[str, Any]] | None = None)
```
Converts a list of JSON files to documents.
@@ -721,8 +721,8 @@ If False, only the file name is stored.
```python
@component.output_types(documents=list[Document])
def run(sources: list[Union[str, Path, ByteStream]],
meta: Optional[Union[dict[str, Any], list[dict[str, Any]]]] = None)
def run(sources: list[str | Path | ByteStream],
meta: dict[str, Any] | list[dict[str, Any]] | None = None)
```
Converts a list of Markdown files to Documents.
@@ -791,9 +791,9 @@ If False, only the file name is stored.
```python
@component.output_types(documents=list[Document], attachments=list[ByteStream])
def run(
sources: list[Union[str, Path, ByteStream]],
meta: Optional[Union[dict[str, Any], list[dict[str, Any]]]] = None
) -> dict[str, Union[list[Document], list[ByteStream]]]
sources: list[str | Path | ByteStream],
meta: dict[str, Any] | list[dict[str, Any]] | None = None
) -> dict[str, list[Document] | list[ByteStream]]
```
Converts MSG files to Documents.
@@ -905,7 +905,7 @@ Create an OpenAPIServiceToFunctions component.
```python
@component.output_types(functions=list[dict[str, Any]],
openapi_specs=list[dict[str, Any]])
def run(sources: list[Union[str, Path, ByteStream]]) -> dict[str, Any]
def run(sources: list[str | Path | ByteStream]) -> dict[str, Any]
```
Converts OpenAPI definitions in OpenAI function calling format.
@@ -960,7 +960,7 @@ assert result["output"] == "Test content"
```python
def __init__(template: str,
output_type: TypeAlias,
custom_filters: Optional[dict[str, Callable]] = None,
custom_filters: dict[str, Callable] | None = None,
unsafe: bool = False) -> None
```
@@ -1075,7 +1075,7 @@ def __init__(line_overlap: float = 0.5,
char_margin: float = 2.0,
line_margin: float = 0.5,
word_margin: float = 0.1,
boxes_flow: Optional[float] = 0.5,
boxes_flow: float | None = 0.5,
detect_vertical: bool = True,
all_texts: bool = False,
store_full_path: bool = False) -> None
@@ -1140,8 +1140,8 @@ see: https://pdfminersix.readthedocs.io/en/latest/faq.html#why-are-there-cid-x-v
```python
@component.output_types(documents=list[Document])
def run(sources: list[Union[str, Path, ByteStream]],
meta: Optional[Union[dict[str, Any], list[dict[str, Any]]]] = None)
def run(sources: list[str | Path | ByteStream],
meta: dict[str, Any] | list[dict[str, Any]] | None = None)
```
Converts PDF files to Documents.
@@ -1203,8 +1203,8 @@ If False, only the file name is stored.
```python
@component.output_types(documents=list[Document])
def run(sources: list[Union[str, Path, ByteStream]],
meta: Optional[Union[dict[str, Any], list[dict[str, Any]]]] = None)
def run(sources: list[str | Path | ByteStream],
meta: dict[str, Any] | list[dict[str, Any]] | None = None)
```
Converts PPTX files to Documents.
@@ -1282,8 +1282,8 @@ print(documents[0].content)
```python
def __init__(*,
extraction_mode: Union[
str, PyPDFExtractionMode] = PyPDFExtractionMode.PLAIN,
extraction_mode: str
| PyPDFExtractionMode = PyPDFExtractionMode.PLAIN,
plain_mode_orientations: tuple = (0, 90, 180, 270),
plain_mode_space_width: float = 200.0,
layout_mode_space_vertically: bool = True,
@@ -1354,8 +1354,8 @@ Deserialized component.
```python
@component.output_types(documents=list[Document])
def run(sources: list[Union[str, Path, ByteStream]],
meta: Optional[Union[dict[str, Any], list[dict[str, Any]]]] = None)
def run(sources: list[str | Path | ByteStream],
meta: dict[str, Any] | list[dict[str, Any]] | None = None)
```
Converts PDF files to documents.
@@ -1462,8 +1462,8 @@ If False, only the file name is stored.
```python
@component.output_types(documents=list[Document])
def run(sources: list[Union[str, Path, ByteStream]],
meta: Optional[Union[dict[str, Any], list[dict[str, Any]]]] = None)
def run(sources: list[str | Path | ByteStream],
meta: dict[str, Any] | list[dict[str, Any]] | None = None)
```
Converts files to Documents.
@@ -1533,8 +1533,8 @@ If False, only the file name is stored.
```python
@component.output_types(documents=list[Document])
def run(sources: list[Union[str, Path, ByteStream]],
meta: Optional[Union[dict[str, Any], list[dict[str, Any]]]] = None)
def run(sources: list[str | Path | ByteStream],
meta: dict[str, Any] | list[dict[str, Any]] | None = None)
```
Converts text files to documents.
@@ -1587,9 +1587,9 @@ Converts XLSX (Excel) files into Documents.
```python
def __init__(table_format: Literal["csv", "markdown"] = "csv",
sheet_name: Union[str, int, list[Union[str, int]], None] = None,
read_excel_kwargs: Optional[dict[str, Any]] = None,
table_format_kwargs: Optional[dict[str, Any]] = None,
sheet_name: str | int | list[str | int] | None = None,
read_excel_kwargs: dict[str, Any] | None = None,
table_format_kwargs: dict[str, Any] | None = None,
*,
store_full_path: bool = False)
```
@@ -1617,8 +1617,8 @@ If False, only the file name is stored.
```python
@component.output_types(documents=list[Document])
def run(
sources: list[Union[str, Path, ByteStream]],
meta: Optional[Union[dict[str, Any], list[dict[str, Any]]]] = None
sources: list[str | Path | ByteStream],
meta: dict[str, Any] | list[dict[str, Any]] | None = None
) -> dict[str, list[Document]]
```
@@ -121,8 +121,8 @@ Write the ByteStream to a file. Note: the metadata will be lost.
@classmethod
def from_file_path(cls,
filepath: Path,
mime_type: Optional[str] = None,
meta: Optional[dict[str, Any]] = None,
mime_type: str | None = None,
meta: dict[str, Any] | None = None,
guess_mime_type: bool = False) -> "ByteStream"
```
@@ -144,8 +144,8 @@ Create a ByteStream from the contents read from a file.
def from_string(cls,
text: str,
encoding: str = "utf-8",
mime_type: Optional[str] = None,
meta: Optional[dict[str, Any]] = None) -> "ByteStream"
mime_type: str | None = None,
meta: dict[str, Any] | None = None) -> "ByteStream"
```
Create a ByteStream encoding a string.
@@ -497,7 +497,7 @@ Returns the metadata associated with the message.
```python
@property
def name() -> Optional[str]
def name() -> str | None
```
Returns the name associated with the message.
@@ -519,7 +519,7 @@ Returns the list of all texts contained in the message.
```python
@property
def text() -> Optional[str]
def text() -> str | None
```
Returns the first text contained in the message.
@@ -541,7 +541,7 @@ Returns the list of all Tool calls contained in the message.
```python
@property
def tool_call() -> Optional[ToolCall]
def tool_call() -> ToolCall | None
```
Returns the first Tool call contained in the message.
@@ -563,7 +563,7 @@ Returns the list of all Tool call results contained in the message.
```python
@property
def tool_call_result() -> Optional[ToolCallResult]
def tool_call_result() -> ToolCallResult | None
```
Returns the first Tool call result contained in the message.
@@ -585,7 +585,7 @@ Returns the list of all images contained in the message.
```python
@property
def image() -> Optional[ImageContent]
def image() -> ImageContent | None
```
Returns the first image contained in the message.
@@ -607,7 +607,7 @@ Returns the list of all reasoning contents contained in the message.
```python
@property
def reasoning() -> Optional[ReasoningContent]
def reasoning() -> ReasoningContent | None
```
Returns the first reasoning content contained in the message.
@@ -617,7 +617,7 @@ Returns the first reasoning content contained in the message.
#### ChatMessage.is\_from
```python
def is_from(role: Union[ChatRole, str]) -> bool
def is_from(role: ChatRole | str) -> bool
```
Check if the message is from a specific role.
@@ -638,12 +638,11 @@ True if the message is from the specified role, False otherwise.
@classmethod
def from_user(
cls,
text: Optional[str] = None,
meta: Optional[dict[str, Any]] = None,
name: Optional[str] = None,
text: str | None = None,
meta: dict[str, Any] | None = None,
name: str | None = None,
*,
content_parts: Optional[Sequence[Union[TextContent, str,
ImageContent]]] = None
content_parts: Sequence[TextContent | str | ImageContent] | None = None
) -> "ChatMessage"
```
@@ -668,8 +667,8 @@ A new ChatMessage instance.
@classmethod
def from_system(cls,
text: str,
meta: Optional[dict[str, Any]] = None,
name: Optional[str] = None) -> "ChatMessage"
meta: dict[str, Any] | None = None,
name: str | None = None) -> "ChatMessage"
```
Create a message from the system.
@@ -692,13 +691,12 @@ A new ChatMessage instance.
@classmethod
def from_assistant(
cls,
text: Optional[str] = None,
meta: Optional[dict[str, Any]] = None,
name: Optional[str] = None,
tool_calls: Optional[list[ToolCall]] = None,
text: str | None = None,
meta: dict[str, Any] | None = None,
name: str | None = None,
tool_calls: list[ToolCall] | None = None,
*,
reasoning: Optional[Union[str,
ReasoningContent]] = None) -> "ChatMessage"
reasoning: str | ReasoningContent | None = None) -> "ChatMessage"
```
Create a message from the assistant.
@@ -725,7 +723,7 @@ def from_tool(cls,
tool_result: str,
origin: ToolCall,
error: bool = False,
meta: Optional[dict[str, Any]] = None) -> "ChatMessage"
meta: dict[str, Any] | None = None) -> "ChatMessage"
```
Create a message from a Tool.
@@ -1005,11 +1003,11 @@ Create an ImageContent from a dictionary.
```python
@classmethod
def from_file_path(cls,
file_path: Union[str, Path],
file_path: str | Path,
*,
size: Optional[tuple[int, int]] = None,
detail: Optional[Literal["auto", "high", "low"]] = None,
meta: Optional[dict[str, Any]] = None) -> "ImageContent"
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.
@@ -1042,9 +1040,9 @@ def from_url(cls,
*,
retry_attempts: int = 2,
timeout: int = 10,
size: Optional[tuple[int, int]] = None,
detail: Optional[Literal["auto", "high", "low"]] = None,
meta: Optional[dict[str, Any]] = None) -> "ImageContent"
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.
@@ -1310,9 +1308,9 @@ A StreamingChunk instance.
```python
def select_streaming_callback(
init_callback: Optional[StreamingCallbackT],
runtime_callback: Optional[StreamingCallbackT],
requires_async: bool) -> Optional[StreamingCallbackT]
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.
@@ -34,11 +34,11 @@ Stores data in-memory. It's ephemeral and cannot be saved to disk.
def __init__(bm25_tokenization_regex: str = r"(?u)\b\w\w+\b",
bm25_algorithm: Literal["BM25Okapi", "BM25L",
"BM25Plus"] = "BM25L",
bm25_parameters: Optional[dict] = None,
bm25_parameters: dict | None = None,
embedding_similarity_function: Literal["dot_product",
"cosine"] = "dot_product",
index: Optional[str] = None,
async_executor: Optional[ThreadPoolExecutor] = None,
index: str | None = None,
async_executor: ThreadPoolExecutor | None = None,
return_embedding: bool = True)
```
@@ -172,8 +172,7 @@ Returns the number of how many documents are present in the DocumentStore.
#### InMemoryDocumentStore.filter\_documents
```python
def filter_documents(
filters: Optional[dict[str, Any]] = None) -> list[Document]
def filter_documents(filters: dict[str, Any] | None = None) -> list[Document]
```
Returns the documents that match the filters provided.
@@ -222,7 +221,7 @@ Deletes all documents with matching document_ids from the DocumentStore.
```python
def bm25_retrieval(query: str,
filters: Optional[dict[str, Any]] = None,
filters: dict[str, Any] | None = None,
top_k: int = 10,
scale_score: bool = False) -> list[Document]
```
@@ -247,10 +246,10 @@ A list of the top_k documents most relevant to the query.
```python
def embedding_retrieval(
query_embedding: list[float],
filters: Optional[dict[str, Any]] = None,
filters: dict[str, Any] | None = None,
top_k: int = 10,
scale_score: bool = False,
return_embedding: Optional[bool] = False) -> list[Document]
return_embedding: bool | None = False) -> list[Document]
```
Retrieves documents that are most similar to the query embedding using a vector similarity metric.
@@ -285,7 +284,7 @@ Returns the number of how many documents are present in the DocumentStore.
```python
async def filter_documents_async(
filters: Optional[dict[str, Any]] = None) -> list[Document]
filters: dict[str, Any] | None = None) -> list[Document]
```
Returns the documents that match the filters provided.
@@ -335,7 +334,7 @@ Deletes all documents with matching document_ids from the DocumentStore.
```python
async def bm25_retrieval_async(query: str,
filters: Optional[dict[str, Any]] = None,
filters: dict[str, Any] | None = None,
top_k: int = 10,
scale_score: bool = False) -> list[Document]
```
@@ -360,7 +359,7 @@ A list of the top_k documents most relevant to the query.
```python
async def embedding_retrieval_async(
query_embedding: list[float],
filters: Optional[dict[str, Any]] = None,
filters: dict[str, Any] | None = None,
top_k: int = 10,
scale_score: bool = False,
return_embedding: bool = False) -> list[Document]
@@ -91,7 +91,7 @@ The deserialized component.
```python
@component.output_types(documents_written=int)
def run(documents: list[Document], policy: Optional[DuplicatePolicy] = None)
def run(documents: list[Document], policy: DuplicatePolicy | None = None)
```
Run the DocumentWriter on the given input data.
@@ -116,7 +116,7 @@ Number of documents written to the document store.
```python
@component.output_types(documents_written=int)
async def run_async(documents: list[Document],
policy: Optional[DuplicatePolicy] = None)
policy: DuplicatePolicy | None = None)
```
Asynchronously run the DocumentWriter on the given input data.
@@ -36,27 +36,27 @@ print(result['documents'][0].embedding)
#### AzureOpenAIDocumentEmbedder.\_\_init\_\_
```python
def __init__(azure_endpoint: Optional[str] = None,
api_version: Optional[str] = "2023-05-15",
def __init__(azure_endpoint: str | None = None,
api_version: str | None = "2023-05-15",
azure_deployment: str = "text-embedding-ada-002",
dimensions: Optional[int] = None,
api_key: Optional[Secret] = Secret.from_env_var(
dimensions: int | None = None,
api_key: Secret | None = Secret.from_env_var(
"AZURE_OPENAI_API_KEY", strict=False),
azure_ad_token: Optional[Secret] = Secret.from_env_var(
azure_ad_token: Secret | None = Secret.from_env_var(
"AZURE_OPENAI_AD_TOKEN", strict=False),
organization: Optional[str] = None,
organization: str | None = None,
prefix: str = "",
suffix: str = "",
batch_size: int = 32,
progress_bar: bool = True,
meta_fields_to_embed: Optional[list[str]] = None,
meta_fields_to_embed: list[str] | None = None,
embedding_separator: str = "\n",
timeout: Optional[float] = None,
max_retries: Optional[int] = None,
timeout: float | None = None,
max_retries: int | None = None,
*,
default_headers: Optional[dict[str, str]] = None,
azure_ad_token_provider: Optional[AzureADTokenProvider] = None,
http_client_kwargs: Optional[dict[str, Any]] = None,
default_headers: dict[str, str] | None = None,
azure_ad_token_provider: AzureADTokenProvider | None = None,
http_client_kwargs: dict[str, Any] | None = None,
raise_on_failure: bool = False)
```
@@ -205,23 +205,23 @@ print(text_embedder.run(text_to_embed))
#### AzureOpenAITextEmbedder.\_\_init\_\_
```python
def __init__(azure_endpoint: Optional[str] = None,
api_version: Optional[str] = "2023-05-15",
def __init__(azure_endpoint: str | None = None,
api_version: str | None = "2023-05-15",
azure_deployment: str = "text-embedding-ada-002",
dimensions: Optional[int] = None,
api_key: Optional[Secret] = Secret.from_env_var(
dimensions: int | None = None,
api_key: Secret | None = Secret.from_env_var(
"AZURE_OPENAI_API_KEY", strict=False),
azure_ad_token: Optional[Secret] = Secret.from_env_var(
azure_ad_token: Secret | None = Secret.from_env_var(
"AZURE_OPENAI_AD_TOKEN", strict=False),
organization: Optional[str] = None,
timeout: Optional[float] = None,
max_retries: Optional[int] = None,
organization: str | None = None,
timeout: float | None = None,
max_retries: int | None = None,
prefix: str = "",
suffix: str = "",
*,
default_headers: Optional[dict[str, str]] = None,
azure_ad_token_provider: Optional[AzureADTokenProvider] = None,
http_client_kwargs: Optional[dict[str, Any]] = None)
default_headers: dict[str, str] | None = None,
azure_ad_token_provider: AzureADTokenProvider | None = None,
http_client_kwargs: dict[str, Any] | None = None)
```
Creates an AzureOpenAITextEmbedder component.
@@ -413,17 +413,17 @@ print(result["documents"][0].embedding)
#### HuggingFaceAPIDocumentEmbedder.\_\_init\_\_
```python
def __init__(api_type: Union[HFEmbeddingAPIType, str],
def __init__(api_type: HFEmbeddingAPIType | str,
api_params: dict[str, str],
token: Optional[Secret] = Secret.from_env_var(
token: Secret | None = Secret.from_env_var(
["HF_API_TOKEN", "HF_TOKEN"], strict=False),
prefix: str = "",
suffix: str = "",
truncate: Optional[bool] = True,
normalize: Optional[bool] = False,
truncate: bool | None = True,
normalize: bool | None = False,
batch_size: int = 32,
progress_bar: bool = True,
meta_fields_to_embed: Optional[list[str]] = None,
meta_fields_to_embed: list[str] | None = None,
embedding_separator: str = "\n")
```
@@ -591,14 +591,14 @@ print(text_embedder.run("I love pizza!"))
#### HuggingFaceAPITextEmbedder.\_\_init\_\_
```python
def __init__(api_type: Union[HFEmbeddingAPIType, str],
def __init__(api_type: HFEmbeddingAPIType | str,
api_params: dict[str, str],
token: Optional[Secret] = Secret.from_env_var(
token: Secret | None = Secret.from_env_var(
["HF_API_TOKEN", "HF_TOKEN"], strict=False),
prefix: str = "",
suffix: str = "",
truncate: Optional[bool] = True,
normalize: Optional[bool] = False)
truncate: bool | None = True,
normalize: bool | None = False)
```
Creates a HuggingFaceAPITextEmbedder component.
@@ -740,22 +740,22 @@ print(documents_with_embeddings)
```python
def __init__(*,
file_path_meta_field: str = "file_path",
root_path: Optional[str] = None,
root_path: str | None = None,
model: str = "sentence-transformers/clip-ViT-B-32",
device: Optional[ComponentDevice] = None,
token: Optional[Secret] = Secret.from_env_var(
device: ComponentDevice | None = None,
token: Secret | None = Secret.from_env_var(
["HF_API_TOKEN", "HF_TOKEN"], strict=False),
batch_size: int = 32,
progress_bar: bool = True,
normalize_embeddings: bool = False,
trust_remote_code: bool = False,
local_files_only: bool = False,
model_kwargs: Optional[dict[str, Any]] = None,
tokenizer_kwargs: Optional[dict[str, Any]] = None,
config_kwargs: Optional[dict[str, Any]] = None,
model_kwargs: dict[str, Any] | None = None,
tokenizer_kwargs: dict[str, Any] | None = None,
config_kwargs: dict[str, Any] | None = None,
precision: Literal["float32", "int8", "uint8", "binary",
"ubinary"] = "float32",
encode_kwargs: Optional[dict[str, Any]] = None,
encode_kwargs: dict[str, Any] | None = None,
backend: Literal["torch", "onnx", "openvino"] = "torch") -> None
```
@@ -899,18 +899,18 @@ print(result['documents'][0].embedding)
```python
def __init__(api_key: Secret = Secret.from_env_var("OPENAI_API_KEY"),
model: str = "text-embedding-ada-002",
dimensions: Optional[int] = None,
api_base_url: Optional[str] = None,
organization: Optional[str] = None,
dimensions: int | None = None,
api_base_url: str | None = None,
organization: str | None = None,
prefix: str = "",
suffix: str = "",
batch_size: int = 32,
progress_bar: bool = True,
meta_fields_to_embed: Optional[list[str]] = None,
meta_fields_to_embed: list[str] | None = None,
embedding_separator: str = "\n",
timeout: Optional[float] = None,
max_retries: Optional[int] = None,
http_client_kwargs: Optional[dict[str, Any]] = None,
timeout: float | None = None,
max_retries: int | None = None,
http_client_kwargs: dict[str, Any] | None = None,
*,
raise_on_failure: bool = False)
```
@@ -1059,14 +1059,14 @@ print(text_embedder.run(text_to_embed))
```python
def __init__(api_key: Secret = Secret.from_env_var("OPENAI_API_KEY"),
model: str = "text-embedding-ada-002",
dimensions: Optional[int] = None,
api_base_url: Optional[str] = None,
organization: Optional[str] = None,
dimensions: int | None = None,
api_base_url: str | None = None,
organization: str | None = None,
prefix: str = "",
suffix: str = "",
timeout: Optional[float] = None,
max_retries: Optional[int] = None,
http_client_kwargs: Optional[dict[str, Any]] = None)
timeout: float | None = None,
max_retries: int | None = None,
http_client_kwargs: dict[str, Any] | None = None)
```
Creates an OpenAITextEmbedder component.
@@ -1211,27 +1211,27 @@ print(result['documents'][0].embedding)
```python
def __init__(model: str = "sentence-transformers/all-mpnet-base-v2",
device: Optional[ComponentDevice] = None,
token: Optional[Secret] = Secret.from_env_var(
device: ComponentDevice | None = None,
token: Secret | None = Secret.from_env_var(
["HF_API_TOKEN", "HF_TOKEN"], strict=False),
prefix: str = "",
suffix: str = "",
batch_size: int = 32,
progress_bar: bool = True,
normalize_embeddings: bool = False,
meta_fields_to_embed: Optional[list[str]] = None,
meta_fields_to_embed: list[str] | None = None,
embedding_separator: str = "\n",
trust_remote_code: bool = False,
local_files_only: bool = False,
truncate_dim: Optional[int] = None,
model_kwargs: Optional[dict[str, Any]] = None,
tokenizer_kwargs: Optional[dict[str, Any]] = None,
config_kwargs: Optional[dict[str, Any]] = None,
truncate_dim: int | None = None,
model_kwargs: dict[str, Any] | None = None,
tokenizer_kwargs: dict[str, Any] | None = None,
config_kwargs: dict[str, Any] | None = None,
precision: Literal["float32", "int8", "uint8", "binary",
"ubinary"] = "float32",
encode_kwargs: Optional[dict[str, Any]] = None,
encode_kwargs: dict[str, Any] | None = None,
backend: Literal["torch", "onnx", "openvino"] = "torch",
revision: Optional[str] = None)
revision: str | None = None)
```
Creates a SentenceTransformersDocumentEmbedder component.
@@ -1378,22 +1378,22 @@ print(result['documents'][0].sparse_embedding)
```python
def __init__(*,
model: str = "prithivida/Splade_PP_en_v2",
device: Optional[ComponentDevice] = None,
token: Optional[Secret] = Secret.from_env_var(
device: ComponentDevice | None = None,
token: Secret | None = Secret.from_env_var(
["HF_API_TOKEN", "HF_TOKEN"], strict=False),
prefix: str = "",
suffix: str = "",
batch_size: int = 32,
progress_bar: bool = True,
meta_fields_to_embed: Optional[list[str]] = None,
meta_fields_to_embed: list[str] | None = None,
embedding_separator: str = "\n",
trust_remote_code: bool = False,
local_files_only: bool = False,
model_kwargs: Optional[dict[str, Any]] = None,
tokenizer_kwargs: Optional[dict[str, Any]] = None,
config_kwargs: Optional[dict[str, Any]] = None,
model_kwargs: dict[str, Any] | None = None,
tokenizer_kwargs: dict[str, Any] | None = None,
config_kwargs: dict[str, Any] | None = None,
backend: Literal["torch", "onnx", "openvino"] = "torch",
revision: Optional[str] = None)
revision: str | None = None)
```
Creates a SentenceTransformersSparseDocumentEmbedder component.
@@ -1523,19 +1523,19 @@ print(text_embedder.run(text_to_embed))
```python
def __init__(*,
model: str = "prithivida/Splade_PP_en_v2",
device: Optional[ComponentDevice] = None,
token: Optional[Secret] = Secret.from_env_var(
device: ComponentDevice | None = None,
token: Secret | None = Secret.from_env_var(
["HF_API_TOKEN", "HF_TOKEN"], strict=False),
prefix: str = "",
suffix: str = "",
trust_remote_code: bool = False,
local_files_only: bool = False,
model_kwargs: Optional[dict[str, Any]] = None,
tokenizer_kwargs: Optional[dict[str, Any]] = None,
config_kwargs: Optional[dict[str, Any]] = None,
encode_kwargs: Optional[dict[str, Any]] = None,
model_kwargs: dict[str, Any] | None = None,
tokenizer_kwargs: dict[str, Any] | None = None,
config_kwargs: dict[str, Any] | None = None,
encode_kwargs: dict[str, Any] | None = None,
backend: Literal["torch", "onnx", "openvino"] = "torch",
revision: Optional[str] = None)
revision: str | None = None)
```
Create a SentenceTransformersSparseTextEmbedder component.
@@ -1658,8 +1658,8 @@ print(text_embedder.run(text_to_embed))
```python
def __init__(model: str = "sentence-transformers/all-mpnet-base-v2",
device: Optional[ComponentDevice] = None,
token: Optional[Secret] = Secret.from_env_var(
device: ComponentDevice | None = None,
token: Secret | None = Secret.from_env_var(
["HF_API_TOKEN", "HF_TOKEN"], strict=False),
prefix: str = "",
suffix: str = "",
@@ -1668,15 +1668,15 @@ def __init__(model: str = "sentence-transformers/all-mpnet-base-v2",
normalize_embeddings: bool = False,
trust_remote_code: bool = False,
local_files_only: bool = False,
truncate_dim: Optional[int] = None,
model_kwargs: Optional[dict[str, Any]] = None,
tokenizer_kwargs: Optional[dict[str, Any]] = None,
config_kwargs: Optional[dict[str, Any]] = None,
truncate_dim: int | None = None,
model_kwargs: dict[str, Any] | None = None,
tokenizer_kwargs: dict[str, Any] | None = None,
config_kwargs: dict[str, Any] | None = None,
precision: Literal["float32", "int8", "uint8", "binary",
"ubinary"] = "float32",
encode_kwargs: Optional[dict[str, Any]] = None,
encode_kwargs: dict[str, Any] | None = None,
backend: Literal["torch", "onnx", "openvino"] = "torch",
revision: Optional[str] = None)
revision: str | None = None)
```
Create a SentenceTransformersTextEmbedder component.
@@ -43,7 +43,7 @@ of the metric and its value is dictionary with the following keys:
```python
def aggregated_report(
output_format: Literal["json", "csv", "df"] = "json",
csv_file: Optional[str] = None
csv_file: str | None = None
) -> Union[dict[str, list[Any]], "DataFrame", str]
```
@@ -66,7 +66,7 @@ successful write or an error message.
```python
def detailed_report(
output_format: Literal["json", "csv", "df"] = "json",
csv_file: Optional[str] = None
csv_file: str | None = None
) -> Union[dict[str, list[Any]], "DataFrame", str]
```
@@ -89,9 +89,9 @@ the successful write or an error message.
```python
def comparative_detailed_report(
other: "EvaluationRunResult",
keep_columns: Optional[list[str]] = None,
keep_columns: list[str] | None = None,
output_format: Literal["json", "csv", "df"] = "json",
csv_file: Optional[str] = None) -> Union[str, "DataFrame", None]
csv_file: str | None = None) -> Union[str, "DataFrame", None]
```
Generates a report with detailed scores for each metric from two evaluation runs for comparison.
@@ -132,10 +132,10 @@ print(result["results"])
#### ContextRelevanceEvaluator.\_\_init\_\_
```python
def __init__(examples: Optional[list[dict[str, Any]]] = None,
def __init__(examples: list[dict[str, Any]] | None = None,
progress_bar: bool = True,
raise_on_failure: bool = True,
chat_generator: Optional[ChatGenerator] = None)
chat_generator: ChatGenerator | None = None)
```
Creates an instance of ContextRelevanceEvaluator.
@@ -641,7 +641,7 @@ print(result["score"])
#### DocumentRecallEvaluator.\_\_init\_\_
```python
def __init__(mode: Union[str, RecallMode] = RecallMode.SINGLE_HIT)
def __init__(mode: str | RecallMode = RecallMode.SINGLE_HIT)
```
Create a DocumentRecallEvaluator component.
@@ -733,10 +733,10 @@ print(result["results"])
#### FaithfulnessEvaluator.\_\_init\_\_
```python
def __init__(examples: Optional[list[dict[str, Any]]] = None,
def __init__(examples: list[dict[str, Any]] | None = None,
progress_bar: bool = True,
raise_on_failure: bool = True,
chat_generator: Optional[ChatGenerator] = None)
chat_generator: ChatGenerator | None = None)
```
Creates an instance of FaithfulnessEvaluator.
@@ -990,7 +990,7 @@ def __init__(instructions: str,
progress_bar: bool = True,
*,
raise_on_failure: bool = True,
chat_generator: Optional[ChatGenerator] = None)
chat_generator: ChatGenerator | None = None)
```
Creates an instance of LLMEvaluator.
@@ -1239,7 +1239,7 @@ print(result["individual_scores"])
def __init__(
model: str = "sentence-transformers/paraphrase-multilingual-mpnet-base-v2",
batch_size: int = 32,
device: Optional[ComponentDevice] = None,
device: ComponentDevice | None = None,
token: Secret = Secret.from_env_var(["HF_API_TOKEN", "HF_TOKEN"],
strict=False))
```
@@ -53,9 +53,9 @@ def __init__(*,
chat_generator: ChatGenerator,
prompt: str = DEFAULT_PROMPT_TEMPLATE,
file_path_meta_field: str = "file_path",
root_path: Optional[str] = None,
detail: Optional[Literal["auto", "high", "low"]] = None,
size: Optional[tuple[int, int]] = None,
root_path: str | None = None,
detail: Literal["auto", "high", "low"] | None = None,
size: tuple[int, int] | None = None,
raise_on_failure: bool = False,
max_workers: int = 3)
```
@@ -263,8 +263,8 @@ extractor.run(documents=docs)
```python
def __init__(prompt: str,
chat_generator: ChatGenerator,
expected_keys: Optional[list[str]] = None,
page_range: Optional[list[Union[str, int]]] = None,
expected_keys: list[str] | None = None,
page_range: list[str | int] | None = None,
raise_on_failure: bool = False,
max_workers: int = 3)
```
@@ -337,8 +337,7 @@ An instance of the component.
```python
@component.output_types(documents=list[Document],
failed_documents=list[Document])
def run(documents: list[Document],
page_range: Optional[list[Union[str, int]]] = None)
def run(documents: list[Document], page_range: list[str | int] | None = None)
```
Extract metadata from documents using a Large Language Model.
@@ -449,12 +448,12 @@ print(annotations)
```python
def __init__(
*,
backend: Union[str, NamedEntityExtractorBackend],
backend: str | NamedEntityExtractorBackend,
model: str,
pipeline_kwargs: Optional[dict[str, Any]] = None,
device: Optional[ComponentDevice] = None,
token: Optional[Secret] = Secret.from_env_var(["HF_API_TOKEN", "HF_TOKEN"],
strict=False)
pipeline_kwargs: dict[str, Any] | None = None,
device: ComponentDevice | None = None,
token: Secret | None = Secret.from_env_var(["HF_API_TOKEN", "HF_TOKEN"],
strict=False)
) -> None
```
@@ -563,7 +562,7 @@ Returns if the extractor is ready to annotate text.
```python
@classmethod
def get_stored_annotations(
cls, document: Document) -> Optional[list[NamedEntityAnnotation]]
cls, document: Document) -> list[NamedEntityAnnotation] | None
```
Returns the document's named entity annotations stored in its metadata, if any.
@@ -628,7 +627,7 @@ Example: `'<issue url="(.+)">'` captures `'github.com/hahahaha'` from `'<issue u
```python
@component.output_types(captured_text=str, captured_texts=list[str])
def run(text_or_messages: Union[str, list[ChatMessage]]) -> dict
def run(text_or_messages: str | list[ChatMessage]) -> dict
```
Extracts text from input using the configured regex pattern.
@@ -54,12 +54,12 @@ streams = asyncio.run(fetch_async())
```python
def __init__(raise_on_failure: bool = True,
user_agents: Optional[list[str]] = None,
user_agents: list[str] | None = None,
retry_attempts: int = 2,
timeout: int = 3,
http2: bool = False,
client_kwargs: Optional[dict] = None,
request_headers: Optional[dict[str, str]] = None)
client_kwargs: dict | None = None,
request_headers: dict[str, str] | None = None)
```
Initializes the component.
@@ -54,23 +54,23 @@ print(response)
#### AzureOpenAIGenerator.\_\_init\_\_
```python
def __init__(azure_endpoint: Optional[str] = None,
api_version: Optional[str] = "2024-12-01-preview",
azure_deployment: Optional[str] = "gpt-4.1-mini",
api_key: Optional[Secret] = Secret.from_env_var(
def __init__(azure_endpoint: str | None = None,
api_version: str | None = "2024-12-01-preview",
azure_deployment: str | None = "gpt-4.1-mini",
api_key: Secret | None = Secret.from_env_var(
"AZURE_OPENAI_API_KEY", strict=False),
azure_ad_token: Optional[Secret] = Secret.from_env_var(
azure_ad_token: Secret | None = Secret.from_env_var(
"AZURE_OPENAI_AD_TOKEN", strict=False),
organization: Optional[str] = None,
streaming_callback: Optional[StreamingCallbackT] = None,
system_prompt: Optional[str] = None,
timeout: Optional[float] = None,
max_retries: Optional[int] = None,
http_client_kwargs: Optional[dict[str, Any]] = None,
generation_kwargs: Optional[dict[str, Any]] = None,
default_headers: Optional[dict[str, str]] = None,
organization: str | None = None,
streaming_callback: StreamingCallbackT | None = None,
system_prompt: str | None = None,
timeout: float | None = None,
max_retries: int | None = None,
http_client_kwargs: dict[str, Any] | None = None,
generation_kwargs: dict[str, Any] | None = None,
default_headers: dict[str, str] | None = None,
*,
azure_ad_token_provider: Optional[AzureADTokenProvider] = None)
azure_ad_token_provider: AzureADTokenProvider | None = None)
```
Initialize the Azure OpenAI Generator.
@@ -160,10 +160,10 @@ The deserialized component instance.
@component.output_types(replies=list[str], meta=list[dict[str, Any]])
def run(
prompt: str,
system_prompt: Optional[str] = None,
streaming_callback: Optional[StreamingCallbackT] = None,
generation_kwargs: Optional[dict[str, Any]] = None
) -> dict[str, Union[list[str], list[dict[str, Any]]]]
system_prompt: str | None = None,
streaming_callback: StreamingCallbackT | None = None,
generation_kwargs: dict[str, Any] | None = None
) -> dict[str, list[str] | list[dict[str, Any]]]
```
Invoke the text generation inference based on the provided messages and generation parameters.
@@ -238,25 +238,25 @@ print(response)
#### AzureOpenAIChatGenerator.\_\_init\_\_
```python
def __init__(azure_endpoint: Optional[str] = None,
api_version: Optional[str] = "2024-12-01-preview",
azure_deployment: Optional[str] = "gpt-4.1-mini",
api_key: Optional[Secret] = Secret.from_env_var(
def __init__(azure_endpoint: str | None = None,
api_version: str | None = "2024-12-01-preview",
azure_deployment: str | None = "gpt-4.1-mini",
api_key: Secret | None = Secret.from_env_var(
"AZURE_OPENAI_API_KEY", strict=False),
azure_ad_token: Optional[Secret] = Secret.from_env_var(
azure_ad_token: Secret | None = Secret.from_env_var(
"AZURE_OPENAI_AD_TOKEN", strict=False),
organization: Optional[str] = None,
streaming_callback: Optional[StreamingCallbackT] = None,
timeout: Optional[float] = None,
max_retries: Optional[int] = None,
generation_kwargs: Optional[dict[str, Any]] = None,
default_headers: Optional[dict[str, str]] = None,
tools: Optional[ToolsType] = None,
organization: str | None = None,
streaming_callback: StreamingCallbackT | None = None,
timeout: float | None = None,
max_retries: int | None = None,
generation_kwargs: dict[str, Any] | None = None,
default_headers: dict[str, str] | None = None,
tools: ToolsType | None = None,
tools_strict: bool = False,
*,
azure_ad_token_provider: Optional[Union[
AzureADTokenProvider, AsyncAzureADTokenProvider]] = None,
http_client_kwargs: Optional[dict[str, Any]] = None)
azure_ad_token_provider: AzureADTokenProvider
| AsyncAzureADTokenProvider | None = None,
http_client_kwargs: dict[str, Any] | None = None)
```
Initialize the Azure OpenAI Chat Generator component.
@@ -368,11 +368,11 @@ The deserialized component instance.
```python
@component.output_types(replies=list[ChatMessage])
def run(messages: list[ChatMessage],
streaming_callback: Optional[StreamingCallbackT] = None,
generation_kwargs: Optional[dict[str, Any]] = None,
streaming_callback: StreamingCallbackT | None = None,
generation_kwargs: dict[str, Any] | None = None,
*,
tools: Optional[ToolsType] = None,
tools_strict: Optional[bool] = None) -> dict[str, list[ChatMessage]]
tools: ToolsType | None = None,
tools_strict: bool | None = None) -> dict[str, list[ChatMessage]]
```
Invokes chat completion based on the provided messages and generation parameters.
@@ -403,11 +403,11 @@ A dictionary with the following key:
@component.output_types(replies=list[ChatMessage])
async def run_async(
messages: list[ChatMessage],
streaming_callback: Optional[StreamingCallbackT] = None,
generation_kwargs: Optional[dict[str, Any]] = None,
streaming_callback: StreamingCallbackT | None = None,
generation_kwargs: dict[str, Any] | None = None,
*,
tools: Optional[ToolsType] = None,
tools_strict: Optional[bool] = None) -> dict[str, list[ChatMessage]]
tools: ToolsType | None = None,
tools_strict: bool | None = None) -> dict[str, list[ChatMessage]]
```
Asynchronously invokes chat completion based on the provided messages and generation parameters.
@@ -478,20 +478,19 @@ print(response)
```python
def __init__(*,
api_key: Union[Secret, Callable[[], str],
Callable[[],
Awaitable[str]]] = Secret.from_env_var(
"AZURE_OPENAI_API_KEY", strict=False),
azure_endpoint: Optional[str] = None,
api_key: Secret | Callable[[], str]
| Callable[[], Awaitable[str]] = Secret.from_env_var(
"AZURE_OPENAI_API_KEY", strict=False),
azure_endpoint: str | None = None,
azure_deployment: str = "gpt-5-mini",
streaming_callback: Optional[StreamingCallbackT] = None,
organization: Optional[str] = None,
generation_kwargs: Optional[dict[str, Any]] = None,
timeout: Optional[float] = None,
max_retries: Optional[int] = None,
tools: Optional[ToolsType] = None,
streaming_callback: StreamingCallbackT | None = None,
organization: str | None = None,
generation_kwargs: dict[str, Any] | None = None,
timeout: float | None = None,
max_retries: int | None = None,
tools: ToolsType | None = None,
tools_strict: bool = False,
http_client_kwargs: Optional[dict[str, Any]] = None)
http_client_kwargs: dict[str, Any] | None = None)
```
Initialize the AzureOpenAIResponsesChatGenerator component.
@@ -605,10 +604,10 @@ This method is idempotent and will only warm up the tools once.
@component.output_types(replies=list[ChatMessage])
def run(messages: list[ChatMessage],
*,
streaming_callback: Optional[StreamingCallbackT] = None,
generation_kwargs: Optional[dict[str, Any]] = None,
tools: Optional[Union[ToolsType, list[dict]]] = None,
tools_strict: Optional[bool] = None) -> dict[str, list[ChatMessage]]
streaming_callback: StreamingCallbackT | None = None,
generation_kwargs: dict[str, Any] | None = None,
tools: ToolsType | list[dict] | None = None,
tools_strict: bool | None = None) -> dict[str, list[ChatMessage]]
```
Invokes response generation based on the provided messages and generation parameters.
@@ -645,10 +644,10 @@ A dictionary with the following key:
async def run_async(
messages: list[ChatMessage],
*,
streaming_callback: Optional[StreamingCallbackT] = None,
generation_kwargs: Optional[dict[str, Any]] = None,
tools: Optional[Union[ToolsType, list[dict]]] = None,
tools_strict: Optional[bool] = None) -> dict[str, list[ChatMessage]]
streaming_callback: StreamingCallbackT | None = None,
generation_kwargs: dict[str, Any] | None = None,
tools: ToolsType | list[dict] | None = None,
tools_strict: bool | None = None) -> dict[str, list[ChatMessage]]
```
Asynchronously invokes response generation based on the provided messages and generation parameters.
@@ -768,10 +767,10 @@ This method calls warm_up() on each underlying generator that supports it.
@component.output_types(replies=list[ChatMessage], meta=dict[str, Any])
def run(
messages: list[ChatMessage],
generation_kwargs: Union[dict[str, Any], None] = None,
tools: Optional[ToolsType] = None,
streaming_callback: Union[StreamingCallbackT, None] = None
) -> dict[str, Union[list[ChatMessage], dict[str, Any]]]
generation_kwargs: dict[str, Any] | None = None,
tools: ToolsType | None = None,
streaming_callback: StreamingCallbackT | None = None
) -> dict[str, list[ChatMessage] | dict[str, Any]]
```
Execute chat generators sequentially until one succeeds.
@@ -802,10 +801,10 @@ A dictionary with:
@component.output_types(replies=list[ChatMessage], meta=dict[str, Any])
async def run_async(
messages: list[ChatMessage],
generation_kwargs: Union[dict[str, Any], None] = None,
tools: Optional[ToolsType] = None,
streaming_callback: Union[StreamingCallbackT, None] = None
) -> dict[str, Union[list[ChatMessage], dict[str, Any]]]
generation_kwargs: dict[str, Any] | None = None,
tools: ToolsType | None = None,
streaming_callback: StreamingCallbackT | None = None
) -> dict[str, list[ChatMessage] | dict[str, Any]]
```
Asynchronously execute chat generators sequentially until one succeeds.
@@ -935,14 +934,14 @@ print(result)
#### HuggingFaceAPIChatGenerator.\_\_init\_\_
```python
def __init__(api_type: Union[HFGenerationAPIType, str],
def __init__(api_type: HFGenerationAPIType | str,
api_params: dict[str, str],
token: Optional[Secret] = Secret.from_env_var(
token: Secret | None = Secret.from_env_var(
["HF_API_TOKEN", "HF_TOKEN"], strict=False),
generation_kwargs: Optional[dict[str, Any]] = None,
stop_words: Optional[list[str]] = None,
streaming_callback: Optional[StreamingCallbackT] = None,
tools: Optional[ToolsType] = None)
generation_kwargs: dict[str, Any] | None = None,
stop_words: list[str] | None = None,
streaming_callback: StreamingCallbackT | None = None,
tools: ToolsType | None = None)
```
Initialize the HuggingFaceAPIChatGenerator instance.
@@ -1018,9 +1017,9 @@ Deserialize this component from a dictionary.
@component.output_types(replies=list[ChatMessage])
def run(
messages: list[ChatMessage],
generation_kwargs: Optional[dict[str, Any]] = None,
tools: Optional[ToolsType] = None,
streaming_callback: Optional[StreamingCallbackT] = None
generation_kwargs: dict[str, Any] | None = None,
tools: ToolsType | None = None,
streaming_callback: StreamingCallbackT | None = None
) -> dict[str, list[ChatMessage]]
```
@@ -1049,9 +1048,9 @@ A dictionary with the following keys:
@component.output_types(replies=list[ChatMessage])
async def run_async(
messages: list[ChatMessage],
generation_kwargs: Optional[dict[str, Any]] = None,
tools: Optional[ToolsType] = None,
streaming_callback: Optional[StreamingCallbackT] = None
generation_kwargs: dict[str, Any] | None = None,
tools: ToolsType | None = None,
streaming_callback: StreamingCallbackT | None = None
) -> dict[str, list[ChatMessage]]
```
@@ -1084,7 +1083,7 @@ A dictionary with the following keys:
#### default\_tool\_parser
```python
def default_tool_parser(text: str) -> Optional[list[ToolCall]]
def default_tool_parser(text: str) -> list[ToolCall] | None
```
Default implementation for parsing tool calls from model output text.
@@ -1143,20 +1142,20 @@ print(generator.run(messages))
```python
def __init__(model: str = "Qwen/Qwen3-0.6B",
task: Optional[Literal["text-generation",
"text2text-generation"]] = None,
device: Optional[ComponentDevice] = None,
token: Optional[Secret] = Secret.from_env_var(
task: Literal["text-generation", "text2text-generation"]
| None = None,
device: ComponentDevice | None = None,
token: Secret | None = Secret.from_env_var(
["HF_API_TOKEN", "HF_TOKEN"], strict=False),
chat_template: Optional[str] = None,
generation_kwargs: Optional[dict[str, Any]] = None,
huggingface_pipeline_kwargs: Optional[dict[str, Any]] = None,
stop_words: Optional[list[str]] = None,
streaming_callback: Optional[StreamingCallbackT] = None,
tools: Optional[ToolsType] = None,
tool_parsing_function: Optional[Callable[
[str], Optional[list[ToolCall]]]] = None,
async_executor: Optional[ThreadPoolExecutor] = None,
chat_template: str | None = None,
generation_kwargs: dict[str, Any] | None = None,
huggingface_pipeline_kwargs: dict[str, Any] | None = None,
stop_words: list[str] | None = None,
streaming_callback: StreamingCallbackT | None = None,
tools: ToolsType | None = None,
tool_parsing_function: Callable[[str], list[ToolCall] | None]
| None = None,
async_executor: ThreadPoolExecutor | None = None,
*,
enable_thinking: bool = False) -> None
```
@@ -1277,9 +1276,9 @@ The deserialized component.
```python
@component.output_types(replies=list[ChatMessage])
def run(messages: list[ChatMessage],
generation_kwargs: Optional[dict[str, Any]] = None,
streaming_callback: Optional[StreamingCallbackT] = None,
tools: Optional[ToolsType] = None) -> dict[str, list[ChatMessage]]
generation_kwargs: dict[str, Any] | None = None,
streaming_callback: StreamingCallbackT | None = None,
tools: ToolsType | None = None) -> dict[str, list[ChatMessage]]
```
Invoke text generation inference based on the provided messages and generation parameters.
@@ -1334,9 +1333,9 @@ A ChatMessage instance.
@component.output_types(replies=list[ChatMessage])
async def run_async(
messages: list[ChatMessage],
generation_kwargs: Optional[dict[str, Any]] = None,
streaming_callback: Optional[StreamingCallbackT] = None,
tools: Optional[ToolsType] = None) -> dict[str, list[ChatMessage]]
generation_kwargs: dict[str, Any] | None = None,
streaming_callback: StreamingCallbackT | None = None,
tools: ToolsType | None = None) -> dict[str, list[ChatMessage]]
```
Asynchronously invokes text generation inference based on the provided messages and generation parameters.
@@ -1412,15 +1411,15 @@ Output:
```python
def __init__(api_key: Secret = Secret.from_env_var("OPENAI_API_KEY"),
model: str = "gpt-5-mini",
streaming_callback: Optional[StreamingCallbackT] = None,
api_base_url: Optional[str] = None,
organization: Optional[str] = None,
generation_kwargs: Optional[dict[str, Any]] = None,
timeout: Optional[float] = None,
max_retries: Optional[int] = None,
tools: Optional[ToolsType] = None,
streaming_callback: StreamingCallbackT | None = None,
api_base_url: str | None = None,
organization: str | None = None,
generation_kwargs: dict[str, Any] | None = None,
timeout: float | None = None,
max_retries: int | None = None,
tools: ToolsType | None = None,
tools_strict: bool = False,
http_client_kwargs: Optional[dict[str, Any]] = None)
http_client_kwargs: dict[str, Any] | None = None)
```
Creates an instance of OpenAIChatGenerator. Unless specified otherwise in `model`, uses OpenAI's gpt-5-mini
@@ -1534,11 +1533,11 @@ The deserialized component instance.
```python
@component.output_types(replies=list[ChatMessage])
def run(messages: list[ChatMessage],
streaming_callback: Optional[StreamingCallbackT] = None,
generation_kwargs: Optional[dict[str, Any]] = None,
streaming_callback: StreamingCallbackT | None = None,
generation_kwargs: dict[str, Any] | None = None,
*,
tools: Optional[ToolsType] = None,
tools_strict: Optional[bool] = None) -> dict[str, list[ChatMessage]]
tools: ToolsType | None = None,
tools_strict: bool | None = None) -> dict[str, list[ChatMessage]]
```
Invokes chat completion based on the provided messages and generation parameters.
@@ -1569,11 +1568,11 @@ A dictionary with the following key:
@component.output_types(replies=list[ChatMessage])
async def run_async(
messages: list[ChatMessage],
streaming_callback: Optional[StreamingCallbackT] = None,
generation_kwargs: Optional[dict[str, Any]] = None,
streaming_callback: StreamingCallbackT | None = None,
generation_kwargs: dict[str, Any] | None = None,
*,
tools: Optional[ToolsType] = None,
tools_strict: Optional[bool] = None) -> dict[str, list[ChatMessage]]
tools: ToolsType | None = None,
tools_strict: bool | None = None) -> dict[str, list[ChatMessage]]
```
Asynchronously invokes chat completion based on the provided messages and generation parameters.
@@ -1643,15 +1642,15 @@ print(response)
def __init__(*,
api_key: Secret = Secret.from_env_var("OPENAI_API_KEY"),
model: str = "gpt-5-mini",
streaming_callback: Optional[StreamingCallbackT] = None,
api_base_url: Optional[str] = None,
organization: Optional[str] = None,
generation_kwargs: Optional[dict[str, Any]] = None,
timeout: Optional[float] = None,
max_retries: Optional[int] = None,
tools: Optional[Union[ToolsType, list[dict]]] = None,
streaming_callback: StreamingCallbackT | None = None,
api_base_url: str | None = None,
organization: str | None = None,
generation_kwargs: dict[str, Any] | None = None,
timeout: float | None = None,
max_retries: int | None = None,
tools: ToolsType | list[dict] | None = None,
tools_strict: bool = False,
http_client_kwargs: Optional[dict[str, Any]] = None)
http_client_kwargs: dict[str, Any] | None = None)
```
Creates an instance of OpenAIResponsesChatGenerator. Uses OpenAI's gpt-5-mini by default.
@@ -1772,10 +1771,10 @@ The deserialized component instance.
@component.output_types(replies=list[ChatMessage])
def run(messages: list[ChatMessage],
*,
streaming_callback: Optional[StreamingCallbackT] = None,
generation_kwargs: Optional[dict[str, Any]] = None,
tools: Optional[Union[ToolsType, list[dict]]] = None,
tools_strict: Optional[bool] = None) -> dict[str, list[ChatMessage]]
streaming_callback: StreamingCallbackT | None = None,
generation_kwargs: dict[str, Any] | None = None,
tools: ToolsType | list[dict] | None = None,
tools_strict: bool | None = None) -> dict[str, list[ChatMessage]]
```
Invokes response generation based on the provided messages and generation parameters.
@@ -1812,10 +1811,10 @@ A dictionary with the following key:
async def run_async(
messages: list[ChatMessage],
*,
streaming_callback: Optional[StreamingCallbackT] = None,
generation_kwargs: Optional[dict[str, Any]] = None,
tools: Optional[Union[ToolsType, list[dict]]] = None,
tools_strict: Optional[bool] = None) -> dict[str, list[ChatMessage]]
streaming_callback: StreamingCallbackT | None = None,
generation_kwargs: dict[str, Any] | None = None,
tools: ToolsType | list[dict] | None = None,
tools_strict: bool | None = None) -> dict[str, list[ChatMessage]]
```
Asynchronously invokes response generation based on the provided messages and generation parameters.
@@ -1914,13 +1913,13 @@ print(result)
#### HuggingFaceAPIGenerator.\_\_init\_\_
```python
def __init__(api_type: Union[HFGenerationAPIType, str],
def __init__(api_type: HFGenerationAPIType | str,
api_params: dict[str, str],
token: Optional[Secret] = Secret.from_env_var(
token: Secret | None = Secret.from_env_var(
["HF_API_TOKEN", "HF_TOKEN"], strict=False),
generation_kwargs: Optional[dict[str, Any]] = None,
stop_words: Optional[list[str]] = None,
streaming_callback: Optional[StreamingCallbackT] = None)
generation_kwargs: dict[str, Any] | None = None,
stop_words: list[str] | None = None,
streaming_callback: StreamingCallbackT | None = None)
```
Initialize the HuggingFaceAPIGenerator instance.
@@ -1979,8 +1978,8 @@ Deserialize this component from a dictionary.
```python
@component.output_types(replies=list[str], meta=list[dict[str, Any]])
def run(prompt: str,
streaming_callback: Optional[StreamingCallbackT] = None,
generation_kwargs: Optional[dict[str, Any]] = None)
streaming_callback: StreamingCallbackT | None = None,
generation_kwargs: dict[str, Any] | None = None)
```
Invoke the text generation inference for the given prompt and generation parameters.
@@ -2030,15 +2029,15 @@ print(generator.run("Who is the best American actor?"))
```python
def __init__(model: str = "google/flan-t5-base",
task: Optional[Literal["text-generation",
"text2text-generation"]] = None,
device: Optional[ComponentDevice] = None,
token: Optional[Secret] = Secret.from_env_var(
task: Literal["text-generation", "text2text-generation"]
| None = None,
device: ComponentDevice | None = None,
token: Secret | None = Secret.from_env_var(
["HF_API_TOKEN", "HF_TOKEN"], strict=False),
generation_kwargs: Optional[dict[str, Any]] = None,
huggingface_pipeline_kwargs: Optional[dict[str, Any]] = None,
stop_words: Optional[list[str]] = None,
streaming_callback: Optional[StreamingCallbackT] = None)
generation_kwargs: dict[str, Any] | None = None,
huggingface_pipeline_kwargs: dict[str, Any] | None = None,
stop_words: list[str] | None = None,
streaming_callback: StreamingCallbackT | None = None)
```
Creates an instance of a HuggingFaceLocalGenerator.
@@ -2123,8 +2122,8 @@ The deserialized component.
```python
@component.output_types(replies=list[str])
def run(prompt: str,
streaming_callback: Optional[StreamingCallbackT] = None,
generation_kwargs: Optional[dict[str, Any]] = None)
streaming_callback: StreamingCallbackT | None = None,
generation_kwargs: dict[str, Any] | None = None)
```
Run the text generation model on the given prompt.
@@ -2184,14 +2183,14 @@ print(response)
```python
def __init__(api_key: Secret = Secret.from_env_var("OPENAI_API_KEY"),
model: str = "gpt-5-mini",
streaming_callback: Optional[StreamingCallbackT] = None,
api_base_url: Optional[str] = None,
organization: Optional[str] = None,
system_prompt: Optional[str] = None,
generation_kwargs: Optional[dict[str, Any]] = None,
timeout: Optional[float] = None,
max_retries: Optional[int] = None,
http_client_kwargs: Optional[dict[str, Any]] = None)
streaming_callback: StreamingCallbackT | None = None,
api_base_url: str | None = None,
organization: str | None = None,
system_prompt: str | None = None,
generation_kwargs: dict[str, Any] | None = None,
timeout: float | None = None,
max_retries: int | None = None,
http_client_kwargs: dict[str, Any] | None = None)
```
Creates an instance of OpenAIGenerator. Unless specified otherwise in `model`, uses OpenAI's gpt-5-mini
@@ -2277,10 +2276,10 @@ The deserialized component instance.
@component.output_types(replies=list[str], meta=list[dict[str, Any]])
def run(
prompt: str,
system_prompt: Optional[str] = None,
streaming_callback: Optional[StreamingCallbackT] = None,
generation_kwargs: Optional[dict[str, Any]] = None
) -> dict[str, Union[list[str], list[dict[str, Any]]]]
system_prompt: str | None = None,
streaming_callback: StreamingCallbackT | None = None,
generation_kwargs: dict[str, Any] | None = None
) -> dict[str, list[str] | list[dict[str, Any]]]
```
Invoke the text generation inference based on the provided messages and generation parameters.
@@ -2333,11 +2332,11 @@ def __init__(model: str = "dall-e-3",
"1024x1792"] = "1024x1024",
response_format: Literal["url", "b64_json"] = "url",
api_key: Secret = Secret.from_env_var("OPENAI_API_KEY"),
api_base_url: Optional[str] = None,
organization: Optional[str] = None,
timeout: Optional[float] = None,
max_retries: Optional[int] = None,
http_client_kwargs: Optional[dict[str, Any]] = None)
api_base_url: str | None = None,
organization: str | None = None,
timeout: float | None = None,
max_retries: int | None = None,
http_client_kwargs: dict[str, Any] | None = None)
```
Creates an instance of DALLEImageGenerator. Unless specified otherwise in `model`, uses OpenAI's dall-e-3.
@@ -2377,11 +2376,10 @@ Warm up the OpenAI client.
```python
@component.output_types(images=list[str], revised_prompt=str)
def run(prompt: str,
size: Optional[Literal["256x256", "512x512", "1024x1024", "1792x1024",
"1024x1792"]] = None,
quality: Optional[Literal["standard", "hd"]] = None,
response_format: Optional[Optional[Literal["url",
"b64_json"]]] = None)
size: Literal["256x256", "512x512", "1024x1024", "1792x1024",
"1024x1792"] | None = None,
quality: Literal["standard", "hd"] | None = None,
response_format: Literal["url", "b64_json"] | None = None)
```
Invokes the image generation inference based on the provided prompt and generation parameters.
@@ -59,9 +59,9 @@ Documents are expected to have metadata containing:
```python
def __init__(*,
file_path_meta_field: str = "file_path",
root_path: Optional[str] = None,
detail: Optional[Literal["auto", "high", "low"]] = None,
size: Optional[tuple[int, int]] = None)
root_path: str | None = None,
detail: Literal["auto", "high", "low"] | None = None,
size: tuple[int, int] | None = None)
```
Initialize the DocumentToImageContent component.
@@ -82,8 +82,8 @@ when working with models that have resolution constraints or when transmitting i
#### DocumentToImageContent.run
```python
@component.output_types(image_contents=list[Optional[ImageContent]])
def run(documents: list[Document]) -> dict[str, list[Optional[ImageContent]]]
@component.output_types(image_contents=list[ImageContent | None])
def run(documents: list[Document]) -> dict[str, list[ImageContent | None]]
```
Convert documents with image or PDF sources into ImageContent objects.
@@ -164,8 +164,8 @@ If False, only the file name is stored.
@component.output_types(documents=list[Document])
def run(
*,
sources: list[Union[str, Path, ByteStream]],
meta: Optional[Union[dict[str, Any], list[dict[str, Any]]]] = None
sources: list[str | Path | ByteStream],
meta: dict[str, Any] | list[dict[str, Any]] | None = None
) -> dict[str, list[Document]]
```
@@ -223,8 +223,8 @@ print(image_contents)
```python
def __init__(*,
detail: Optional[Literal["auto", "high", "low"]] = None,
size: Optional[tuple[int, int]] = None)
detail: Literal["auto", "high", "low"] | None = None,
size: tuple[int, int] | None = None)
```
Create the ImageFileToImageContent component.
@@ -243,12 +243,11 @@ when working with models that have resolution constraints or when transmitting i
```python
@component.output_types(image_contents=list[ImageContent])
def run(sources: list[Union[str, Path, ByteStream]],
meta: Optional[Union[dict[str, Any], list[dict[str, Any]]]] = None,
def run(sources: list[str | Path | ByteStream],
meta: dict[str, Any] | list[dict[str, Any]] | None = None,
*,
detail: Optional[Literal["auto", "high", "low"]] = None,
size: Optional[tuple[int,
int]] = None) -> dict[str, list[ImageContent]]
detail: Literal["auto", "high", "low"] | None = None,
size: tuple[int, int] | None = None) -> dict[str, list[ImageContent]]
```
Converts files to ImageContent objects.
@@ -308,9 +307,9 @@ print(image_contents)
```python
def __init__(*,
detail: Optional[Literal["auto", "high", "low"]] = None,
size: Optional[tuple[int, int]] = None,
page_range: Optional[list[Union[str, int]]] = None)
detail: Literal["auto", "high", "low"] | None = None,
size: tuple[int, int] | None = None,
page_range: list[str | int] | None = None)
```
Create the PDFToImageContent component.
@@ -335,12 +334,12 @@ will convert pages 1, 2, 3, 5, 8, 10, 11, 12.
```python
@component.output_types(image_contents=list[ImageContent])
def run(
sources: list[Union[str, Path, ByteStream]],
meta: Optional[Union[dict[str, Any], list[dict[str, Any]]]] = None,
sources: list[str | Path | ByteStream],
meta: dict[str, Any] | list[dict[str, Any]] | None = None,
*,
detail: Optional[Literal["auto", "high", "low"]] = None,
size: Optional[tuple[int, int]] = None,
page_range: Optional[list[Union[str, int]]] = None
detail: Literal["auto", "high", "low"] | None = None,
size: tuple[int, int] | None = None,
page_range: list[str | int] | None = None
) -> dict[str, list[ImageContent]]
```
@@ -77,8 +77,8 @@ results = pipe.run(data={"llm_1": {"messages": messages},
#### AnswerJoiner.\_\_init\_\_
```python
def __init__(join_mode: Union[str, JoinMode] = JoinMode.CONCATENATE,
top_k: Optional[int] = None,
def __init__(join_mode: str | JoinMode = JoinMode.CONCATENATE,
top_k: int | None = None,
sort_by_score: bool = False)
```
@@ -98,7 +98,7 @@ If a document has no score, it is handled as if its score is -infinity.
```python
@component.output_types(answers=list[AnswerType])
def run(answers: Variadic[list[AnswerType]], top_k: Optional[int] = None)
def run(answers: Variadic[list[AnswerType]], top_k: int | None = None)
```
Joins multiple lists of Answers into a single list depending on the `join_mode` parameter.
@@ -364,9 +364,9 @@ p.run(data={"query": query, "text": query, "top_k": 1})
#### DocumentJoiner.\_\_init\_\_
```python
def __init__(join_mode: Union[str, JoinMode] = JoinMode.CONCATENATE,
weights: Optional[list[float]] = None,
top_k: Optional[int] = None,
def __init__(join_mode: str | JoinMode = JoinMode.CONCATENATE,
weights: list[float] | None = None,
top_k: int | None = None,
sort_by_score: bool = True)
```
@@ -394,7 +394,7 @@ If a document has no score, it is handled as if its score is -infinity.
```python
@component.output_types(documents=list[Document])
def run(documents: Variadic[list[Document]], top_k: Optional[int] = None)
def run(documents: Variadic[list[Document]], top_k: int | None = None)
```
Joins multiple lists of Documents into a single list depending on the `join_mode` parameter.
@@ -505,7 +505,7 @@ print(ans["list_joiner"]["values"])
#### ListJoiner.\_\_init\_\_
```python
def __init__(list_type_: Optional[type] = None)
def __init__(list_type_: type | None = None)
```
Creates a ListJoiner component.
@@ -25,7 +25,7 @@ This enables efficient processing of components by minimizing idle time and maxi
```python
async def run_async_generator(
data: dict[str, Any],
include_outputs_from: Optional[set[str]] = None,
include_outputs_from: set[str] | None = None,
concurrency_limit: int = 4) -> AsyncIterator[dict[str, Any]]
```
@@ -128,7 +128,7 @@ An async iterator containing partial (and final) outputs.
```python
async def run_async(data: dict[str, Any],
include_outputs_from: Optional[set[str]] = None,
include_outputs_from: set[str] | None = None,
concurrency_limit: int = 4) -> dict[str, Any]
```
@@ -245,7 +245,7 @@ without outgoing connections.
```python
def run(data: dict[str, Any],
include_outputs_from: Optional[set[str]] = None,
include_outputs_from: set[str] | None = None,
concurrency_limit: int = 4) -> dict[str, Any]
```
@@ -360,7 +360,7 @@ without outgoing connections.
#### AsyncPipeline.\_\_init\_\_
```python
def __init__(metadata: Optional[dict[str, Any]] = None,
def __init__(metadata: dict[str, Any] | None = None,
max_runs_per_component: int = 100,
connection_type_validation: bool = True)
```
@@ -424,7 +424,7 @@ Dictionary with serialized data.
@classmethod
def from_dict(cls: type[T],
data: dict[str, Any],
callbacks: Optional[DeserializationCallbacks] = None,
callbacks: DeserializationCallbacks | None = None,
**kwargs: Any) -> T
```
@@ -481,9 +481,9 @@ Writes the string representation of this pipeline to the file-like object passed
```python
@classmethod
def loads(cls: type[T],
data: Union[str, bytes, bytearray],
data: str | bytes | bytearray,
marshaller: Marshaller = DEFAULT_MARSHALLER,
callbacks: Optional[DeserializationCallbacks] = None) -> T
callbacks: DeserializationCallbacks | None = None) -> T
```
Creates a `Pipeline` object from the string representation passed in the `data` argument.
@@ -511,7 +511,7 @@ A `Pipeline` object.
def load(cls: type[T],
fp: TextIO,
marshaller: Marshaller = DEFAULT_MARSHALLER,
callbacks: Optional[DeserializationCallbacks] = None) -> T
callbacks: DeserializationCallbacks | None = None) -> T
```
Creates a `Pipeline` object a string representation.
@@ -707,7 +707,7 @@ output sockets of that component.
```python
def show(*,
server_url: str = "https://mermaid.ink",
params: Optional[dict] = None,
params: dict | None = None,
timeout: int = 30,
super_component_expansion: bool = False) -> None
```
@@ -751,7 +751,7 @@ Otherwise, only the super-component itself will be displayed.
def draw(*,
path: Path,
server_url: str = "https://mermaid.ink",
params: Optional[dict] = None,
params: dict | None = None,
timeout: int = 30,
super_component_expansion: bool = False) -> None
```
@@ -849,7 +849,7 @@ Validates that data:
def from_template(
cls,
predefined_pipeline: PredefinedPipeline,
template_params: Optional[dict[str, Any]] = None) -> "PipelineBase"
template_params: dict[str, Any] | None = None) -> "PipelineBase"
```
Create a Pipeline from a predefined template. See `PredefinedPipeline` for available options.
@@ -900,11 +900,10 @@ Orchestrates component execution according to the execution graph, one after the
```python
def run(data: dict[str, Any],
include_outputs_from: Optional[set[str]] = None,
include_outputs_from: set[str] | None = None,
*,
break_point: Optional[Union[Breakpoint, AgentBreakpoint]] = None,
pipeline_snapshot: Optional[PipelineSnapshot] = None
) -> dict[str, Any]
break_point: Breakpoint | AgentBreakpoint | None = None,
pipeline_snapshot: PipelineSnapshot | None = None) -> dict[str, Any]
```
Runs the Pipeline with given input data.
@@ -1004,7 +1003,7 @@ without outgoing connections.
#### Pipeline.\_\_init\_\_
```python
def __init__(metadata: Optional[dict[str, Any]] = None,
def __init__(metadata: dict[str, Any] | None = None,
max_runs_per_component: int = 100,
connection_type_validation: bool = True)
```
@@ -1068,7 +1067,7 @@ Dictionary with serialized data.
@classmethod
def from_dict(cls: type[T],
data: dict[str, Any],
callbacks: Optional[DeserializationCallbacks] = None,
callbacks: DeserializationCallbacks | None = None,
**kwargs: Any) -> T
```
@@ -1125,9 +1124,9 @@ Writes the string representation of this pipeline to the file-like object passed
```python
@classmethod
def loads(cls: type[T],
data: Union[str, bytes, bytearray],
data: str | bytes | bytearray,
marshaller: Marshaller = DEFAULT_MARSHALLER,
callbacks: Optional[DeserializationCallbacks] = None) -> T
callbacks: DeserializationCallbacks | None = None) -> T
```
Creates a `Pipeline` object from the string representation passed in the `data` argument.
@@ -1155,7 +1154,7 @@ A `Pipeline` object.
def load(cls: type[T],
fp: TextIO,
marshaller: Marshaller = DEFAULT_MARSHALLER,
callbacks: Optional[DeserializationCallbacks] = None) -> T
callbacks: DeserializationCallbacks | None = None) -> T
```
Creates a `Pipeline` object a string representation.
@@ -1351,7 +1350,7 @@ output sockets of that component.
```python
def show(*,
server_url: str = "https://mermaid.ink",
params: Optional[dict] = None,
params: dict | None = None,
timeout: int = 30,
super_component_expansion: bool = False) -> None
```
@@ -1395,7 +1394,7 @@ Otherwise, only the super-component itself will be displayed.
def draw(*,
path: Path,
server_url: str = "https://mermaid.ink",
params: Optional[dict] = None,
params: dict | None = None,
timeout: int = 30,
super_component_expansion: bool = False) -> None
```
@@ -1493,7 +1492,7 @@ Validates that data:
def from_template(
cls,
predefined_pipeline: PredefinedPipeline,
template_params: Optional[dict[str, Any]] = None) -> "PipelineBase"
template_params: dict[str, Any] | None = None) -> "PipelineBase"
```
Create a Pipeline from a predefined template. See `PredefinedPipeline` for available options.
@@ -92,9 +92,9 @@ and uses them as delimiters to segment the document into smaller tables.
#### CSVDocumentSplitter.\_\_init\_\_
```python
def __init__(row_split_threshold: Optional[int] = 2,
column_split_threshold: Optional[int] = 2,
read_csv_kwargs: Optional[dict[str, Any]] = None,
def __init__(row_split_threshold: int | None = 2,
column_split_threshold: int | None = 2,
read_csv_kwargs: dict[str, Any] | None = None,
split_mode: SplitMode = "threshold") -> None
```
@@ -188,10 +188,10 @@ def __init__(remove_empty_lines: bool = True,
remove_extra_whitespaces: bool = True,
remove_repeated_substrings: bool = False,
keep_id: bool = False,
remove_substrings: Optional[list[str]] = None,
remove_regex: Optional[str] = None,
unicode_normalization: Optional[Literal["NFC", "NFKC", "NFD",
"NFKD"]] = None,
remove_substrings: list[str] | None = None,
remove_regex: str | None = None,
unicode_normalization: Literal["NFC", "NFKC", "NFD", "NFKD"]
| None = None,
ascii_only: bool = False)
```
@@ -273,7 +273,7 @@ def __init__(*,
split_length: int = 250,
split_overlap: int = 0,
split_threshold: int = 0,
splitting_function: Optional[Callable[[str], list[str]]] = None,
splitting_function: Callable[[str], list[str]] | None = None,
respect_sentence_boundary: bool = False,
language: Language = "en",
use_split_rules: bool = True,
@@ -282,10 +282,10 @@ def __init__(*,
remove_extra_whitespaces: bool = True,
remove_repeated_substrings: bool = False,
keep_id: bool = False,
remove_substrings: Optional[list[str]] = None,
remove_regex: Optional[str] = None,
unicode_normalization: Optional[Literal["NFC", "NFKC", "NFD",
"NFKD"]] = None,
remove_substrings: list[str] | None = None,
remove_regex: str | None = None,
unicode_normalization: Literal["NFC", "NFKC", "NFD", "NFKD"]
| None = None,
ascii_only: bool = False) -> None
```
@@ -398,7 +398,7 @@ def __init__(split_by: Literal["function", "page", "passage", "period", "word",
split_length: int = 200,
split_overlap: int = 0,
split_threshold: int = 0,
splitting_function: Optional[Callable[[str], list[str]]] = None,
splitting_function: Callable[[str], list[str]] | None = None,
respect_sentence_boundary: bool = False,
language: Language = "en",
use_split_rules: bool = True,
@@ -674,8 +674,8 @@ def __init__(*,
split_length: int = 200,
split_overlap: int = 0,
split_unit: Literal["word", "char", "token"] = "word",
separators: Optional[list[str]] = None,
sentence_splitter_params: Optional[dict[str, Any]] = None)
separators: list[str] | None = None,
sentence_splitter_params: dict[str, Any] | None = None)
```
Initializes a RecursiveDocumentSplitter.
@@ -760,7 +760,7 @@ result = cleaner.run(texts=[text_to_clean])
#### TextCleaner.\_\_init\_\_
```python
def __init__(remove_regexps: Optional[list[str]] = None,
def __init__(remove_regexps: list[str] | None = None,
convert_to_lowercase: bool = False,
remove_punctuation: bool = False,
remove_numbers: bool = False)
@@ -49,8 +49,8 @@ expander = QueryExpander(n_expansions=3, include_original_query=False) # Exactl
```python
def __init__(*,
chat_generator: Optional[ChatGenerator] = None,
prompt_template: Optional[str] = None,
chat_generator: ChatGenerator | None = None,
prompt_template: str | None = None,
n_expansions: int = 4,
include_original_query: bool = True) -> None
```
@@ -107,8 +107,7 @@ Deserialized component.
```python
@component.output_types(queries=list[str])
def run(query: str,
n_expansions: Optional[int] = None) -> dict[str, list[str]]
def run(query: str, n_expansions: int | None = None) -> dict[str, list[str]]
```
Expand the input query into multiple semantically similar queries.
@@ -63,11 +63,11 @@ def __init__(
url: str,
top_k: int = 10,
raw_scores: bool = False,
timeout: Optional[int] = 30,
timeout: int | None = 30,
max_retries: int = 3,
retry_status_codes: Optional[list[int]] = None,
token: Optional[Secret] = Secret.from_env_var(["HF_API_TOKEN", "HF_TOKEN"],
strict=False)
retry_status_codes: list[int] | None = None,
token: Secret | None = Secret.from_env_var(["HF_API_TOKEN", "HF_TOKEN"],
strict=False)
) -> None
```
@@ -128,8 +128,8 @@ Deserialized component.
def run(
query: str,
documents: list[Document],
top_k: Optional[int] = None,
truncation_direction: Optional[TruncationDirection] = None
top_k: int | None = None,
truncation_direction: TruncationDirection | None = None
) -> dict[str, list[Document]]
```
@@ -161,8 +161,8 @@ A dictionary with the following keys:
async def run_async(
query: str,
documents: list[Document],
top_k: Optional[int] = None,
truncation_direction: Optional[TruncationDirection] = None
top_k: int | None = None,
truncation_direction: TruncationDirection | None = None
) -> dict[str, list[Document]]
```
@@ -224,8 +224,8 @@ for doc in result["documents"]:
#### LostInTheMiddleRanker.\_\_init\_\_
```python
def __init__(word_count_threshold: Optional[int] = None,
top_k: Optional[int] = None)
def __init__(word_count_threshold: int | None = None,
top_k: int | None = None)
```
Initialize the LostInTheMiddleRanker.
@@ -247,9 +247,8 @@ discarded.
```python
@component.output_types(documents=list[Document])
def run(documents: list[Document],
top_k: Optional[int] = None,
word_count_threshold: Optional[int] = None
) -> dict[str, list[Document]]
top_k: int | None = None,
word_count_threshold: int | None = None) -> dict[str, list[Document]]
```
Reranks documents based on the "lost in the middle" order.
@@ -306,13 +305,12 @@ assert docs[0].content == "Barcelona"
```python
def __init__(meta_field: str,
weight: float = 1.0,
top_k: Optional[int] = None,
top_k: int | None = None,
ranking_mode: Literal["reciprocal_rank_fusion",
"linear_score"] = "reciprocal_rank_fusion",
sort_order: Literal["ascending", "descending"] = "descending",
missing_meta: Literal["drop", "top", "bottom"] = "bottom",
meta_value_type: Optional[Literal["float", "int",
"date"]] = None)
meta_value_type: Literal["float", "int", "date"] | None = None)
```
Creates an instance of MetaFieldRanker.
@@ -355,13 +353,13 @@ The available options are:
```python
@component.output_types(documents=list[Document])
def run(documents: list[Document],
top_k: Optional[int] = None,
weight: Optional[float] = None,
ranking_mode: Optional[Literal["reciprocal_rank_fusion",
"linear_score"]] = None,
sort_order: Optional[Literal["ascending", "descending"]] = None,
missing_meta: Optional[Literal["drop", "top", "bottom"]] = None,
meta_value_type: Optional[Literal["float", "int", "date"]] = None)
top_k: int | None = None,
weight: float | None = None,
ranking_mode: Literal["reciprocal_rank_fusion", "linear_score"]
| None = None,
sort_order: Literal["ascending", "descending"] | None = None,
missing_meta: Literal["drop", "top", "bottom"] | None = None,
meta_value_type: Literal["float", "int", "date"] | None = None)
```
Ranks a list of Documents based on the selected meta field by:
@@ -477,8 +475,8 @@ print(result["documents"])
```python
def __init__(group_by: str,
subgroup_by: Optional[str] = None,
sort_docs_by: Optional[str] = None)
subgroup_by: str | None = None,
sort_docs_by: str | None = None)
```
Creates an instance of MetaFieldGroupingRanker.
@@ -617,26 +615,25 @@ docs = output["documents"]
#### SentenceTransformersDiversityRanker.\_\_init\_\_
```python
def __init__(
model: str = "sentence-transformers/all-MiniLM-L6-v2",
top_k: int = 10,
device: Optional[ComponentDevice] = None,
token: Optional[Secret] = Secret.from_env_var(
["HF_API_TOKEN", "HF_TOKEN"], strict=False),
similarity: Union[str, DiversityRankingSimilarity] = "cosine",
query_prefix: str = "",
query_suffix: str = "",
document_prefix: str = "",
document_suffix: str = "",
meta_fields_to_embed: Optional[list[str]] = None,
embedding_separator: str = "\n",
strategy: Union[str,
DiversityRankingStrategy] = "greedy_diversity_order",
lambda_threshold: float = 0.5,
model_kwargs: Optional[dict[str, Any]] = None,
tokenizer_kwargs: Optional[dict[str, Any]] = None,
config_kwargs: Optional[dict[str, Any]] = None,
backend: Literal["torch", "onnx", "openvino"] = "torch")
def __init__(model: str = "sentence-transformers/all-MiniLM-L6-v2",
top_k: int = 10,
device: ComponentDevice | None = None,
token: Secret | None = Secret.from_env_var(
["HF_API_TOKEN", "HF_TOKEN"], strict=False),
similarity: str | DiversityRankingSimilarity = "cosine",
query_prefix: str = "",
query_suffix: str = "",
document_prefix: str = "",
document_suffix: str = "",
meta_fields_to_embed: list[str] | None = None,
embedding_separator: str = "\n",
strategy: str
| DiversityRankingStrategy = "greedy_diversity_order",
lambda_threshold: float = 0.5,
model_kwargs: dict[str, Any] | None = None,
tokenizer_kwargs: dict[str, Any] | None = None,
config_kwargs: dict[str, Any] | None = None,
backend: Literal["torch", "onnx", "openvino"] = "torch")
```
Initialize a SentenceTransformersDiversityRanker.
@@ -726,8 +723,8 @@ The deserialized component.
@component.output_types(documents=list[Document])
def run(query: str,
documents: list[Document],
top_k: Optional[int] = None,
lambda_threshold: Optional[float] = None) -> dict[str, list[Document]]
top_k: int | None = None,
lambda_threshold: float | None = None) -> dict[str, list[Document]]
```
Rank the documents based on their diversity.
@@ -782,23 +779,23 @@ print(docs[0].content)
```python
def __init__(*,
model: Union[str, Path] = "cross-encoder/ms-marco-MiniLM-L-6-v2",
device: Optional[ComponentDevice] = None,
token: Optional[Secret] = Secret.from_env_var(
model: str | Path = "cross-encoder/ms-marco-MiniLM-L-6-v2",
device: ComponentDevice | None = None,
token: Secret | None = Secret.from_env_var(
["HF_API_TOKEN", "HF_TOKEN"], strict=False),
top_k: int = 10,
query_prefix: str = "",
query_suffix: str = "",
document_prefix: str = "",
document_suffix: str = "",
meta_fields_to_embed: Optional[list[str]] = None,
meta_fields_to_embed: list[str] | None = None,
embedding_separator: str = "\n",
scale_score: bool = True,
score_threshold: Optional[float] = None,
score_threshold: float | None = None,
trust_remote_code: bool = False,
model_kwargs: Optional[dict[str, Any]] = None,
tokenizer_kwargs: Optional[dict[str, Any]] = None,
config_kwargs: Optional[dict[str, Any]] = None,
model_kwargs: dict[str, Any] | None = None,
tokenizer_kwargs: dict[str, Any] | None = None,
config_kwargs: dict[str, Any] | None = None,
backend: Literal["torch", "onnx", "openvino"] = "torch",
batch_size: int = 16)
```
@@ -894,9 +891,9 @@ Deserialized component.
def run(*,
query: str,
documents: list[Document],
top_k: Optional[int] = None,
scale_score: Optional[bool] = None,
score_threshold: Optional[float] = None) -> dict[str, list[Document]]
top_k: int | None = None,
scale_score: bool | None = None,
score_threshold: float | None = None) -> dict[str, list[Document]]
```
Returns a list of documents ranked by their similarity to the given query.
@@ -960,20 +957,20 @@ print(docs[0].content)
#### TransformersSimilarityRanker.\_\_init\_\_
```python
def __init__(model: Union[str, Path] = "cross-encoder/ms-marco-MiniLM-L-6-v2",
device: Optional[ComponentDevice] = None,
token: Optional[Secret] = Secret.from_env_var(
def __init__(model: str | Path = "cross-encoder/ms-marco-MiniLM-L-6-v2",
device: ComponentDevice | None = None,
token: Secret | None = Secret.from_env_var(
["HF_API_TOKEN", "HF_TOKEN"], strict=False),
top_k: int = 10,
query_prefix: str = "",
document_prefix: str = "",
meta_fields_to_embed: Optional[list[str]] = None,
meta_fields_to_embed: list[str] | None = None,
embedding_separator: str = "\n",
scale_score: bool = True,
calibration_factor: Optional[float] = 1.0,
score_threshold: Optional[float] = None,
model_kwargs: Optional[dict[str, Any]] = None,
tokenizer_kwargs: Optional[dict[str, Any]] = None,
calibration_factor: float | None = 1.0,
score_threshold: float | None = None,
model_kwargs: dict[str, Any] | None = None,
tokenizer_kwargs: dict[str, Any] | None = None,
batch_size: int = 16)
```
@@ -1059,10 +1056,10 @@ Deserialized component.
@component.output_types(documents=list[Document])
def run(query: str,
documents: list[Document],
top_k: Optional[int] = None,
scale_score: Optional[bool] = None,
calibration_factor: Optional[float] = None,
score_threshold: Optional[float] = None)
top_k: int | None = None,
scale_score: bool | None = None,
calibration_factor: float | None = None,
score_threshold: float | None = None)
```
Returns a list of documents ranked by their similarity to the given query.
@@ -43,20 +43,20 @@ assert "Python" in result["answers"][0].data
#### ExtractiveReader.\_\_init\_\_
```python
def __init__(model: Union[Path, str] = "deepset/roberta-base-squad2-distilled",
device: Optional[ComponentDevice] = None,
token: Optional[Secret] = Secret.from_env_var(
def __init__(model: Path | str = "deepset/roberta-base-squad2-distilled",
device: ComponentDevice | None = None,
token: Secret | None = Secret.from_env_var(
["HF_API_TOKEN", "HF_TOKEN"], strict=False),
top_k: int = 20,
score_threshold: Optional[float] = None,
score_threshold: float | None = None,
max_seq_length: int = 384,
stride: int = 128,
max_batch_size: Optional[int] = None,
answers_per_seq: Optional[int] = None,
max_batch_size: int | None = None,
answers_per_seq: int | None = None,
no_answer: bool = True,
calibration_factor: float = 0.1,
overlap_threshold: Optional[float] = 0.01,
model_kwargs: Optional[dict[str, Any]] = None) -> None
overlap_threshold: float | None = 0.01,
model_kwargs: dict[str, Any] | None = None) -> None
```
Creates an instance of ExtractiveReader.
@@ -138,7 +138,7 @@ Initializes the component.
```python
def deduplicate_by_overlap(
answers: list[ExtractedAnswer],
overlap_threshold: Optional[float]) -> list[ExtractedAnswer]
overlap_threshold: float | None) -> list[ExtractedAnswer]
```
De-duplicates overlapping Extractive Answers.
@@ -168,14 +168,14 @@ List of deduplicated answers.
@component.output_types(answers=list[ExtractedAnswer])
def run(query: str,
documents: list[Document],
top_k: Optional[int] = None,
score_threshold: Optional[float] = None,
max_seq_length: Optional[int] = None,
stride: Optional[int] = None,
max_batch_size: Optional[int] = None,
answers_per_seq: Optional[int] = None,
no_answer: Optional[bool] = None,
overlap_threshold: Optional[float] = None)
top_k: int | None = None,
score_threshold: float | None = None,
max_seq_length: int | None = None,
stride: int | None = None,
max_batch_size: int | None = None,
answers_per_seq: int | None = None,
no_answer: bool | None = None,
overlap_threshold: float | None = None)
```
Locates and extracts answers from the given Documents using the given query.
@@ -193,7 +193,7 @@ print(result["documents"])
```python
def __init__(document_store: DocumentStore,
filters: Optional[dict[str, Any]] = None)
filters: dict[str, Any] | None = None)
```
Create the FilterRetriever component.
@@ -242,7 +242,7 @@ The deserialized component.
```python
@component.output_types(documents=list[Document])
def run(filters: Optional[dict[str, Any]] = None)
def run(filters: dict[str, Any] | None = None)
```
Run the FilterRetriever on the given input data.
@@ -262,7 +262,7 @@ A list of retrieved documents.
```python
@component.output_types(documents=list[Document])
async def run_async(filters: Optional[dict[str, Any]] = None)
async def run_async(filters: dict[str, Any] | None = None)
```
Asynchronously run the FilterRetriever on the given input data.
@@ -315,7 +315,7 @@ print(result["documents"])
```python
def __init__(document_store: InMemoryDocumentStore,
filters: Optional[dict[str, Any]] = None,
filters: dict[str, Any] | None = None,
top_k: int = 10,
scale_score: bool = False,
filter_policy: FilterPolicy = FilterPolicy.REPLACE)
@@ -380,9 +380,9 @@ The deserialized component.
```python
@component.output_types(documents=list[Document])
def run(query: str,
filters: Optional[dict[str, Any]] = None,
top_k: Optional[int] = None,
scale_score: Optional[bool] = None)
filters: dict[str, Any] | None = None,
top_k: int | None = None,
scale_score: bool | None = None)
```
Run the InMemoryBM25Retriever on the given input data.
@@ -410,9 +410,9 @@ The retrieved documents.
```python
@component.output_types(documents=list[Document])
async def run_async(query: str,
filters: Optional[dict[str, Any]] = None,
top_k: Optional[int] = None,
scale_score: Optional[bool] = None)
filters: dict[str, Any] | None = None,
top_k: int | None = None,
scale_score: bool | None = None)
```
Run the InMemoryBM25Retriever on the given input data.
@@ -484,7 +484,7 @@ print(result["documents"])
```python
def __init__(document_store: InMemoryDocumentStore,
filters: Optional[dict[str, Any]] = None,
filters: dict[str, Any] | None = None,
top_k: int = 10,
scale_score: bool = False,
return_embedding: bool = False,
@@ -552,10 +552,10 @@ The deserialized component.
```python
@component.output_types(documents=list[Document])
def run(query_embedding: list[float],
filters: Optional[dict[str, Any]] = None,
top_k: Optional[int] = None,
scale_score: Optional[bool] = None,
return_embedding: Optional[bool] = None)
filters: dict[str, Any] | None = None,
top_k: int | None = None,
scale_score: bool | None = None,
return_embedding: bool | None = None)
```
Run the InMemoryEmbeddingRetriever on the given input data.
@@ -585,10 +585,10 @@ The retrieved documents.
```python
@component.output_types(documents=list[Document])
async def run_async(query_embedding: list[float],
filters: Optional[dict[str, Any]] = None,
top_k: Optional[int] = None,
scale_score: Optional[bool] = None,
return_embedding: Optional[bool] = None)
filters: dict[str, Any] | None = None,
top_k: int | None = None,
scale_score: bool | None = None,
return_embedding: bool | None = None)
```
Run the InMemoryEmbeddingRetriever on the given input data.
@@ -713,7 +713,7 @@ Warm up the query embedder and the retriever if any has a warm_up method.
@component.output_types(documents=list[Document])
def run(
queries: list[str],
retriever_kwargs: Optional[dict[str, Any]] = None
retriever_kwargs: dict[str, Any] | None = None
) -> dict[str, list[Document]]
```
@@ -844,7 +844,7 @@ Warm up the retriever if it has a warm_up method.
@component.output_types(documents=list[Document])
def run(
queries: list[str],
retriever_kwargs: Optional[dict[str, Any]] = None
retriever_kwargs: dict[str, Any] | None = None
) -> dict[str, list[Document]]
```
@@ -976,7 +976,7 @@ rag.run({'bm25_retriever': {"query":"third"}})
def __init__(document_store: DocumentStore,
window_size: int = 3,
*,
source_id_meta_field: Union[str, list[str]] = "source_id",
source_id_meta_field: str | list[str] = "source_id",
split_id_meta_field: str = "split_id",
raise_on_missing_meta_fields: bool = True)
```
@@ -1050,8 +1050,7 @@ Deserialized component.
```python
@component.output_types(context_windows=list[str],
context_documents=list[Document])
def run(retrieved_documents: list[Document],
window_size: Optional[int] = None)
def run(retrieved_documents: list[Document], window_size: int | None = None)
```
Based on the `source_id` and on the `doc.meta['split_id']` get surrounding documents from the document store.
@@ -1082,7 +1081,7 @@ A dictionary with the following keys:
@component.output_types(context_windows=list[str],
context_documents=list[Document])
async def run_async(retrieved_documents: list[Document],
window_size: Optional[int] = None)
window_size: int | None = None)
```
Based on the `source_id` and on the `doc.meta['split_id']` get surrounding documents from the document store.
@@ -111,10 +111,10 @@ print(result)
```python
def __init__(routes: list[Route],
custom_filters: Optional[dict[str, Callable]] = None,
custom_filters: dict[str, Callable] | None = None,
unsafe: bool = False,
validate_output_type: bool = False,
optional_variables: Optional[list[str]] = None)
optional_variables: list[str] | None = None)
```
Initializes the `ConditionalRouter` with a list of routes detailing the conditions for routing.
@@ -373,9 +373,9 @@ Expected output:
```python
def __init__(*,
mime_types: list[str],
mime_type_meta_field: Optional[str] = None,
file_path_meta_field: Optional[str] = None,
additional_mimetypes: Optional[dict[str, str]] = None) -> None
mime_type_meta_field: str | None = None,
file_path_meta_field: str | None = None,
additional_mimetypes: dict[str, str] | None = None) -> None
```
Initialize the DocumentTypeRouter component.
@@ -465,7 +465,7 @@ print(router_with_regex.run(sources=sources))
```python
def __init__(mime_types: list[str],
additional_mimetypes: Optional[dict[str, str]] = None,
additional_mimetypes: dict[str, str] | None = None,
raise_on_failure: bool = False)
```
@@ -520,9 +520,9 @@ The deserialized component.
```python
def run(
sources: list[Union[str, Path, ByteStream]],
meta: Optional[Union[dict[str, Any], list[dict[str, Any]]]] = None
) -> dict[str, list[Union[ByteStream, Path]]]
sources: list[str | Path | ByteStream],
meta: dict[str, Any] | list[dict[str, Any]] | None = None
) -> dict[str, list[ByteStream | Path]]
```
Categorize files or byte streams according to their MIME types.
@@ -595,7 +595,7 @@ S2',
def __init__(chat_generator: ChatGenerator,
output_names: list[str],
output_patterns: list[str],
system_prompt: Optional[str] = None)
system_prompt: str | None = None)
```
Initialize the LLMMessagesRouter component.
@@ -630,8 +630,7 @@ Warm up the underlying LLM.
#### LLMMessagesRouter.run
```python
def run(messages: list[ChatMessage]
) -> dict[str, Union[str, list[ChatMessage]]]
def run(messages: list[ChatMessage]) -> dict[str, str | list[ChatMessage]]
```
Classify the messages based on LLM output and route them to the appropriate output connection.
@@ -790,7 +789,7 @@ For example:
#### MetadataRouter.run
```python
def run(documents: Union[list[Document], list[ByteStream]])
def run(documents: list[Document] | list[ByteStream])
```
Routes documents or byte streams to different connections based on their metadata fields.
@@ -882,7 +881,7 @@ assert result["text_language_router"]["unmatched"] == "ένα ελληνικό
#### TextLanguageRouter.\_\_init\_\_
```python
def __init__(languages: Optional[list[str]] = None)
def __init__(languages: list[str] | None = None)
```
Initialize the TextLanguageRouter component.
@@ -979,11 +978,11 @@ print(p.run({"text_router": {"text": "Was ist die Hauptstadt von Deutschland?"}}
```python
def __init__(model: str,
labels: Optional[list[str]] = None,
device: Optional[ComponentDevice] = None,
token: Optional[Secret] = Secret.from_env_var(
labels: list[str] | None = None,
device: ComponentDevice | None = None,
token: Secret | None = Secret.from_env_var(
["HF_API_TOKEN", "HF_TOKEN"], strict=False),
huggingface_pipeline_kwargs: Optional[dict[str, Any]] = None)
huggingface_pipeline_kwargs: dict[str, Any] | None = None)
```
Initializes the TransformersTextRouter component.
@@ -1151,10 +1150,10 @@ p.run({
def __init__(labels: list[str],
multi_label: bool = False,
model: str = "MoritzLaurer/deberta-v3-base-zeroshot-v1.1-all-33",
device: Optional[ComponentDevice] = None,
token: Optional[Secret] = Secret.from_env_var(
device: ComponentDevice | None = None,
token: Secret | None = Secret.from_env_var(
["HF_API_TOKEN", "HF_TOKEN"], strict=False),
huggingface_pipeline_kwargs: Optional[dict[str, Any]] = None)
huggingface_pipeline_kwargs: dict[str, Any] | None = None)
```
Initializes the TransformersZeroShotTextRouter component.
@@ -43,8 +43,8 @@ assert docs[0].content == "Sarajevo"
```python
def __init__(top_p: float = 1.0,
score_field: Optional[str] = None,
min_top_k: Optional[int] = None)
score_field: str | None = None,
min_top_k: int | None = None)
```
Creates an instance of TopPSampler.
@@ -64,7 +64,7 @@ fewer documents, additional ones with the next highest scores are added to the s
```python
@component.output_types(documents=list[Document])
def run(documents: list[Document], top_p: Optional[float] = None)
def run(documents: list[Document], top_p: float | None = None)
```
Filters documents using top-p sampling based on their scores.
@@ -156,7 +156,7 @@ print(result)
def __init__(tools: ToolsType,
raise_on_failure: bool = True,
convert_result_to_json_string: bool = False,
streaming_callback: Optional[StreamingCallbackT] = None,
streaming_callback: StreamingCallbackT | None = None,
*,
enable_streaming_callback_passthrough: bool = False,
max_workers: int = 4)
@@ -207,11 +207,11 @@ This method is idempotent and will only warm up the tools once.
```python
@component.output_types(tool_messages=list[ChatMessage], state=State)
def run(messages: list[ChatMessage],
state: Optional[State] = None,
streaming_callback: Optional[StreamingCallbackT] = None,
state: State | None = None,
streaming_callback: StreamingCallbackT | None = None,
*,
enable_streaming_callback_passthrough: Optional[bool] = None,
tools: Optional[ToolsType] = None) -> dict[str, Any]
enable_streaming_callback_passthrough: bool | None = None,
tools: ToolsType | None = None) -> dict[str, Any]
```
Processes ChatMessage objects containing tool calls and invokes the corresponding tools, if available.
@@ -249,13 +249,12 @@ Each ChatMessage objects wraps the result of a tool invocation.
```python
@component.output_types(tool_messages=list[ChatMessage], state=State)
async def run_async(
messages: list[ChatMessage],
state: Optional[State] = None,
streaming_callback: Optional[StreamingCallbackT] = None,
*,
enable_streaming_callback_passthrough: Optional[bool] = None,
tools: Optional[ToolsType] = None) -> dict[str, Any]
async def run_async(messages: list[ChatMessage],
state: State | None = None,
streaming_callback: StreamingCallbackT | None = None,
*,
enable_streaming_callback_passthrough: bool | None = None,
tools: ToolsType | None = None) -> dict[str, Any]
```
Asynchronously processes ChatMessage objects containing tool calls.
@@ -78,15 +78,13 @@ print(result)
```python
def __init__(
component: Component,
name: Optional[str] = None,
description: Optional[str] = None,
parameters: Optional[dict[str, Any]] = None,
name: str | None = None,
description: str | None = None,
parameters: dict[str, Any] | None = None,
*,
outputs_to_string: Optional[dict[str, Union[str, Callable[[Any],
str]]]] = None,
inputs_from_state: Optional[dict[str, str]] = None,
outputs_to_state: Optional[dict[str, dict[str, Union[str,
Callable]]]] = None
outputs_to_string: dict[str, str | Callable[[Any], str]] | None = None,
inputs_from_state: dict[str, str] | None = None,
outputs_to_state: dict[str, dict[str, str | Callable]] | None = None
) -> None
```
@@ -193,11 +191,10 @@ Invoke the Tool with the provided keyword arguments.
```python
def create_tool_from_function(
function: Callable,
name: Optional[str] = None,
description: Optional[str] = None,
inputs_from_state: Optional[dict[str, str]] = None,
outputs_to_state: Optional[dict[str, dict[str,
Any]]] = None) -> "Tool"
name: str | None = None,
description: str | None = None,
inputs_from_state: dict[str, str] | None = None,
outputs_to_state: dict[str, dict[str, Any]] | None = None) -> "Tool"
```
Create a Tool instance from a function.
@@ -272,13 +269,13 @@ The Tool created from the function.
```python
def tool(
function: Optional[Callable] = None,
function: Callable | None = None,
*,
name: Optional[str] = None,
description: Optional[str] = None,
inputs_from_state: Optional[dict[str, str]] = None,
outputs_to_state: Optional[dict[str, dict[str, Any]]] = None
) -> Union[Tool, Callable[[Callable], Tool]]
name: str | None = None,
description: str | None = None,
inputs_from_state: dict[str, str] | None = None,
outputs_to_state: dict[str, dict[str, Any]] | None = None
) -> Tool | Callable[[Callable], Tool]
```
Decorator to convert a function into a Tool.
@@ -85,7 +85,7 @@ Create a token-based secret. Cannot be serialized.
```python
@staticmethod
def from_env_var(env_vars: Union[str, list[str]],
def from_env_var(env_vars: str | list[str],
*,
strict: bool = True) -> "Secret"
```
@@ -142,7 +142,7 @@ The deserialized secret.
```python
@abstractmethod
def resolve_value() -> Optional[Any]
def resolve_value() -> Any | None
```
Resolve the secret to an atomic value. The semantics of the value is secret-dependent.
@@ -407,7 +407,7 @@ A generic representation of a device.
#### Device.\_\_init\_\_
```python
def __init__(type: DeviceType, id: Optional[int] = None)
def __init__(type: DeviceType, id: int | None = None)
```
Create a generic device.
@@ -544,7 +544,7 @@ The serialized mapping.
```python
@property
def first_device() -> Optional[Device]
def first_device() -> Device | None
```
Return the first device in the mapping, if any.
@@ -715,7 +715,7 @@ The spaCy device representation.
#### ComponentDevice.to\_hf
```python
def to_hf() -> Union[Union[int, str], dict[str, Union[int, str]]]
def to_hf() -> int | str | dict[str, int | str]
```
Convert the component device representation to HuggingFace format.
@@ -835,7 +835,7 @@ The deserialized component device.
```python
def raise_on_invalid_filter_syntax(
filters: Optional[dict[str, Any]] = None) -> None
filters: dict[str, Any] | None = None) -> None
```
Raise an error if the filter syntax is invalid.
@@ -846,7 +846,7 @@ Raise an error if the filter syntax is invalid.
```python
def document_matches_filter(filters: dict[str, Any],
document: Union[Document, ByteStream]) -> bool
document: Document | ByteStream) -> bool
```
Return whether `filters` match the Document or the ByteStream.
@@ -864,9 +864,8 @@ For a detailed specification of the filters, refer to the
```python
def init_http_client(
http_client_kwargs: Optional[dict[str, Any]] = None,
async_client: bool = False
) -> Union[httpx.Client, httpx.AsyncClient, None]
http_client_kwargs: dict[str, Any] | None = None,
async_client: bool = False) -> httpx.Client | httpx.AsyncClient | None
```
Initialize an httpx client based on the http_client_kwargs.
@@ -925,7 +924,7 @@ Hello! I am {{user_name}}. Please describe the images.
#### ChatMessageExtension.parse
```python
def parse(parser: Any) -> Union[nodes.Node, list[nodes.Node]]
def parse(parser: Any) -> nodes.Node | list[nodes.Node]
```
Parse the message tag and its attributes in the Jinja2 template.
@@ -994,7 +993,7 @@ It provides the context where the extension will operate.
#### Jinja2TimeExtension.parse
```python
def parse(parser: Any) -> Union[nodes.Node, list[nodes.Node]]
def parse(parser: Any) -> nodes.Node | list[nodes.Node]
```
Parse the template expression to determine how to handle the datetime formatting.
@@ -1027,7 +1026,7 @@ Returns `True` if in Jupyter or Google Colab, `False` otherwise.
#### expand\_page\_range
```python
def expand_page_range(page_range: list[Union[str, int]]) -> list[int]
def expand_page_range(page_range: list[str | int]) -> list[int]
```
Takes a list of page numbers and ranges and expands them into a list of page numbers.
@@ -1047,8 +1046,7 @@ An expanded list of page integers
#### expit
```python
def expit(
x: Union[float, ndarray[Any, Any]]) -> Union[float, ndarray[Any, Any]]
def expit(x: float | ndarray[Any, Any]) -> float | ndarray[Any, Any]
```
Compute logistic sigmoid function. Maps input values to a range between 0 and 1
@@ -1067,7 +1065,7 @@ Compute logistic sigmoid function. Maps input values to a range between 0 and 1
```python
def request_with_retry(attempts: int = 3,
status_codes_to_retry: Optional[list[int]] = None,
status_codes_to_retry: list[int] | None = None,
**kwargs: Any) -> requests.Response
```
@@ -1131,8 +1129,8 @@ The `Response` object.
```python
async def async_request_with_retry(attempts: int = 3,
status_codes_to_retry: Optional[
list[int]] = None,
status_codes_to_retry: list[int]
| None = None,
**kwargs: Any) -> httpx.Response
```
@@ -93,8 +93,8 @@ _name=None, _meta={'model': 'gpt-4-1106-preview', 'index': 0,
#### JsonSchemaValidator.\_\_init\_\_
```python
def __init__(json_schema: Optional[dict[str, Any]] = None,
error_template: Optional[str] = None)
def __init__(json_schema: dict[str, Any] | None = None,
error_template: str | None = None)
```
Initialize the JsonSchemaValidator component.
@@ -113,8 +113,8 @@ the messages' content is validated.
@component.output_types(validated=list[ChatMessage],
validation_error=list[ChatMessage])
def run(messages: list[ChatMessage],
json_schema: Optional[dict[str, Any]] = None,
error_template: Optional[str] = None) -> dict[str, list[ChatMessage]]
json_schema: dict[str, Any] | None = None,
error_template: str | None = None) -> dict[str, list[ChatMessage]]
```
Validates the last of the provided messages against the specified json schema.
@@ -33,9 +33,9 @@ assert results["links"]
```python
def __init__(api_key: Secret = Secret.from_env_var("SEARCHAPI_API_KEY"),
top_k: Optional[int] = 10,
allowed_domains: Optional[list[str]] = None,
search_params: Optional[dict[str, Any]] = None)
top_k: int | None = 10,
allowed_domains: list[str] | None = None,
search_params: dict[str, Any] | None = None)
```
Initialize the SearchApiWebSearch component.
@@ -91,7 +91,7 @@ The deserialized component.
```python
@component.output_types(documents=list[Document], links=list[str])
def run(query: str) -> dict[str, Union[list[Document], list[str]]]
def run(query: str) -> dict[str, list[Document] | list[str]]
```
Uses [SearchApi](https://www.searchapi.io/) to search the web.
@@ -150,9 +150,9 @@ results_filtered = websearch_filtered.run(query="search query")
```python
def __init__(api_key: Secret = Secret.from_env_var("SERPERDEV_API_KEY"),
top_k: Optional[int] = 10,
allowed_domains: Optional[list[str]] = None,
search_params: Optional[dict[str, Any]] = None,
top_k: int | None = 10,
allowed_domains: list[str] | None = None,
search_params: dict[str, Any] | None = None,
*,
exclude_subdomains: bool = False)
```
@@ -206,7 +206,7 @@ Dictionary with serialized data.
```python
@component.output_types(documents=list[Document], links=list[str])
def run(query: str) -> dict[str, Union[list[Document], list[str]]]
def run(query: str) -> dict[str, list[Document] | list[str]]
```
Use [Serper](https://serper.dev/) to search the web.