mirror of
https://github.com/langgenius/dify.git
synced 2026-04-27 05:58:14 +08:00
Raise on invalid tool-call deltas
This commit is contained in:
@ -53,23 +53,12 @@ def _get_or_create_tool_call(
|
||||
If `tool_call_id` is empty, returns the most recently created tool call.
|
||||
"""
|
||||
if not tool_call_id:
|
||||
if existing_tools_calls:
|
||||
return existing_tools_calls[-1]
|
||||
|
||||
tool_call = AssistantPromptMessage.ToolCall(
|
||||
id="",
|
||||
type="function",
|
||||
function=AssistantPromptMessage.ToolCall.ToolCallFunction(name="", arguments=""),
|
||||
)
|
||||
existing_tools_calls.append(tool_call)
|
||||
return tool_call
|
||||
if not existing_tools_calls:
|
||||
raise ValueError("tool_call_id is empty but no existing tool call is available to apply the delta")
|
||||
return existing_tools_calls[-1]
|
||||
|
||||
tool_call = next((tool_call for tool_call in existing_tools_calls if tool_call.id == tool_call_id), None)
|
||||
if tool_call is None:
|
||||
if existing_tools_calls and not existing_tools_calls[-1].id:
|
||||
existing_tools_calls[-1].id = tool_call_id
|
||||
return existing_tools_calls[-1]
|
||||
|
||||
tool_call = AssistantPromptMessage.ToolCall(
|
||||
id=tool_call_id,
|
||||
type="function",
|
||||
|
||||
Reference in New Issue
Block a user