Skip to content

Commit c5f0b61

Browse files
committed
Fix openai/anthropic calls
1 parent a80d17c commit c5f0b61

4 files changed

Lines changed: 10 additions & 9 deletions

File tree

src/eca/features/tools/filesystem.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
(map (comp shared/uri->filename :uri) (:workspace-folders db))))))
2424

2525
(defn ^:private list-directory [arguments db]
26-
(let [path (fs/canonicalize (:path arguments))]
26+
(let [path (fs/canonicalize (get arguments "path"))]
2727
(or (not-allowed-path path db)
2828
(single-text-content
2929
(reduce

src/eca/llm_providers/anthropic.clj

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
:name "web_search"
2929
:max_uses 10})))
3030

31-
(defn ^:private base-request! [{:keys [rid body api-key on-error on-response]}]
31+
(defn ^:private base-request! [{:keys [rid body api-key content-block* on-error on-response]}]
3232
(let [api-key (or api-key
3333
(System/getenv "ANTHROPIC_API_KEY"))
3434
url (url messages-path)]
@@ -51,7 +51,7 @@
5151
(with-open [rdr (io/reader body)]
5252
(doseq [[event data] (llm-util/event-data-seq rdr)]
5353
(llm-util/log-response logger-tag rid event data)
54-
(on-response event data))))
54+
(on-response event data content-block*))))
5555
(catch Exception e
5656
(on-error {:exception e}))))
5757
(fn [e]
@@ -90,9 +90,8 @@
9090
:stream true
9191
:tools (->tools tools web-search)
9292
:system context}
93-
content-block* (atom nil)
9493
on-response-fn
95-
(fn handle-response [event data]
94+
(fn handle-response [event data content-block*]
9695
(case event
9796
"content_block_start" (case (-> data :content_block :type)
9897
"tool_use" (do
@@ -140,6 +139,7 @@
140139
{:rid (llm-util/gen-rid)
141140
:body (assoc body :messages messages)
142141
:api-key api-key
142+
:content-block* (atom nil)
143143
:on-error on-error
144144
:on-response handle-response}))))
145145
"end_turn" (on-message-received {:type :finish
@@ -150,5 +150,6 @@
150150
{:rid (llm-util/gen-rid)
151151
:body body
152152
:api-key api-key
153+
:content-block* (atom nil)
153154
:on-error on-error
154155
:on-response on-response-fn})))

src/eca/llm_providers/openai.clj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@
5252
(case role
5353
"tool_call" {:type "function_call"
5454
:name (:name content)
55-
:call-id (:id content)
55+
:call_id (:id content)
5656
:arguments (:arguments content)}
5757
"tool_call_output"
5858
{:type "function_call_output"
5959
:name (:name content)
60-
:call-id (:id content)
60+
:call_id (:id content)
6161
:output (llm-util/stringfy-tool-result content)}
6262
msg))
6363
past-messages)

test/eca/llm_providers/openai_test.clj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@
2323
[{:role "user" :content "List the files you are allowed"}
2424
{:role "assistant" :content "Ok!"}
2525
{:type "function_call"
26-
:call-id "call-1"
26+
:call_id "call-1"
2727
:name "list_allowed_directories"
2828
:arguments {}}
2929
{:type "function_call_output"
30-
:call-id "call-1"
30+
:call_id "call-1"
3131
:output "Allowed directories: /foo/bar\n"}
3232
{:role "assistant" :content "I see /foo/bar"}
3333
{:role "user" :content "Thanks"}]

0 commit comments

Comments
 (0)