mirror of
https://github.com/hwchase17/langchain
synced 2024-11-06 03:20:49 +00:00
Update base chain type hints (#7680)
Addresses #7578. `run()` can return dictionaries, Pydantic objects or strings, so the type hints should reflect that. See the chain from `create_structured_output_chain` for an example of a non-string return type from `run()`. I've updated the BaseLLMChain return type hint from `str` to `Any`. Although, the differences between `run()` and `__call__()` seem less clear now. CC: @baskaryan Co-authored-by: Bagatur <baskaryan@gmail.com>
This commit is contained in:
parent
e58b1d7073
commit
a7efa95775
@ -49,8 +49,8 @@ class Chain(Serializable, ABC):
|
|||||||
execute a Chain. This takes inputs as a dictionary and returns a
|
execute a Chain. This takes inputs as a dictionary and returns a
|
||||||
dictionary output.
|
dictionary output.
|
||||||
- `run`: A convenience method that takes inputs as args/kwargs and returns the
|
- `run`: A convenience method that takes inputs as args/kwargs and returns the
|
||||||
output as a string. This method can only be used for a subset of chains and
|
output as a string or object. This method can only be used for a subset of
|
||||||
cannot return as rich of an output as `__call__`.
|
chains and cannot return as rich of an output as `__call__`.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
memory: Optional[BaseMemory] = None
|
memory: Optional[BaseMemory] = None
|
||||||
@ -390,17 +390,13 @@ class Chain(Serializable, ABC):
|
|||||||
tags: Optional[List[str]] = None,
|
tags: Optional[List[str]] = None,
|
||||||
metadata: Optional[Dict[str, Any]] = None,
|
metadata: Optional[Dict[str, Any]] = None,
|
||||||
**kwargs: Any,
|
**kwargs: Any,
|
||||||
) -> str:
|
) -> Any:
|
||||||
"""Execute chain when there's a single string output.
|
"""Convenience method for executing chain.
|
||||||
|
|
||||||
The main difference between this method and `Chain.__call__` is that this method
|
The main difference between this method and `Chain.__call__` is that this
|
||||||
can only be used for chains that return a single string output. If a Chain
|
method expects inputs to be passed directly in as positional arguments or
|
||||||
has more outputs, a non-string output, or you want to return the inputs/run
|
keyword arguments, whereas `Chain.__call__` expects a single input dictionary
|
||||||
info along with the outputs, use `Chain.__call__`.
|
with all the inputs
|
||||||
|
|
||||||
The other difference is that this method expects inputs to be passed directly in
|
|
||||||
as positional arguments or keyword arguments, whereas `Chain.__call__` expects
|
|
||||||
a single input dictionary with all the inputs.
|
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
*args: If the chain expects a single input, it can be passed in as the
|
*args: If the chain expects a single input, it can be passed in as the
|
||||||
@ -415,7 +411,7 @@ class Chain(Serializable, ABC):
|
|||||||
directly as keyword arguments.
|
directly as keyword arguments.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
The chain output as a string.
|
The chain output.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
@ -464,17 +460,14 @@ class Chain(Serializable, ABC):
|
|||||||
tags: Optional[List[str]] = None,
|
tags: Optional[List[str]] = None,
|
||||||
metadata: Optional[Dict[str, Any]] = None,
|
metadata: Optional[Dict[str, Any]] = None,
|
||||||
**kwargs: Any,
|
**kwargs: Any,
|
||||||
) -> str:
|
) -> Any:
|
||||||
"""Execute chain when there's a single string output.
|
"""Convenience method for executing chain.
|
||||||
|
|
||||||
The main difference between this method and `Chain.__call__` is that this method
|
The main difference between this method and `Chain.__call__` is that this
|
||||||
can only be used for chains that return a single string output. If a Chain
|
method expects inputs to be passed directly in as positional arguments or
|
||||||
has more outputs, a non-string output, or you want to return the inputs/run
|
keyword arguments, whereas `Chain.__call__` expects a single input dictionary
|
||||||
info along with the outputs, use `Chain.__call__`.
|
with all the inputs
|
||||||
|
|
||||||
The other difference is that this method expects inputs to be passed directly in
|
|
||||||
as positional arguments or keyword arguments, whereas `Chain.__call__` expects
|
|
||||||
a single input dictionary with all the inputs.
|
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
*args: If the chain expects a single input, it can be passed in as the
|
*args: If the chain expects a single input, it can be passed in as the
|
||||||
@ -489,7 +482,7 @@ class Chain(Serializable, ABC):
|
|||||||
directly as keyword arguments.
|
directly as keyword arguments.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
The chain output as a string.
|
The chain output.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
Loading…
Reference in New Issue
Block a user