Skip to content

Commit 69d41ef

Browse files
committed
Fix anthropic api for custom providers.
1 parent e3bf19f commit 69d41ef

File tree

3 files changed

+17
-17
lines changed

3 files changed

+17
-17
lines changed

src/eca/features/chat.clj

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,10 @@
142142
:state :running
143143
:text "Generating"}))
144144
:on-usage-updated (fn [usage]
145-
(send-content! chat-ctx :system
146-
(merge {:type :usage}
147-
(usage-msg->usage usage model chat-ctx))))
145+
(when-let [usage (usage-msg->usage usage model chat-ctx)]
146+
(send-content! chat-ctx :system
147+
(merge {:type :usage}
148+
usage))))
148149
:on-message-received (fn [{:keys [type] :as msg}]
149150
(assert-chat-not-stopped! chat-ctx)
150151
(case type

src/eca/llm_api.clj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,6 @@
177177
:max-output-tokens max-output-tokens
178178
:reason? (and reason? (:reason? model-config))
179179
:past-messages past-messages
180-
:web-search web-search
181180
:tools tools
182181
:extra-payload extra-payload
183182
:api-url url

src/eca/shared.clj

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,19 @@
5050
(defn tokens->cost [input-tokens input-cache-creation-tokens input-cache-read-tokens output-tokens model db]
5151
(let [normalized-model (if (string/includes? model "/")
5252
(last (string/split model #"/"))
53-
model)
54-
{:keys [input-token-cost output-token-cost
55-
input-cache-creation-token-cost input-cache-read-token-cost]} (get-in db [:models normalized-model])
56-
input-cost (* input-tokens input-token-cost)
57-
input-cost (if (and input-cache-creation-tokens input-cache-creation-token-cost)
58-
(+ input-cost (* input-cache-creation-tokens input-cache-creation-token-cost))
59-
input-cost)
60-
input-cost (if (and input-cache-read-tokens input-cache-read-token-cost)
61-
(+ input-cost (* input-cache-read-tokens input-cache-read-token-cost))
62-
input-cost)]
63-
(when (and input-token-cost output-token-cost)
64-
(format "%.2f" (+ input-cost
65-
(* output-tokens output-token-cost))))))
53+
model)]
54+
(when-let [{:keys [input-token-cost output-token-cost
55+
input-cache-creation-token-cost input-cache-read-token-cost]} (get-in db [:models normalized-model])]
56+
(when (and input-token-cost output-token-cost)
57+
(let [input-cost (* input-tokens input-token-cost)
58+
input-cost (if (and input-cache-creation-tokens input-cache-creation-token-cost)
59+
(+ input-cost (* input-cache-creation-tokens input-cache-creation-token-cost))
60+
input-cost)
61+
input-cost (if (and input-cache-read-tokens input-cache-read-token-cost)
62+
(+ input-cost (* input-cache-read-tokens input-cache-read-token-cost))
63+
input-cost)]
64+
(format "%.2f" (+ input-cost
65+
(* output-tokens output-token-cost))))))))
6666

6767
(defn map->camel-cased-map [m]
6868
(let [f (fn [[k v]]

0 commit comments

Comments
 (0)