mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-24 03:52:10 +00:00
core: Improve Runnable __or__
method typing annotations (#31273)
* It is possible to chain a `Runnable` with an `AsyncIterator` as seen in `test_runnable.py`. * Iterator and AsyncIterator Input/Output of Callables must be put before `Callable[[Other], Any]` otherwise the pattern matching picks the latter.
This commit is contained in:
committed by
GitHub
parent
e1af509966
commit
17c5a1621f
@@ -1,6 +1,6 @@
|
||||
"""Structured prompt template for a language model."""
|
||||
|
||||
from collections.abc import Iterator, Mapping, Sequence
|
||||
from collections.abc import AsyncIterator, Iterator, Mapping, Sequence
|
||||
from typing import (
|
||||
Any,
|
||||
Callable,
|
||||
@@ -123,8 +123,9 @@ class StructuredPrompt(ChatPromptTemplate):
|
||||
self,
|
||||
other: Union[
|
||||
Runnable[Any, Other],
|
||||
Callable[[Any], Other],
|
||||
Callable[[Iterator[Any]], Iterator[Other]],
|
||||
Callable[[AsyncIterator[Any]], AsyncIterator[Other]],
|
||||
Callable[[Any], Other],
|
||||
Mapping[str, Union[Runnable[Any, Other], Callable[[Any], Other], Any]],
|
||||
],
|
||||
) -> RunnableSerializable[dict, Other]:
|
||||
@@ -134,8 +135,9 @@ class StructuredPrompt(ChatPromptTemplate):
|
||||
self,
|
||||
*others: Union[
|
||||
Runnable[Any, Other],
|
||||
Callable[[Any], Other],
|
||||
Callable[[Iterator[Any]], Iterator[Other]],
|
||||
Callable[[AsyncIterator[Any]], AsyncIterator[Other]],
|
||||
Callable[[Any], Other],
|
||||
Mapping[str, Union[Runnable[Any, Other], Callable[[Any], Other], Any]],
|
||||
],
|
||||
name: Optional[str] = None,
|
||||
|
Reference in New Issue
Block a user