Skip to content

The agent engineering platform.

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

Yudhajit Sinha140f06e59a03
diff --git a/libs/community/langchain_community/llms/openai.py b/libs/community/langchain_community/llms/openai.py
index 7f0aa07548..ce35db32e3 100644
--- a/libs/community/langchain_community/llms/openai.py
+++ b/libs/community/langchain_community/llms/openai.py
@@ -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,