community[patch]: invoke callback prior to yielding token (fireworks) (#19388)

**Description:** Invoke callback prior to yielding token for Fireworks
**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)
**Dependencies:** None
This commit is contained in:
aditya thomas 2024-03-23 05:14:06 +05:30 committed by GitHub
parent 16ef88a87d
commit 49e932cd24
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -186,9 +186,9 @@ class Fireworks(BaseLLM):
self, self.use_retry, run_manager=run_manager, stop=stop, **params
):
chunk = _stream_response_to_generation_chunk(stream_resp)
yield chunk
if run_manager:
run_manager.on_llm_new_token(chunk.text, chunk=chunk)
yield chunk
async def _astream(
self,
@ -207,9 +207,9 @@ class Fireworks(BaseLLM):
self, self.use_retry, run_manager=run_manager, stop=stop, **params
):
chunk = _stream_response_to_generation_chunk(stream_resp)
yield chunk
if run_manager:
await run_manager.on_llm_new_token(chunk.text, chunk=chunk)
yield chunk
def conditional_decorator(