|
2 | 2 | import uuid
|
3 | 3 | import time
|
4 | 4 | import multiprocessing
|
5 |
| -from typing import List, Optional, Union, Generator, Sequence |
| 5 | +from typing import List, Optional, Union, Generator, Sequence, Iterator |
6 | 6 | from collections import deque
|
7 | 7 |
|
8 | 8 | from . import llama_cpp
|
@@ -286,10 +286,7 @@ def _create_completion(
|
286 | 286 | repeat_penalty: float = 1.1,
|
287 | 287 | top_k: int = 40,
|
288 | 288 | stream: bool = False,
|
289 |
| - ) -> Union[ |
290 |
| - Generator[Completion, None, None], |
291 |
| - Generator[CompletionChunk, None, None], |
292 |
| - ]: |
| 289 | + ) -> Union[Iterator[Completion], Iterator[CompletionChunk],]: |
293 | 290 | assert self.ctx is not None
|
294 | 291 | completion_id = f"cmpl-{str(uuid.uuid4())}"
|
295 | 292 | created = int(time.time())
|
@@ -428,7 +425,7 @@ def create_completion(
|
428 | 425 | repeat_penalty: float = 1.1,
|
429 | 426 | top_k: int = 40,
|
430 | 427 | stream: bool = False,
|
431 |
| - ) -> Union[Completion, Generator[CompletionChunk, None, None]]: |
| 428 | + ) -> Union[Completion, Iterator[CompletionChunk]]: |
432 | 429 | """Generate text from a prompt.
|
433 | 430 |
|
434 | 431 | Args:
|
@@ -465,7 +462,7 @@ def create_completion(
|
465 | 462 | stream=stream,
|
466 | 463 | )
|
467 | 464 | if stream:
|
468 |
| - chunks: Generator[CompletionChunk, None, None] = completion_or_chunks |
| 465 | + chunks: Iterator[CompletionChunk] = completion_or_chunks |
469 | 466 | return chunks
|
470 | 467 | completion: Completion = next(completion_or_chunks) # type: ignore
|
471 | 468 | return completion
|
|
0 commit comments