mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-18 21:09:00 +00:00
community[patch]: Fix tool_calls
parsing when streaming from DeepInfra (#26813)
- **Description:** This PR fixes the response parsing logic for `ChatDeepInfra`, more specifially `_convert_delta_to_message_chunk()`, which is invoked when streaming via `ChatDeepInfra`. - **Issue:** Streaming from DeepInfra via `ChatDeepInfra` is currently broken because the response parsing logic doesn't handle that `tool_calls` can be `None`. (There is no GitHub issue for this problem yet.) - **Dependencies:** – - **Twitter handle:** – Keeping this here as a reminder: > If no one reviews your PR within a few days, please @-mention one of baskaryan, efriis, eyurtsev, ccurme, vbarda, hwchase17.
This commit is contained in:
parent
997d95c8f8
commit
2b83c7c3ab
@ -144,13 +144,12 @@ def _convert_delta_to_message_chunk(
|
||||
) -> BaseMessageChunk:
|
||||
role = _dict.get("role")
|
||||
content = _dict.get("content") or ""
|
||||
tool_calls = _dict.get("tool_calls") or []
|
||||
|
||||
if role == "user" or default_class == HumanMessageChunk:
|
||||
return HumanMessageChunk(content=content)
|
||||
elif role == "assistant" or default_class == AIMessageChunk:
|
||||
tool_calls = [
|
||||
_parse_tool_calling(tool_call) for tool_call in _dict.get("tool_calls", [])
|
||||
]
|
||||
tool_calls = [_parse_tool_calling(tool_call) for tool_call in tool_calls]
|
||||
return AIMessageChunk(content=content, tool_calls=tool_calls)
|
||||
elif role == "system" or default_class == SystemMessageChunk:
|
||||
return SystemMessageChunk(content=content)
|
||||
|
Loading…
Reference in New Issue
Block a user