mirror of
https://github.com/hwchase17/langchain.git
synced 2025-07-06 13:18:12 +00:00
Use immutable sequence type for batch/batch_as_completed types (#22433)
Thank you for contributing to LangChain! - [ ] **PR title**: "package: description" - Where "package" is whichever of langchain, community, core, experimental, etc. is being modified. Use "docs: ..." for purely docs changes, "templates: ..." for template changes, "infra: ..." for CI changes. - Example: "community: add foobar LLM" - [ ] **PR message**: ***Delete this entire checklist*** and replace with - **Description:** a description of the change - **Issue:** the issue # it fixes, if applicable - **Dependencies:** any dependencies required for this change - **Twitter handle:** if your PR gets announced, and you'd like a mention, we'll gladly shout you out! - [ ] **Add tests and docs**: If you're adding a new integration, please include 1. a test for the integration, preferably unit tests that do not rely on network access, 2. an example notebook showing its use. It lives in `docs/docs/integrations` directory. - [ ] **Lint and test**: Run `make format`, `make lint` and `make test` from the root of the package(s) you've modified. See contribution guidelines for more: https://python.langchain.com/docs/contributing/ Additional guidelines: - Make sure optional dependencies are imported within a function. - Please do not add dependencies to pyproject.toml files (even optional ones) unless they are required for unit tests. - Most PRs should not touch more than one package. - Changes should be backwards compatible. - If you are adding something to community, do not re-import it in langchain. If no one reviews your PR within a few days, please @-mention one of baskaryan, efriis, eyurtsev, ccurme, vbarda, hwchase17.
This commit is contained in:
parent
9a8fe58ebe
commit
58b118544e
@ -642,8 +642,8 @@ class Runnable(Generic[Input, Output], ABC):
|
|||||||
@overload
|
@overload
|
||||||
def batch_as_completed(
|
def batch_as_completed(
|
||||||
self,
|
self,
|
||||||
inputs: List[Input],
|
inputs: Sequence[Input],
|
||||||
config: Optional[Union[RunnableConfig, List[RunnableConfig]]] = None,
|
config: Optional[Union[RunnableConfig, Sequence[RunnableConfig]]] = None,
|
||||||
*,
|
*,
|
||||||
return_exceptions: Literal[False] = False,
|
return_exceptions: Literal[False] = False,
|
||||||
**kwargs: Any,
|
**kwargs: Any,
|
||||||
@ -653,8 +653,8 @@ class Runnable(Generic[Input, Output], ABC):
|
|||||||
@overload
|
@overload
|
||||||
def batch_as_completed(
|
def batch_as_completed(
|
||||||
self,
|
self,
|
||||||
inputs: List[Input],
|
inputs: Sequence[Input],
|
||||||
config: Optional[Union[RunnableConfig, List[RunnableConfig]]] = None,
|
config: Optional[Union[RunnableConfig, Sequence[RunnableConfig]]] = None,
|
||||||
*,
|
*,
|
||||||
return_exceptions: Literal[True],
|
return_exceptions: Literal[True],
|
||||||
**kwargs: Any,
|
**kwargs: Any,
|
||||||
@ -663,8 +663,8 @@ class Runnable(Generic[Input, Output], ABC):
|
|||||||
|
|
||||||
def batch_as_completed(
|
def batch_as_completed(
|
||||||
self,
|
self,
|
||||||
inputs: List[Input],
|
inputs: Sequence[Input],
|
||||||
config: Optional[Union[RunnableConfig, List[RunnableConfig]]] = None,
|
config: Optional[Union[RunnableConfig, Sequence[RunnableConfig]]] = None,
|
||||||
*,
|
*,
|
||||||
return_exceptions: bool = False,
|
return_exceptions: bool = False,
|
||||||
**kwargs: Optional[Any],
|
**kwargs: Optional[Any],
|
||||||
@ -746,8 +746,8 @@ class Runnable(Generic[Input, Output], ABC):
|
|||||||
@overload
|
@overload
|
||||||
def abatch_as_completed(
|
def abatch_as_completed(
|
||||||
self,
|
self,
|
||||||
inputs: List[Input],
|
inputs: Sequence[Input],
|
||||||
config: Optional[Union[RunnableConfig, List[RunnableConfig]]] = None,
|
config: Optional[Union[RunnableConfig, Sequence[RunnableConfig]]] = None,
|
||||||
*,
|
*,
|
||||||
return_exceptions: Literal[False] = False,
|
return_exceptions: Literal[False] = False,
|
||||||
**kwargs: Optional[Any],
|
**kwargs: Optional[Any],
|
||||||
@ -757,8 +757,8 @@ class Runnable(Generic[Input, Output], ABC):
|
|||||||
@overload
|
@overload
|
||||||
def abatch_as_completed(
|
def abatch_as_completed(
|
||||||
self,
|
self,
|
||||||
inputs: List[Input],
|
inputs: Sequence[Input],
|
||||||
config: Optional[Union[RunnableConfig, List[RunnableConfig]]] = None,
|
config: Optional[Union[RunnableConfig, Sequence[RunnableConfig]]] = None,
|
||||||
*,
|
*,
|
||||||
return_exceptions: Literal[True],
|
return_exceptions: Literal[True],
|
||||||
**kwargs: Optional[Any],
|
**kwargs: Optional[Any],
|
||||||
@ -767,8 +767,8 @@ class Runnable(Generic[Input, Output], ABC):
|
|||||||
|
|
||||||
async def abatch_as_completed(
|
async def abatch_as_completed(
|
||||||
self,
|
self,
|
||||||
inputs: List[Input],
|
inputs: Sequence[Input],
|
||||||
config: Optional[Union[RunnableConfig, List[RunnableConfig]]] = None,
|
config: Optional[Union[RunnableConfig, Sequence[RunnableConfig]]] = None,
|
||||||
*,
|
*,
|
||||||
return_exceptions: bool = False,
|
return_exceptions: bool = False,
|
||||||
**kwargs: Optional[Any],
|
**kwargs: Optional[Any],
|
||||||
@ -4506,8 +4506,8 @@ class RunnableBindingBase(RunnableSerializable[Input, Output]):
|
|||||||
@overload
|
@overload
|
||||||
def batch_as_completed(
|
def batch_as_completed(
|
||||||
self,
|
self,
|
||||||
inputs: List[Input],
|
inputs: Sequence[Input],
|
||||||
config: Optional[Union[RunnableConfig, List[RunnableConfig]]] = None,
|
config: Optional[Union[RunnableConfig, Sequence[RunnableConfig]]] = None,
|
||||||
*,
|
*,
|
||||||
return_exceptions: Literal[False] = False,
|
return_exceptions: Literal[False] = False,
|
||||||
**kwargs: Any,
|
**kwargs: Any,
|
||||||
@ -4517,8 +4517,8 @@ class RunnableBindingBase(RunnableSerializable[Input, Output]):
|
|||||||
@overload
|
@overload
|
||||||
def batch_as_completed(
|
def batch_as_completed(
|
||||||
self,
|
self,
|
||||||
inputs: List[Input],
|
inputs: Sequence[Input],
|
||||||
config: Optional[Union[RunnableConfig, List[RunnableConfig]]] = None,
|
config: Optional[Union[RunnableConfig, Sequence[RunnableConfig]]] = None,
|
||||||
*,
|
*,
|
||||||
return_exceptions: Literal[True],
|
return_exceptions: Literal[True],
|
||||||
**kwargs: Any,
|
**kwargs: Any,
|
||||||
@ -4527,13 +4527,13 @@ class RunnableBindingBase(RunnableSerializable[Input, Output]):
|
|||||||
|
|
||||||
def batch_as_completed(
|
def batch_as_completed(
|
||||||
self,
|
self,
|
||||||
inputs: List[Input],
|
inputs: Sequence[Input],
|
||||||
config: Optional[Union[RunnableConfig, List[RunnableConfig]]] = None,
|
config: Optional[Union[RunnableConfig, Sequence[RunnableConfig]]] = None,
|
||||||
*,
|
*,
|
||||||
return_exceptions: bool = False,
|
return_exceptions: bool = False,
|
||||||
**kwargs: Optional[Any],
|
**kwargs: Optional[Any],
|
||||||
) -> Iterator[Tuple[int, Union[Output, Exception]]]:
|
) -> Iterator[Tuple[int, Union[Output, Exception]]]:
|
||||||
if isinstance(config, list):
|
if isinstance(config, Sequence):
|
||||||
configs = cast(
|
configs = cast(
|
||||||
List[RunnableConfig],
|
List[RunnableConfig],
|
||||||
[self._merge_configs(conf) for conf in config],
|
[self._merge_configs(conf) for conf in config],
|
||||||
@ -4559,8 +4559,8 @@ class RunnableBindingBase(RunnableSerializable[Input, Output]):
|
|||||||
@overload
|
@overload
|
||||||
def abatch_as_completed(
|
def abatch_as_completed(
|
||||||
self,
|
self,
|
||||||
inputs: List[Input],
|
inputs: Sequence[Input],
|
||||||
config: Optional[Union[RunnableConfig, List[RunnableConfig]]] = None,
|
config: Optional[Union[RunnableConfig, Sequence[RunnableConfig]]] = None,
|
||||||
*,
|
*,
|
||||||
return_exceptions: Literal[False] = False,
|
return_exceptions: Literal[False] = False,
|
||||||
**kwargs: Optional[Any],
|
**kwargs: Optional[Any],
|
||||||
@ -4570,8 +4570,8 @@ class RunnableBindingBase(RunnableSerializable[Input, Output]):
|
|||||||
@overload
|
@overload
|
||||||
def abatch_as_completed(
|
def abatch_as_completed(
|
||||||
self,
|
self,
|
||||||
inputs: List[Input],
|
inputs: Sequence[Input],
|
||||||
config: Optional[Union[RunnableConfig, List[RunnableConfig]]] = None,
|
config: Optional[Union[RunnableConfig, Sequence[RunnableConfig]]] = None,
|
||||||
*,
|
*,
|
||||||
return_exceptions: Literal[True],
|
return_exceptions: Literal[True],
|
||||||
**kwargs: Optional[Any],
|
**kwargs: Optional[Any],
|
||||||
@ -4580,13 +4580,13 @@ class RunnableBindingBase(RunnableSerializable[Input, Output]):
|
|||||||
|
|
||||||
async def abatch_as_completed(
|
async def abatch_as_completed(
|
||||||
self,
|
self,
|
||||||
inputs: List[Input],
|
inputs: Sequence[Input],
|
||||||
config: Optional[Union[RunnableConfig, List[RunnableConfig]]] = None,
|
config: Optional[Union[RunnableConfig, Sequence[RunnableConfig]]] = None,
|
||||||
*,
|
*,
|
||||||
return_exceptions: bool = False,
|
return_exceptions: bool = False,
|
||||||
**kwargs: Optional[Any],
|
**kwargs: Optional[Any],
|
||||||
) -> AsyncIterator[Tuple[int, Union[Output, Exception]]]:
|
) -> AsyncIterator[Tuple[int, Union[Output, Exception]]]:
|
||||||
if isinstance(config, list):
|
if isinstance(config, Sequence):
|
||||||
configs = cast(
|
configs = cast(
|
||||||
List[RunnableConfig],
|
List[RunnableConfig],
|
||||||
[self._merge_configs(conf) for conf in config],
|
[self._merge_configs(conf) for conf in config],
|
||||||
|
@ -18,6 +18,7 @@ from typing import (
|
|||||||
Iterator,
|
Iterator,
|
||||||
List,
|
List,
|
||||||
Optional,
|
Optional,
|
||||||
|
Sequence,
|
||||||
TypeVar,
|
TypeVar,
|
||||||
Union,
|
Union,
|
||||||
cast,
|
cast,
|
||||||
@ -159,7 +160,7 @@ def ensure_config(config: Optional[RunnableConfig] = None) -> RunnableConfig:
|
|||||||
|
|
||||||
|
|
||||||
def get_config_list(
|
def get_config_list(
|
||||||
config: Optional[Union[RunnableConfig, List[RunnableConfig]]], length: int
|
config: Optional[Union[RunnableConfig, Sequence[RunnableConfig]]], length: int
|
||||||
) -> List[RunnableConfig]:
|
) -> List[RunnableConfig]:
|
||||||
"""Get a list of configs from a single config or a list of configs.
|
"""Get a list of configs from a single config or a list of configs.
|
||||||
|
|
||||||
@ -179,13 +180,13 @@ def get_config_list(
|
|||||||
"""
|
"""
|
||||||
if length < 0:
|
if length < 0:
|
||||||
raise ValueError(f"length must be >= 0, but got {length}")
|
raise ValueError(f"length must be >= 0, but got {length}")
|
||||||
if isinstance(config, list) and len(config) != length:
|
if isinstance(config, Sequence) and len(config) != length:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
f"config must be a list of the same length as inputs, "
|
f"config must be a list of the same length as inputs, "
|
||||||
f"but got {len(config)} configs for {length} inputs"
|
f"but got {len(config)} configs for {length} inputs"
|
||||||
)
|
)
|
||||||
|
|
||||||
if isinstance(config, list):
|
if isinstance(config, Sequence):
|
||||||
return list(map(ensure_config, config))
|
return list(map(ensure_config, config))
|
||||||
if length > 1 and isinstance(config, dict) and config.get("run_id") is not None:
|
if length > 1 and isinstance(config, dict) and config.get("run_id") is not None:
|
||||||
warnings.warn(
|
warnings.warn(
|
||||||
|
Loading…
Reference in New Issue
Block a user