An async version of the _stream method. The default implementation uses the synchronous _stream method and wraps it in an async iterator. Subclasses that need to provide a true async implementation should override this method. Args: prompt: The prompt to
(
self,
prompt: str,
stop: Optional[List[str]] = None,
run_manager: Optional[AsyncCallbackManagerForLLMRun] = None,
**kwargs: Any,
)
| 579 | raise NotImplementedError() |
| 580 | |
| 581 | async def _astream( |
| 582 | self, |
| 583 | prompt: str, |
| 584 | stop: Optional[List[str]] = None, |
| 585 | run_manager: Optional[AsyncCallbackManagerForLLMRun] = None, |
| 586 | **kwargs: Any, |
| 587 | ) -> AsyncIterator[GenerationChunk]: |
| 588 | """An async version of the _stream method. |
| 589 | |
| 590 | The default implementation uses the synchronous _stream method and wraps it in |
| 591 | an async iterator. Subclasses that need to provide a true async implementation |
| 592 | should override this method. |
| 593 | |
| 594 | Args: |
| 595 | prompt: The prompt to generate from. |
| 596 | stop: Stop words to use when generating. Model output is cut off at the |
| 597 | first occurrence of any of these substrings. |
| 598 | run_manager: Callback manager for the run. |
| 599 | **kwargs: Arbitrary additional keyword arguments. These are usually passed |
| 600 | to the model provider API call. |
| 601 | |
| 602 | Returns: |
| 603 | An async iterator of GenerationChunks. |
| 604 | """ |
| 605 | iterator = await run_in_executor( |
| 606 | None, |
| 607 | self._stream, |
| 608 | prompt, |
| 609 | stop, |
| 610 | run_manager.get_sync() if run_manager else None, |
| 611 | **kwargs, |
| 612 | ) |
| 613 | done = object() |
| 614 | while True: |
| 615 | item = await run_in_executor( |
| 616 | None, |
| 617 | next, |
| 618 | iterator, |
| 619 | done, # type: ignore[call-arg, arg-type] |
| 620 | ) |
| 621 | if item is done: |
| 622 | break |
| 623 | yield item # type: ignore[misc] |
| 624 | |
| 625 | def generate_prompt( |
| 626 | self, |
no test coverage detected