community[patch]: Invoke callback prior to yielding token (#18288)

## PR title
community[patch]: Invoke callback prior to yielding

PR message
Description: Invoke on_llm_new_token callback prior to yielding token in
_stream and _astream methods.
Issue: https://github.com/langchain-ai/langchain/issues/16913
Dependencies: None
Twitter handle: None
This commit is contained in:
William De Vena 2024-02-28 22:40:53 +01:00 committed by GitHub
parent ca4f5e2408
commit 6b58943917
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -175,6 +175,6 @@ class VolcEngineMaasLLM(LLM, VolcEngineMaasBase):
chunk = GenerationChunk(
text=res.get("choice", {}).get("message", {}).get("content", "")
)
yield chunk
if run_manager:
run_manager.on_llm_new_token(chunk.text, chunk=chunk)
yield chunk