|
1 | 1 | import json |
2 | | -from collections.abc import AsyncIterator, Iterator |
3 | | -from typing import Any, Callable, Literal, Optional, Union |
| 2 | +from collections.abc import AsyncIterator, Callable, Iterator |
| 3 | +from typing import Any, Literal |
4 | 4 |
|
5 | 5 | from haystack import component, default_from_dict, default_to_dict |
6 | 6 | from haystack.dataclasses import ( |
@@ -212,13 +212,13 @@ def __init__( |
212 | 212 | self, |
213 | 213 | model: str = "qwen3:0.6b", |
214 | 214 | url: str = "http://localhost:11434", |
215 | | - generation_kwargs: Optional[dict[str, Any]] = None, |
| 215 | + generation_kwargs: dict[str, Any] | None = None, |
216 | 216 | timeout: int = 120, |
217 | | - keep_alive: Optional[Union[float, str]] = None, |
218 | | - streaming_callback: Optional[Callable[[StreamingChunk], None]] = None, |
219 | | - tools: Optional[ToolsType] = None, |
220 | | - response_format: Optional[Union[None, Literal["json"], JsonSchemaValue]] = None, |
221 | | - think: Union[bool, Literal["low", "medium", "high"]] = False, |
| 217 | + keep_alive: float | str | None = None, |
| 218 | + streaming_callback: Callable[[StreamingChunk], None] | None = None, |
| 219 | + tools: ToolsType | None = None, |
| 220 | + response_format: None | Literal["json"] | JsonSchemaValue | None = None, |
| 221 | + think: bool | Literal["low", "medium", "high"] = False, |
222 | 222 | ): |
223 | 223 | """ |
224 | 224 | :param model: |
@@ -315,7 +315,7 @@ def from_dict(cls, data: dict[str, Any]) -> "OllamaChatGenerator": |
315 | 315 | def _handle_streaming_response( |
316 | 316 | self, |
317 | 317 | response_iter: Iterator[ChatResponse], |
318 | | - callback: Optional[SyncStreamingCallbackT], |
| 318 | + callback: SyncStreamingCallbackT | None, |
319 | 319 | ) -> dict[str, list[ChatMessage]]: |
320 | 320 | """ |
321 | 321 | Merge an Ollama streaming response into a single ChatMessage, preserving |
@@ -399,7 +399,7 @@ def _handle_streaming_response( |
399 | 399 | async def _handle_streaming_response_async( |
400 | 400 | self, |
401 | 401 | response_iter: AsyncIterator[ChatResponse], |
402 | | - callback: Optional[AsyncStreamingCallbackT], |
| 402 | + callback: AsyncStreamingCallbackT | None, |
403 | 403 | ) -> dict[str, list[ChatMessage]]: |
404 | 404 | """ |
405 | 405 | Merge an Ollama async streaming response into a single ChatMessage, preserving |
@@ -471,10 +471,10 @@ async def _handle_streaming_response_async( |
471 | 471 | def run( |
472 | 472 | self, |
473 | 473 | messages: list[ChatMessage], |
474 | | - generation_kwargs: Optional[dict[str, Any]] = None, |
475 | | - tools: Optional[ToolsType] = None, |
| 474 | + generation_kwargs: dict[str, Any] | None = None, |
| 475 | + tools: ToolsType | None = None, |
476 | 476 | *, |
477 | | - streaming_callback: Optional[StreamingCallbackT] = None, |
| 477 | + streaming_callback: StreamingCallbackT | None = None, |
478 | 478 | ) -> dict[str, list[ChatMessage]]: |
479 | 479 | """ |
480 | 480 | Runs an Ollama Model on a given chat history. |
@@ -537,10 +537,10 @@ def run( |
537 | 537 | async def run_async( |
538 | 538 | self, |
539 | 539 | messages: list[ChatMessage], |
540 | | - generation_kwargs: Optional[dict[str, Any]] = None, |
541 | | - tools: Optional[ToolsType] = None, |
| 540 | + generation_kwargs: dict[str, Any] | None = None, |
| 541 | + tools: ToolsType | None = None, |
542 | 542 | *, |
543 | | - streaming_callback: Optional[StreamingCallbackT] = None, |
| 543 | + streaming_callback: StreamingCallbackT | None = None, |
544 | 544 | ) -> dict[str, list[ChatMessage]]: |
545 | 545 | """ |
546 | 546 | Async version of run. Runs an Ollama Model on a given chat history. |
|
0 commit comments