Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

community[patch]: invoke callback prior to yielding token (openai) #19389

Merged
merged 1 commit into from
Mar 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions libs/community/langchain_community/llms/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,6 @@ async def _astream(
if not isinstance(stream_resp, dict):
stream_resp = stream_resp.dict()
chunk = _stream_response_to_generation_chunk(stream_resp)
yield chunk
if run_manager:
await run_manager.on_llm_new_token(
chunk.text,
Expand All @@ -401,6 +400,7 @@ async def _astream(
if chunk.generation_info
else None,
)
yield chunk

def _generate(
self,
Expand Down Expand Up @@ -1113,9 +1113,9 @@ def _stream(
stream_resp = stream_resp.dict()
token = stream_resp["choices"][0]["delta"].get("content", "")
chunk = GenerationChunk(text=token)
yield chunk
if run_manager:
run_manager.on_llm_new_token(token, chunk=chunk)
yield chunk

async def _astream(
self,
Expand All @@ -1133,9 +1133,9 @@ async def _astream(
stream_resp = stream_resp.dict()
token = stream_resp["choices"][0]["delta"].get("content", "")
chunk = GenerationChunk(text=token)
yield chunk
if run_manager:
await run_manager.on_llm_new_token(token, chunk=chunk)
yield chunk

def _generate(
self,
Expand Down