Skip to content

Commit 0b07568

Browse files
committed
fallback for json.loads tool function args
some openai-compatible models (such as openrouter's anthropic models) do not default to an empty json object when there are no arguments, leading to a parsing error. `function.arguments == '{}'`: ```bash % llm --tool llm_version "What is the version?" --td -m openrouter/openai/gpt-4o Tool call: llm_version({}) 0.26 The version of the LLM is 0.26. ``` `function.arguments == ''`: ```bash % llm --tool llm_version "What is the version?" --td -m openrouter/anthropic/claude-sonnet-4 I'll check the version of llm for you.Error: Expecting value: line 1 column 1 (char 0) ```
1 parent 2292d7a commit 0b07568

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

llm/default_plugins/openai_models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,7 @@ def execute(self, prompt, stream, response, conversation=None, key=None):
711711
llm.ToolCall(
712712
tool_call_id=value.id,
713713
name=value.function.name,
714-
arguments=json.loads(value.function.arguments),
714+
arguments=json.loads(value.function.arguments or '{}'),
715715
)
716716
)
717717
else:
@@ -728,7 +728,7 @@ def execute(self, prompt, stream, response, conversation=None, key=None):
728728
llm.ToolCall(
729729
tool_call_id=tool_call.id,
730730
name=tool_call.function.name,
731-
arguments=json.loads(tool_call.function.arguments),
731+
arguments=json.loads(tool_call.function.arguments or '{}'),
732732
)
733733
)
734734
if completion.choices[0].message.content is not None:

0 commit comments

Comments
 (0)