Skip to content

The agent engineering platform.

google-genai[patch]: Invoke callback prior to yielding token (#17092)

Sparsh Jaina2167614b768
diff --git a/libs/partners/google-genai/langchain_google_genai/chat_models.py b/libs/partners/google-genai/langchain_google_genai/chat_models.py
index 2f0d35428d..b69ff5824f 100644
--- a/libs/partners/google-genai/langchain_google_genai/chat_models.py
+++ b/libs/partners/google-genai/langchain_google_genai/chat_models.py
@@ -624,9 +624,9 @@ class ChatGoogleGenerativeAI(_BaseGoogleGenerativeAI, BaseChatModel):
generation_t=ChatGenerationChunk,
)
gen = cast(ChatGenerationChunk, _chat_result.generations[0])
- yield gen
if run_manager:
run_manager.on_llm_new_token(gen.text)
+ yield gen
async def _astream(
self,
@@ -654,9 +654,9 @@ class ChatGoogleGenerativeAI(_BaseGoogleGenerativeAI, BaseChatModel):
generation_t=ChatGenerationChunk,
)
gen = cast(ChatGenerationChunk, _chat_result.generations[0])
- yield gen
if run_manager:
await run_manager.on_llm_new_token(gen.text)
+ yield gen
def _prepare_chat(
self,