|
11 | 11 | (def ^:private logger-tag "[OLLAMA]") |
12 | 12 |
|
13 | 13 | (def ^:private chat-url "%s/api/chat") |
14 | | -(def ^:private list-running-models-url "%s/api/ps") |
| 14 | +(def ^:private list-models-url "%s/api/tags") |
15 | 15 |
|
16 | 16 | (defn ^:private base-url [host port] |
17 | 17 | (or (System/getenv "OLLAMA_API_BASE") |
18 | 18 | (str host ":" port))) |
19 | 19 |
|
20 | | -(defn list-running-models [{:keys [host port]}] |
| 20 | +(defn list-models [{:keys [host port]}] |
21 | 21 | (try |
22 | 22 | (let [{:keys [status body]} (http/get |
23 | | - (format list-running-models-url (base-url host port)) |
| 23 | + (format list-models-url (base-url host port)) |
24 | 24 | {:throw-exceptions? false |
25 | 25 | :as :json})] |
26 | 26 | (if (= 200 status) |
27 | 27 | (do |
28 | | - (llm-util/log-response logger-tag "api_ps" body) |
| 28 | + (llm-util/log-response logger-tag "api/tags" body) |
29 | 29 | (:models body)) |
30 | 30 | (do |
31 | 31 | (logger/warn logger-tag "Unknown status code:" status) |
|
34 | 34 | (logger/warn logger-tag "Error listing running models:" (ex-message e)) |
35 | 35 | []))) |
36 | 36 |
|
37 | | -(defn ^:private ->message-with-context [context user-prompt] |
38 | | - (format "%s\nThe user is asking: '%s'" context user-prompt)) |
39 | | - |
40 | 37 | (defn ^:private base-completion-request! [{:keys [url body on-error on-response]}] |
41 | 38 | (logger/debug logger-tag (format "Sending body: '%s', url: '%s'" body url)) |
42 | 39 | (http/post |
|
67 | 64 |
|
68 | 65 | (defn completion! [{:keys [model user-prompt context host port past-messages tools]} |
69 | 66 | {:keys [on-message-received on-error on-prepare-tool-call on-tool-called]}] |
70 | | - (let [messages (if (empty? past-messages) |
71 | | - [{:role "user" :content (->message-with-context context user-prompt)}] |
72 | | - (conj past-messages {:role "user" :content user-prompt})) |
| 67 | + (let [messages (concat |
| 68 | + [{:role "system" :content context}] |
| 69 | + past-messages |
| 70 | + [{:role "user" :content user-prompt}]) |
73 | 71 | body {:model model |
74 | 72 | :messages messages |
75 | 73 | :think false |
|
0 commit comments