mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-24 12:01:54 +00:00
feat(core): zero-out token costs for cache hits (#32437)
This commit is contained in:
@@ -666,6 +666,16 @@ class BaseChatModel(BaseLanguageModel[BaseMessage], ABC):
|
||||
converted_generations.append(chat_gen)
|
||||
else:
|
||||
# Already a ChatGeneration or other expected type
|
||||
if hasattr(gen, "message") and isinstance(gen.message, AIMessage):
|
||||
# We zero out cost on cache hits
|
||||
gen.message = gen.message.model_copy(
|
||||
update={
|
||||
"usage_metadata": {
|
||||
**(gen.message.usage_metadata or {}),
|
||||
"total_cost": 0,
|
||||
}
|
||||
}
|
||||
)
|
||||
converted_generations.append(gen)
|
||||
return converted_generations
|
||||
|
||||
|
Reference in New Issue
Block a user