mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-10 07:21:03 +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):
|
if not isinstance(stream_resp, dict):
|
||||||
stream_resp = stream_resp.dict()
|
stream_resp = stream_resp.dict()
|
||||||
chunk = _stream_response_to_generation_chunk(stream_resp)
|
chunk = _stream_response_to_generation_chunk(stream_resp)
|
||||||
yield chunk
|
|
||||||
if run_manager:
|
if run_manager:
|
||||||
run_manager.on_llm_new_token(
|
run_manager.on_llm_new_token(
|
||||||
chunk.text,
|
chunk.text,
|
||||||
@@ -375,6 +374,7 @@ class BaseOpenAI(BaseLLM):
|
|||||||
if chunk.generation_info
|
if chunk.generation_info
|
||||||
else None,
|
else None,
|
||||||
)
|
)
|
||||||
|
yield chunk
|
||||||
|
|
||||||
async def _astream(
|
async def _astream(
|
||||||
self,
|
self,
|
||||||
|
Reference in New Issue
Block a user