Skip to content

Commit 86f6ade

Browse files
committed
Fix invalid request 400, for tool calls with nil arguments failing when using Anthropic models via GitHub Copilot.
Fixes #340
1 parent 2c6237d commit 86f6ade

5 files changed

Lines changed: 31 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## Unreleased
44

5+
- Fix invalid request 400, for tool calls with nil arguments failing when using Anthropic models via GitHub Copilot. #340
6+
57
## 0.109.2
68

79
- Add `chat/clear` message.

src/eca/llm_providers/openai.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100
"tool_call" {:type "function_call"
101101
:name (:full-name content)
102102
:call_id (:id content)
103-
:arguments (json/generate-string (:arguments content))}
103+
:arguments (json/generate-string (or (:arguments content) {}))}
104104
"tool_call_output"
105105
{:type "function_call_output"
106106
:call_id (:id content)

src/eca/llm_providers/openai_chat.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@
168168
:tool_calls [(cond-> {:id tool-call-id
169169
:type "function"
170170
:function {:name (:full-name content)
171-
:arguments (json/generate-string (:arguments content))}}
171+
:arguments (json/generate-string (or (:arguments content) {}))}}
172172
;; Preserve Google Gemini thought signatures if present
173173
(:external-id content)
174174
(assoc-in [:extra_content :google :thought_signature]

test/eca/llm_providers/openai_chat_test.clj

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,22 @@
146146
thinking-start-tag
147147
thinking-end-tag))))
148148

149+
(testing "Tool call transformation with nil arguments defaults to empty object"
150+
(is (match?
151+
{:role "assistant"
152+
:tool_calls [{:id "call-123"
153+
:type "function"
154+
:function {:name "foo__diagnostics"
155+
:arguments "{}"}}]}
156+
(#'llm-providers.openai-chat/transform-message
157+
{:role "tool_call"
158+
:content {:id "call-123"
159+
:full-name "foo__diagnostics"
160+
:arguments nil}}
161+
true
162+
thinking-start-tag
163+
thinking-end-tag))))
164+
149165
(testing "Tool call transformation prefers :llm-tool-call-id when present"
150166
(is (match?
151167
{:role "assistant"

test/eca/llm_providers/openai_test.clj

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,4 +150,15 @@
150150
:error false
151151
:text "Allowed directories: /foo/bar"}]}}}
152152
{:role "assistant" :content [{:type :text :text "I see /foo/bar"}]}]
153+
true))))
154+
(testing "With tool_call with nil arguments defaults to empty object"
155+
(is (match?
156+
[{:role "user" :content [{:type "input_text" :text "Check diagnostics"}]}
157+
{:type "function_call"
158+
:call_id "call-1"
159+
:name "eca__editor_diagnostics"
160+
:arguments "{}"}]
161+
(#'llm-providers.openai/normalize-messages
162+
[{:role "user" :content [{:type :text :text "Check diagnostics"}]}
163+
{:role "tool_call" :content {:id "call-1" :full-name "eca__editor_diagnostics" :arguments nil}}]
153164
true)))))

0 commit comments

Comments
 (0)