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: fix openai streaming throws 'AIMessageChunk' object has no attribute 'text' #18006

Merged
merged 2 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def _stream(
message=chunk, generation_info=generation_info
)
if run_manager:
run_manager.on_llm_new_token(chunk.text, chunk=cg_chunk)
run_manager.on_llm_new_token(cg_chunk.text, chunk=cg_chunk)
yield cg_chunk

async def _astream(
Expand Down
2 changes: 1 addition & 1 deletion libs/community/langchain_community/chat_models/konko.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def _stream(
message=chunk, generation_info=generation_info
)
if run_manager:
run_manager.on_llm_new_token(chunk.text, chunk=cg_chunk)
run_manager.on_llm_new_token(cg_chunk.text, chunk=cg_chunk)
yield cg_chunk

def _generate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def _stream(
message=chunk, generation_info=generation_info
)
if run_manager:
run_manager.on_llm_new_token(chunk.text, chunk=cg_chunk)
run_manager.on_llm_new_token(cg_chunk.text, chunk=cg_chunk)
yield cg_chunk

def _chat(self, messages: List[BaseMessage], **kwargs: Any) -> requests.Response:
Expand Down
4 changes: 2 additions & 2 deletions libs/community/langchain_community/chat_models/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ def _stream(
message=chunk, generation_info=generation_info
)
if run_manager:
run_manager.on_llm_new_token(chunk.text, chunk=cg_chunk)
run_manager.on_llm_new_token(cg_chunk.text, chunk=cg_chunk)
yield cg_chunk

def _generate(
Expand Down Expand Up @@ -507,7 +507,7 @@ async def _astream(
message=chunk, generation_info=generation_info
)
if run_manager:
await run_manager.on_llm_new_token(token=chunk.text, chunk=cg_chunk)
await run_manager.on_llm_new_token(token=cg_chunk.text, chunk=cg_chunk)
yield cg_chunk

async def _agenerate(
Expand Down