mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-08 06:23:20 +00:00
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:
@@ -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,
|
||||
|
Reference in New Issue
Block a user