generated from langchain-ai/integration-repo-template
-
Notifications
You must be signed in to change notification settings - Fork 305
Labels
bugSomething isn't workingSomething isn't working
Description
Checked other resources
- This is a bug, not a usage question.
- I added a clear and descriptive title that summarizes this issue.
- I used the GitHub search to find a similar question and didn't find it.
- I am sure that this is a bug in LangChain Community rather than my code.
- The bug is not resolved by updating to the latest stable version of LangChain Community.
- I read what a minimal reproducible example is (https://stackoverflow.com/help/minimal-reproducible-example).
- I posted a self-contained, minimal, reproducible example. A maintainer can copy it and run it AS IS.
Example Code
See below
Error Message and Stack Trace (if applicable)
No response
Description
The following code snippet from langchain_community.adapters.openai does not handle the attribute AIMessageChunk.tool_calls || AIMessageChunk.tool_call_chunk and solely relies on AIMessage.additional_kwargs(). additional_kwargs no longer contains the tool calls with Langchain 1.0 upgrade.
def _convert_message_chunk(chunk: BaseMessageChunk, i: int) -> dict:
_dict: Dict[str, Any] = {}
if isinstance(chunk, AIMessageChunk):
if i == 0:
# Only shows up in the first chunk
_dict["role"] = "assistant"
if "function_call" in chunk.additional_kwargs:
_dict["function_call"] = chunk.additional_kwargs["function_call"]
# If the first chunk is a function call, the content is not empty string,
# not missing, but None.
if i == 0:
_dict["content"] = None
if "tool_calls" in chunk.additional_kwargs:
_dict["tool_calls"] = chunk.additional_kwargs["tool_calls"]
# If the first chunk is tool calls, the content is not empty string,
# not missing, but None.
if i == 0:
_dict["content"] = None
else:
_dict["content"] = chunk.content
else:
raise ValueError(f"Got unexpected streaming chunk type: {type(chunk)}")
# This only happens at the end of streams, and OpenAI returns as empty dict
if _dict == {"content": ""}:
_dict = {}
return _dictHere is the response from Langchain 1.0
Same problem with convert_message_to_dict in the same file
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working