From 0653aa469a74a1dea0f1b24c306384f80faade49 Mon Sep 17 00:00:00 2001 From: Robby <45851384+h0rv@users.noreply.github.com> Date: Mon, 12 Feb 2024 19:36:33 -0500 Subject: [PATCH] community[patch]: Invoke callback prior to yielding token (#17346) **Description:** Invoke callback prior to yielding token in stream method for watsonx. **Issue:** [Callback for on_llm_new_token should be invoked before the token is yielded by the model #16913](https://github.com/langchain-ai/langchain/issues/16913) Co-authored-by: Robby --- libs/community/langchain_community/llms/watsonxllm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/community/langchain_community/llms/watsonxllm.py b/libs/community/langchain_community/llms/watsonxllm.py index aaea7cd06f..c35e991db3 100644 --- a/libs/community/langchain_community/llms/watsonxllm.py +++ b/libs/community/langchain_community/llms/watsonxllm.py @@ -397,7 +397,7 @@ class WatsonxLLM(BaseLLM): prompt=prompt, raw_response=True, params=params ): chunk = self._stream_response_to_generation_chunk(stream_resp) - yield chunk if run_manager: run_manager.on_llm_new_token(chunk.text, chunk=chunk) + yield chunk