From 7f37fd8b80b2e22e2d10ea8894a558ecf5b957f7 Mon Sep 17 00:00:00 2001 From: Subhrajyoty Roy Date: Fri, 27 Sep 2024 18:12:01 +0530 Subject: [PATCH] community[patch]: callback before yield for cloudflare (#26927) **Description:** Moves yield to after callback for `_stream` function for the cloudfare workersai model in the community llm package **Issue:** #16913 --- .../langchain_community/llms/cloudflare_workersai.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/community/langchain_community/llms/cloudflare_workersai.py b/libs/community/langchain_community/llms/cloudflare_workersai.py index 314a32223e8..0fb6ac6053d 100644 --- a/libs/community/langchain_community/llms/cloudflare_workersai.py +++ b/libs/community/langchain_community/llms/cloudflare_workersai.py @@ -105,9 +105,9 @@ class CloudflareWorkersAI(LLM): logger.debug(chunk) raise e if data is not None and "response" in data: + if run_manager: + run_manager.on_llm_new_token(data["response"]) yield GenerationChunk(text=data["response"]) - if run_manager: - run_manager.on_llm_new_token(data["response"]) logger.debug("stream end") self.streaming = original_steaming