mirror of
https://github.com/hwchase17/langchain.git
synced 2025-07-08 14:05:16 +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)
|
||||
elif merged[right_k] == right_v:
|
||||
continue
|
||||
elif isinstance(merged[right_k], int):
|
||||
merged[right_k] += right_v
|
||||
else:
|
||||
msg = (
|
||||
f"Additional kwargs key {right_k} already exists in left dict and "
|
||||
|
@ -9,6 +9,7 @@ import pytest
|
||||
from pydantic import SecretStr
|
||||
|
||||
from langchain_core import utils
|
||||
from langchain_core.outputs import GenerationChunk
|
||||
from langchain_core.utils import (
|
||||
check_package_version,
|
||||
from_env,
|
||||
@ -375,3 +376,10 @@ def test_using_secret_from_env_as_default_factory(
|
||||
|
||||
with pytest.raises(ValueError, match="Did not find FOOFOOFOOBAR"):
|
||||
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