Skip to content

The agent engineering platform.

community[patch]: Invoke on_llm_new_token callback before yielding chunk (#24938)

Anneli Samuel2204d8cb7d28
diff --git a/libs/community/langchain_community/chat_models/mlx.py b/libs/community/langchain_community/chat_models/mlx.py
index 1bd9f740d7..e3a28c73c7 100644
--- a/libs/community/langchain_community/chat_models/mlx.py
+++ b/libs/community/langchain_community/chat_models/mlx.py
@@ -186,9 +186,9 @@ class ChatMLX(BaseChatModel):
# yield text, if any
if text:
chunk = ChatGenerationChunk(message=AIMessageChunk(content=text))
- yield chunk
if run_manager:
run_manager.on_llm_new_token(text, chunk=chunk)
+ yield chunk
# break if stop sequence found
if token == eos_token_id or (stop is not None and text in stop):