Skip to content

Commit eb720ad

Browse files
committed
Improve ollama model listing getting capabilities, avoiding change ollama config for different models.
1 parent 7846a0d commit eb720ad

File tree

6 files changed

+54
-18
lines changed

6 files changed

+54
-18
lines changed

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+
- Improve ollama model listing getting capabilities, avoiding change ollama config for different models.
6+
57
## 0.13.0
68

79
- Support reasoning for ollama models that support think.

docs/configuration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ interface Config {
193193
"ollama" : {
194194
"host" : "http://localhost",
195195
"port" : 11434,
196-
"useTools": false,
196+
"useTools": true,
197197
"think": true
198198
},
199199
"chat" : {

src/eca/db.clj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,24 @@
1313
:chat-default-behavior "agent"
1414
:models {"o4-mini" {:tools true
1515
:web-search false
16+
:reason? true
1617
:input-token-cost (/ 1.10 one-million)
1718
:output-token-cost (/ 4.40 one-million)}
1819
"o3" {:tools true
1920
:web-search false
21+
:reason? true
2022
:input-token-cost (/ 2.0 one-million)
2123
:output-token-cost (/ 8.0 one-million)}
2224
"gpt-4.1" {:tools true
2325
:web-search true
26+
:reason? false
2427
:max-output-tokens 32000
2528
:input-token-cost (/ 2.0 one-million)
2629
:output-token-cost (/ 8.0 one-million)}
2730
"claude-sonnet-4-0" {:tools true
2831
:web-search true
2932
:max-output-tokens 8196
33+
:reason? true
3034
:reason-tokens 2048
3135
:input-token-cost (/ 3.0 one-million)
3236
:input-cache-creation-token-cost (/ 3.75 one-million)
@@ -35,13 +39,15 @@
3539
"claude-opus-4-0" {:tools true
3640
:web-search true
3741
:max-output-tokens 8196
42+
:reason? true
3843
:reason-tokens 2048
3944
:input-token-cost (/ 15.0 one-million)
4045
:input-cache-creation-token-cost (/ 18.75 one-million)
4146
:input-cache-read-token-cost (/ 1.5 one-million)
4247
:output-token-cost (/ 75.0 one-million)}
4348
"claude-3-5-haiku-latest" {:tools true
4449
:web-search true
50+
:reason? false
4551
:max-output-tokens 4096
4652
:input-token-cost (/ 0.8 one-million)
4753
:input-cache-creation-token-cost (/ 1.0 one-million)

src/eca/handlers.clj

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,14 @@
2828
{}
2929
custom-providers)))
3030
(when-let [ollama-models (seq (llm-api/extra-models config))]
31-
(swap! db* update :models merge
32-
(reduce
33-
(fn [models {:keys [model]}]
34-
(assoc models
35-
(str config/ollama-model-prefix model)
36-
{:tools (get-in config [:ollama :useTools] false)
37-
:think (get-in config [:ollama :think] false)}))
38-
{}
39-
ollama-models))))
31+
(let [models (reduce
32+
(fn [models {:keys [model] :as ollama-model}]
33+
(assoc models
34+
(str config/ollama-model-prefix model)
35+
(select-keys ollama-model [:tools :reason?])))
36+
{}
37+
ollama-models)]
38+
(swap! db* update :models merge models))))
4039

4140
(defn initialize [{:keys [db* config]} params]
4241
(logger/logging-task
@@ -81,8 +80,8 @@
8180

8281
(defn chat-tool-call-approve [{:keys [db*]} params]
8382
(logger/logging-task
84-
:eca/chat-tool-call-approve
85-
(f.chat/tool-call-approve params db*)))
83+
:eca/chat-tool-call-approve
84+
(f.chat/tool-call-approve params db*)))
8685

