|
5 | 5 | import asyncio |
6 | 6 | import copy |
7 | 7 | from enum import Enum |
8 | | -from typing import Any, Awaitable, Callable, Dict, List, Optional, Union |
| 8 | +from typing import Any, Dict, List, Optional, Union |
9 | 9 |
|
10 | 10 | from haystack import logging |
11 | | -from haystack.dataclasses import ChatMessage, ComponentInfo, StreamingCallbackT, StreamingChunk |
| 11 | +from haystack.dataclasses import ( |
| 12 | + AsyncStreamingCallbackT, |
| 13 | + ChatMessage, |
| 14 | + ComponentInfo, |
| 15 | + StreamingChunk, |
| 16 | + SyncStreamingCallbackT, |
| 17 | +) |
12 | 18 | from haystack.lazy_imports import LazyImport |
13 | 19 | from haystack.utils.auth import Secret |
14 | 20 | from haystack.utils.device import ComponentDevice |
@@ -350,15 +356,15 @@ class HFTokenStreamingHandler(TextStreamer): |
350 | 356 | Streaming handler for HuggingFaceLocalGenerator and HuggingFaceLocalChatGenerator. |
351 | 357 |
|
352 | 358 | Note: This is a helper class for HuggingFaceLocalGenerator & HuggingFaceLocalChatGenerator enabling streaming |
353 | | - of generated text via Haystack StreamingCallbackT callbacks. |
| 359 | + of generated text via Haystack SyncStreamingCallbackT callbacks. |
354 | 360 |
|
355 | 361 | Do not use this class directly. |
356 | 362 | """ |
357 | 363 |
|
358 | 364 | def __init__( |
359 | 365 | self, |
360 | 366 | tokenizer: Union[PreTrainedTokenizer, PreTrainedTokenizerFast], |
361 | | - stream_handler: StreamingCallbackT, |
| 367 | + stream_handler: SyncStreamingCallbackT, |
362 | 368 | stop_words: Optional[List[str]] = None, |
363 | 369 | component_info: Optional[ComponentInfo] = None, |
364 | 370 | ): |
@@ -392,7 +398,7 @@ class AsyncHFTokenStreamingHandler(TextStreamer): |
392 | 398 | def __init__( |
393 | 399 | self, |
394 | 400 | tokenizer: Union[PreTrainedTokenizer, PreTrainedTokenizerFast], |
395 | | - stream_handler: Callable[[StreamingChunk], Awaitable[None]], |
| 401 | + stream_handler: AsyncStreamingCallbackT, |
396 | 402 | stop_words: Optional[List[str]] = None, |
397 | 403 | component_info: Optional[ComponentInfo] = None, |
398 | 404 | ): |
|
0 commit comments