From c4fdf78d03751be1e4e35079c1d139c86560156b Mon Sep 17 00:00:00 2001 From: Nuno Campos Date: Thu, 2 Nov 2023 18:56:29 +0000 Subject: [PATCH] Fix AddableDict raising exception when used with non-addable values (#12785) --- libs/langchain/langchain/schema/runnable/utils.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/libs/langchain/langchain/schema/runnable/utils.py b/libs/langchain/langchain/schema/runnable/utils.py index 05ea6832d..781f52972 100644 --- a/libs/langchain/langchain/schema/runnable/utils.py +++ b/libs/langchain/langchain/schema/runnable/utils.py @@ -192,7 +192,11 @@ class AddableDict(Dict[str, Any]): if key not in chunk or chunk[key] is None: chunk[key] = other[key] elif other[key] is not None: - chunk[key] = chunk[key] + other[key] + try: + added = chunk[key] + other[key] + except TypeError: + added = other[key] + chunk[key] = added return chunk def __radd__(self, other: AddableDict) -> AddableDict: @@ -201,7 +205,11 @@ class AddableDict(Dict[str, Any]): if key not in chunk or chunk[key] is None: chunk[key] = self[key] elif self[key] is not None: - chunk[key] = chunk[key] + self[key] + try: + added = chunk[key] + self[key] + except TypeError: + added = self[key] + chunk[key] = added return chunk