8786
(defn chat-tool-call-reject [{:keys [db*]} params]
8887
(logger/logging-task

src/eca/llm_api.clj

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,17 @@
1212
(def ^:private logger-tag "[LLM-API]")
1313

1414
(defn extra-models [config]
15-
(llm-providers.ollama/list-models {:host (:host (:ollama config))
16-
:port (:port (:ollama config))}))
15+
(let [ollama-host (:host (:ollama config))
16+
ollama-port (:port (:ollama config))]
17+
(mapv
18+
(fn [{:keys [model] :as ollama-model}]
19+
(let [capabilities (llm-providers.ollama/model-capabilities {:host ollama-host :port ollama-port :model model})]
20+
(assoc ollama-model
21+
:tools (and (get-in config [:ollama :useTools] true)
22+
(boolean (some #(= % "tools") capabilities)))
23+
:reason? (and (get-in config [:ollama :think] true)
24+
(boolean (some #(= % "thinking") capabilities))))))
25+
(llm-providers.ollama/list-models {:host ollama-host :port ollama-port}))))
1726

1827
;; TODO ask LLM for the most relevant parts of the path
1928
(defn refine-file-context [path lines-range]
@@ -116,7 +125,7 @@
116125
:user-messages user-messages
117126
:max-output-tokens max-output-tokens
118127
:reason-tokens reason-tokens
119-
:reason? reason?
128+
:reason? (and reason? (:reason? model-config))
120129
:past-messages past-messages
121130
:tools tools
122131
:web-search web-search
@@ -133,7 +142,7 @@
133142
:user-messages user-messages
134143
:max-output-tokens max-output-tokens
135144
:reason-tokens reason-tokens
136-
:reason? reason?
145+
:reason? (and reason? (:reason? model-config))
137146
:past-messages past-messages
138147
:tools tools
139148
:web-search web-search
@@ -145,7 +154,7 @@
145154
(llm-providers.ollama/completion!
146155
{:host (-> config :ollama :host)
147156
:port (-> config :ollama :port)
148-
:reason? (and reason? (:think model-config))
157+
:reason? (and reason? (:reason? model-config))
149158
:model (string/replace-first model config/ollama-model-prefix "")
150159
:instructions instructions
151160
:user-messages user-messages
@@ -168,7 +177,7 @@
168177
:user-messages user-messages
169178
:max-output-tokens max-output-tokens
170179
:reason-tokens reason-tokens
171-
:reason? reason?
180+
:reason? (and reason? (:reason? model-config))
172181
:past-messages past-messages
173182
:web-search web-search
174183
:tools tools

src/eca/llm_providers/ollama.clj

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
(def ^:private chat-url "%s/api/chat")
1414
(def ^:private list-models-url "%s/api/tags")
15+
(def ^:private show-model-url "%s/api/show")
1516

1617
(defn ^:private base-url [host port]
1718
(or (System/getenv "OLLAMA_API_BASE")
@@ -35,6 +36,25 @@
3536
(logger/warn logger-tag "Error listing running models:" (ex-message e))
3637
[])))
3738

39+
(defn model-capabilities [{:keys [host port model]}]
40+
(try
41+
(let [rid (llm-util/gen-rid)
42+
{:keys [status body]} (http/post
43+
(format show-model-url (base-url host port))
44+
{:throw-exceptions? false
45+
:body (json/generate-string {:model model})
46+
:as :json})]
47+
(if (= 200 status)
48+
(do
49+
(llm-util/log-response logger-tag rid "api/show" body)
50+
(:capabilities body))
51+
(do
52+
(logger/warn logger-tag "Unknown status code:" status)
53+
[])))
54+
(catch Exception e
55+
(logger/warn logger-tag "Error getting model:" (ex-message e))
56+
[])))
57+
3858
(defn ^:private base-completion-request! [{:keys [rid url body on-error on-response]}]
3959
(llm-util/log-request logger-tag rid url body)
4060
(let [reason-id (str (random-uuid))

0 commit comments

Comments
 (0)