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

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

## PR message
- Description: Invoke callback prior to yielding token in _stream_
method in llms/openai.
- Issue: #16913 
- Dependencies: None
This commit is contained in:
Yudhajit Sinha
2024-03-20 20:26:30 +05:30
committed by GitHub
parent 280a914920
commit 140f06e59a

View File

@@ -365,7 +365,6 @@ class BaseOpenAI(BaseLLM):
if not isinstance(stream_resp, dict):
stream_resp = stream_resp.dict()
chunk = _stream_response_to_generation_chunk(stream_resp)
yield chunk
if run_manager:
run_manager.on_llm_new_token(
chunk.text,
@@ -375,6 +374,7 @@ class BaseOpenAI(BaseLLM):
if chunk.generation_info
else None,
)
yield chunk
async def _astream(
self,