fix: use object.__setattr__ for LLM ainvoke patching to avoid pydantic crash

This commit is contained in:
Laith Weinberger
2026-04-08 17:20:46 -04:00
parent 8de903dfdd
commit 3242d9dbc2

View File

@@ -367,9 +367,9 @@ class TokenCost:
return result
# Replace the method with our tracked version
# Using setattr to avoid type checking issues with overloaded methods
setattr(llm, 'ainvoke', tracked_ainvoke)
# Replace the method with our tracked version.
# Use setattr so Pydantic-backed models don't reject runtime patch
object.__setattr__(llm, 'ainvoke', tracked_ainvoke)
return llm