community[deepinfra]: fix tool call parsing. (#23162)

This PR includes fix for DeepInfra tool call parsing.
This commit is contained in:
Oguz Vuruskaner 2024-07-03 09:11:37 -07:00 committed by GitHub
parent 525109e506
commit 2a2c0d1a94
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -45,6 +45,7 @@ from langchain_core.messages import (
HumanMessageChunk,
SystemMessage,
SystemMessageChunk,
ToolMessage,
)
from langchain_core.messages.tool import ToolCall
from langchain_core.outputs import (
@ -92,7 +93,7 @@ def _parse_tool_calling(tool_call: dict) -> ToolCall:
Returns:
"""
name = tool_call.get("name", "")
name = tool_call["function"].get("name", "")
args = json.loads(tool_call["function"]["arguments"])
id = tool_call.get("id")
return ToolCall(name=name, args=args, id=id)
@ -181,6 +182,13 @@ def _convert_message_to_dict(message: BaseMessage) -> dict:
"content": message.content,
"name": message.name,
}
elif isinstance(message, ToolMessage):
message_dict = {
"role": "tool",
"content": message.content,
"name": message.name, # type: ignore[dict-item]
"tool_call_id": message.tool_call_id,
}
else:
raise ValueError(f"Got unknown type {message}")
if "name" in message.additional_kwargs: