mirror of
https://github.com/hwchase17/langchain.git
synced 2025-07-09 14:35:50 +00:00
core[patch]: Int Combine when Merging Dicts (#31572)
- **Description:** Combining the Int Types by adding them which makes the most sense. - **Issue:** #31565
This commit is contained in:
parent
6a5073b227
commit
b26d2250ba
@ -64,6 +64,8 @@ def merge_dicts(left: dict[str, Any], *others: dict[str, Any]) -> dict[str, Any]
|
|||||||
merged[right_k] = merge_lists(merged[right_k], right_v)
|
merged[right_k] = merge_lists(merged[right_k], right_v)
|
||||||
elif merged[right_k] == right_v:
|
elif merged[right_k] == right_v:
|
||||||
continue
|
continue
|
||||||
|
elif isinstance(merged[right_k], int):
|
||||||
|
merged[right_k] += right_v
|
||||||
else:
|
else:
|
||||||
msg = (
|
msg = (
|
||||||
f"Additional kwargs key {right_k} already exists in left dict and "
|
f"Additional kwargs key {right_k} already exists in left dict and "
|
||||||
|
@ -9,6 +9,7 @@ import pytest
|
|||||||
from pydantic import SecretStr
|
from pydantic import SecretStr
|
||||||
|
|
||||||
from langchain_core import utils
|
from langchain_core import utils
|
||||||
|
from langchain_core.outputs import GenerationChunk
|
||||||
from langchain_core.utils import (
|
from langchain_core.utils import (
|
||||||
check_package_version,
|
check_package_version,
|
||||||
from_env,
|
from_env,
|
||||||
@ -375,3 +376,10 @@ def test_using_secret_from_env_as_default_factory(
|
|||||||
|
|
||||||
with pytest.raises(ValueError, match="Did not find FOOFOOFOOBAR"):
|
with pytest.raises(ValueError, match="Did not find FOOFOOFOOBAR"):
|
||||||
OhMy()
|
OhMy()
|
||||||
|
|
||||||
|
|
||||||
|
def test_generation_chunk_addition_type_error() -> None:
|
||||||
|
chunk1 = GenerationChunk(text="", generation_info={"len": 0})
|
||||||
|
chunk2 = GenerationChunk(text="Non-empty text", generation_info={"len": 14})
|
||||||
|
result = chunk1 + chunk2
|
||||||
|
assert result == GenerationChunk(text="Non-empty text", generation_info={"len": 14})
|
||||||
|
Loading…
Reference in New Issue
Block a user