mirror of
https://github.com/hwchase17/langchain.git
synced 2025-07-16 17:53:37 +00:00
google-genai[patch]: Invoke callback prior to yielding token (#17092)
- **Description:** Invoke callback prior to yielding token in stream and astream methods for Google-genai, - **Issue:** the issue # 16913, - **Twitter handle:** Sparsh10649446 --------- Co-authored-by: Eugene Yurtsev <eyurtsev@gmail.com>
This commit is contained in:
parent
7306600e2f
commit
a2167614b7
@ -624,9 +624,9 @@ class ChatGoogleGenerativeAI(_BaseGoogleGenerativeAI, BaseChatModel):
|
|||||||
generation_t=ChatGenerationChunk,
|
generation_t=ChatGenerationChunk,
|
||||||
)
|
)
|
||||||
gen = cast(ChatGenerationChunk, _chat_result.generations[0])
|
gen = cast(ChatGenerationChunk, _chat_result.generations[0])
|
||||||
yield gen
|
|
||||||
if run_manager:
|
if run_manager:
|
||||||
run_manager.on_llm_new_token(gen.text)
|
run_manager.on_llm_new_token(gen.text)
|
||||||
|
yield gen
|
||||||
|
|
||||||
async def _astream(
|
async def _astream(
|
||||||
self,
|
self,
|
||||||
@ -654,9 +654,9 @@ class ChatGoogleGenerativeAI(_BaseGoogleGenerativeAI, BaseChatModel):
|
|||||||
generation_t=ChatGenerationChunk,
|
generation_t=ChatGenerationChunk,
|
||||||
)
|
)
|
||||||
gen = cast(ChatGenerationChunk, _chat_result.generations[0])
|
gen = cast(ChatGenerationChunk, _chat_result.generations[0])
|
||||||
yield gen
|
|
||||||
if run_manager:
|
if run_manager:
|
||||||
await run_manager.on_llm_new_token(gen.text)
|
await run_manager.on_llm_new_token(gen.text)
|
||||||
|
yield gen
|
||||||
|
|
||||||
def _prepare_chat(
|
def _prepare_chat(
|
||||||
self,
|
self,
|
||||||
|
Loading…
Reference in New Issue
Block a user