Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions llm/default_plugins/openai_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,8 @@ def execute(self, prompt, stream, response, conversation=None, key=None):
usage = chunk.usage.model_dump()
if chunk.choices and chunk.choices[0].delta:
for tool_call in chunk.choices[0].delta.tool_calls or []:
if tool_call.function.arguments is None:
tool_call.function.arguments = ""
index = tool_call.index
if index not in tool_calls:
tool_calls[index] = tool_call
Expand All @@ -711,7 +713,7 @@ def execute(self, prompt, stream, response, conversation=None, key=None):
llm.ToolCall(
tool_call_id=value.id,
name=value.function.name,
arguments=json.loads(value.function.arguments),
arguments=json.loads(value.function.arguments or "{}"),
)
)
else:
Expand All @@ -728,7 +730,7 @@ def execute(self, prompt, stream, response, conversation=None, key=None):
llm.ToolCall(
tool_call_id=tool_call.id,
name=tool_call.function.name,
arguments=json.loads(tool_call.function.arguments),
arguments=json.loads(tool_call.function.arguments or "{}"),
)
)
if completion.choices[0].message.content is not None:
Expand Down Expand Up @@ -774,6 +776,8 @@ async def execute(
usage = chunk.usage.model_dump()
if chunk.choices and chunk.choices[0].delta:
for tool_call in chunk.choices[0].delta.tool_calls or []:
if tool_call.function.arguments is None:
tool_call.function.arguments = ""
index = tool_call.index
if index not in tool_calls:
tool_calls[index] = tool_call
Expand All @@ -794,7 +798,7 @@ async def execute(
llm.ToolCall(
tool_call_id=value.id,
name=value.function.name,
arguments=json.loads(value.function.arguments),
arguments=json.loads(value.function.arguments or "{}"),
)
)
response.response_json = remove_dict_none_values(combine_chunks(chunks))
Expand All @@ -812,7 +816,7 @@ async def execute(
llm.ToolCall(
tool_call_id=tool_call.id,
name=tool_call.function.name,
arguments=json.loads(tool_call.function.arguments),
arguments=json.loads(tool_call.function.arguments or "{}"),
)
)
if completion.choices[0].message.content is not None:
Expand Down