From 7137c073d70822a8b60e5f27d5cc086c735dd922 Mon Sep 17 00:00:00 2001 From: williamdevena Date: Wed, 28 Feb 2024 18:11:23 +0100 Subject: [PATCH 1/2] langchain_groq[patch]: Invoke callback prior to yielding toke --- libs/partners/groq/langchain_groq/chat_models.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libs/partners/groq/langchain_groq/chat_models.py b/libs/partners/groq/langchain_groq/chat_models.py index f09da3d09e2940..05b4753d2df9a7 100644 --- a/libs/partners/groq/langchain_groq/chat_models.py +++ b/libs/partners/groq/langchain_groq/chat_models.py @@ -274,9 +274,10 @@ def _stream( chunk = ChatGenerationChunk( message=chunk, generation_info=generation_info or None ) - yield chunk + if run_manager: run_manager.on_llm_new_token(chunk.text, chunk=chunk, logprobs=logprobs) + yield chunk async def _astream( self, @@ -310,11 +311,12 @@ async def _astream( chunk = ChatGenerationChunk( message=chunk, generation_info=generation_info or None ) - yield chunk + if run_manager: await run_manager.on_llm_new_token( token=chunk.text, chunk=chunk, logprobs=logprobs ) + yield chunk # # Internal methods From 152ea9161b920a13adb4b0edbdb262e6cd4dc659 Mon Sep 17 00:00:00 2001 From: Erick Friis Date: Wed, 28 Feb 2024 15:41:28 -0800 Subject: [PATCH 2/2] x --- libs/partners/groq/langchain_groq/chat_models.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/partners/groq/langchain_groq/chat_models.py b/libs/partners/groq/langchain_groq/chat_models.py index 05b4753d2df9a7..e185d4d5380a86 100644 --- a/libs/partners/groq/langchain_groq/chat_models.py +++ b/libs/partners/groq/langchain_groq/chat_models.py @@ -274,7 +274,7 @@ def _stream( chunk = ChatGenerationChunk( message=chunk, generation_info=generation_info or None ) - + if run_manager: run_manager.on_llm_new_token(chunk.text, chunk=chunk, logprobs=logprobs) yield chunk @@ -311,7 +311,7 @@ async def _astream( chunk = ChatGenerationChunk( message=chunk, generation_info=generation_info or None ) - + if run_manager: await run_manager.on_llm_new_token( token=chunk.text, chunk=chunk, logprobs=logprobs