Skip to content

Commit fe812e2

Browse files
committed
feat(core): strip message IDs from cache keys using model_copy
1 parent 31b5e48 commit fe812e2

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

libs/core/langchain_core/language_models/chat_models.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1128,7 +1128,12 @@ def _generate_with_cache(
11281128
if check_cache:
11291129
if llm_cache:
11301130
llm_string = self._get_llm_string(stop=stop, **kwargs)
1131-
prompt = dumps(messages)
1131+
normalized_messages = [
1132+
msg.model_copy(update={"id": None})
1133+
if getattr(msg, "id", None) is not None else msg
1134+
for msg in messages
1135+
]
1136+
prompt = dumps(normalized_messages)
11321137
cache_val = llm_cache.lookup(prompt, llm_string)
11331138
if isinstance(cache_val, list):
11341139
converted_generations = self._convert_cached_generations(cache_val)

0 commit comments

Comments
 (0)