Skip to content

Commit eea9d48

Browse files
committed
Add max tokens to llm providers
1 parent 1a7b1fd commit eea9d48

File tree

4 files changed

+16
-6
lines changed

4 files changed

+16
-6
lines changed

src/eca/db.clj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,22 @@
2121
:output-token-cost (/ 8.0 one-million)}
2222
"gpt-4.1" {:tools true
2323
:web-search true
24+
:max-output-tokens 32000
2425
:input-token-cost (/ 2.0 one-million)
2526
:output-token-cost (/ 8.0 one-million)}
2627
"claude-sonnet-4-0" {:tools true
2728
:web-search true
29+
:max-output-tokens 8196
2830
:input-token-cost (/ 3.0 one-million)
2931
:output-token-cost (/ 15.0 one-million)}
3032
"claude-opus-4-0" {:tools true
3133
:web-search true
34+
:max-output-tokens 8196
3235
:input-token-cost (/ 15.0 one-million)
3336
:output-token-cost (/ 75.0 one-million)}
3437
"claude-3-5-haiku-latest" {:tools true
3538
:web-search true
39+
:max-output-tokens 4096
3640
:input-token-cost (/ 0.8 one-million)
3741
:output-token-cost (/ 4.0 one-million)}} ;; + ollama local models + custom provider models
3842
:mcp-clients {}})

src/eca/llm_api.clj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
tools (when (:tools model-config)
8787
(mapv tool->llm-tool tools))
8888
web-search (:web-search model-config)
89+
max-output-tokens (:max-output-tokens model-config)
8990
custom-providers (:customProviders config)
9091
custom-models (set (mapcat (fn [[k v]]
9192
(map #(str (name k) "/" %) (:models v)))
@@ -103,6 +104,7 @@
103104
{:model model
104105
:instructions instructions
105106
:user-prompt user-prompt
107+
:max-output-tokens max-output-tokens
106108
:past-messages past-messages
107109
:tools tools
108110
:web-search web-search
@@ -117,6 +119,7 @@
117119
{:model model
118120
:instructions instructions
119121
:user-prompt user-prompt
122+
:max-output-tokens max-output-tokens
120123
:past-messages past-messages
121124
:tools tools
122125
:web-search web-search
@@ -148,6 +151,7 @@
148151
{:model model
149152
:instructions instructions
150153
:user-prompt user-prompt
154+
:max-output-tokens max-output-tokens
151155
:past-messages past-messages
152156
:web-search web-search
153157
:tools tools

src/eca/llm_providers/anthropic.clj

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,17 +76,16 @@
7676
#(assoc-in % [:content 0 :cache_control] {:type "ephemeral"})))
7777

7878
(defn completion!
79-
[{:keys [model user-prompt temperature instructions max-tokens
79+
[{:keys [model user-prompt temperature instructions max-output-tokens
8080
api-url api-key past-messages tools web-search]
81-
:or {max-tokens 8192
82-
temperature 1.0}}
81+
:or {temperature 1.0}}
8382
{:keys [on-message-received on-error on-prepare-tool-call on-tool-called]}]
8483
(let [messages (conj (past-messages->messages past-messages)
8584
{:role "user" :content [{:type :text
8685
:text user-prompt}]})
8786
body {:model model
8887
:messages (add-cache-to-last-message messages)
89-
:max_tokens max-tokens
88+
:max_tokens max-output-tokens
9089
:temperature temperature
9190
;; TODO support :thinking
9291
:stream true

src/eca/llm_providers/openai.clj

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
[clojure.java.io :as io]
55
[eca.llm-util :as llm-util]
66
[eca.logger :as logger]
7+
[eca.shared :refer [assoc-some]]
78
[hato.client :as http]))
89

910
(set! *warn-on-reflection* true)
@@ -54,7 +55,8 @@
5455
msg))
5556
past-messages))
5657

57-
(defn completion! [{:keys [model user-prompt instructions temperature api-key api-url past-messages tools web-search]
58+
(defn completion! [{:keys [model user-prompt instructions temperature api-key api-url
59+
max-output-tokens past-messages tools web-search]
5860
:or {temperature 1.0}}
5961
{:keys [on-message-received on-error on-prepare-tool-call on-tool-called on-reason]}]
6062
(let [input (conj (past-messages->input past-messages)
@@ -67,7 +69,8 @@
6769
:instructions instructions
6870
:temperature temperature
6971
:tools tools
70-
:stream true}
72+
:stream true
73+
:max_completion_tokens max-output-tokens}
7174
mcp-call-by-item-id* (atom {})
7275
on-response-fn
7376
(fn handle-response [event data]

0 commit comments

Comments
 (0)