The agent engineering platform.
Python agentsaiai-agentsanthropicchatgptdeepagentsenterpriseframeworkgeminigenerative-ailangchainlanggraphllmmultiagentopen-sourceopenaipydanticpythonragtypescript
community[patch]: invoke callback prior to yielding token (openai) (#19389)
aditya thomas515aab3312be
diff --git a/libs/community/langchain_community/llms/openai.py b/libs/community/langchain_community/llms/openai.pyindex ce35db32e3..56ca15dda7 100644--- a/libs/community/langchain_community/llms/openai.py+++ b/libs/community/langchain_community/llms/openai.py@@ -391,7 +391,6 @@ class BaseOpenAI(BaseLLM):if not isinstance(stream_resp, dict):stream_resp = stream_resp.dict()chunk = _stream_response_to_generation_chunk(stream_resp)- yield chunkif run_manager:await run_manager.on_llm_new_token(chunk.text,@@ -401,6 +400,7 @@ class BaseOpenAI(BaseLLM):if chunk.generation_infoelse None,)+ yield chunkdef _generate(self,@@ -1113,9 +1113,9 @@ class OpenAIChat(BaseLLM):stream_resp = stream_resp.dict()token = stream_resp["choices"][0]["delta"].get("content", "")chunk = GenerationChunk(text=token)- yield chunkif run_manager:run_manager.on_llm_new_token(token, chunk=chunk)+ yield chunkasync def _astream(self,@@ -1133,9 +1133,9 @@ class OpenAIChat(BaseLLM):stream_resp = stream_resp.dict()token = stream_resp["choices"][0]["delta"].get("content", "")chunk = GenerationChunk(text=token)- yield chunkif run_manager:await run_manager.on_llm_new_token(token, chunk=chunk)+ yield chunkdef _generate(self,