|
4 | 4 | [clojure.string :as string] |
5 | 5 | [eca.config :as config] |
6 | 6 | [eca.llm-providers.anthropic :as llm-providers.anthropic] |
7 | | - [eca.llm-providers.copilot :as llm-providers.copilot] |
8 | 7 | [eca.llm-providers.ollama :as llm-providers.ollama] |
9 | 8 | [eca.llm-providers.openai :as llm-providers.openai] |
10 | 9 | [eca.llm-providers.openai-chat :as llm-providers.openai-chat] |
|
32 | 31 | (string/join "\n" (subvec lines start end))) |
33 | 32 | content)))) |
34 | 33 |
|
35 | | -(defn ^:private anthropic-api-key [config] |
36 | | - (or (:anthropicApiKey config) |
37 | | - (config/get-env "ANTHROPIC_API_KEY"))) |
| 34 | +(defn ^:private provider-api-key [provider config] |
| 35 | + (or (get-in config [:providers (name provider) :key]) |
| 36 | + (config/get-env (str (-> provider |
| 37 | + (string/replace "-" "_") |
| 38 | + string/upper-case) "_API_KEY")))) |
38 | 39 |
|
39 | | -(defn ^:private anthropic-api-url [config] |
40 | | - (or (:anthropicApiUrl config) |
41 | | - (config/get-env "ANTHROPIC_API_URL") |
42 | | - llm-providers.anthropic/base-url)) |
43 | | - |
44 | | -(defn ^:private openai-api-key [config] |
45 | | - (or (:openaiApiKey config) |
46 | | - (config/get-env "OPENAI_API_KEY"))) |
47 | | - |
48 | | -(defn ^:private openai-api-url [config] |
49 | | - (or (:openaiApiUrl config) |
50 | | - (config/get-env "OPENAI_API_URL") |
51 | | - llm-providers.openai/base-url)) |
52 | | - |
53 | | -(defn ^:private github-copilot-api-url [config] |
54 | | - (or (:githubCopilotApiUrl config) |
55 | | - (config/get-env "GITHUB_COPILOT_API_URL") |
56 | | - llm-providers.copilot/base-api-url)) |
57 | | - |
58 | | -(defn ^:private ollama-api-url [config] |
59 | | - (or (:ollamaApiUrl config) |
60 | | - (config/get-env "OLLAMA_API_URL") |
61 | | - llm-providers.ollama/base-url)) |
| 40 | +(defn ^:private provider-api-url [provider config] |
| 41 | + (or (get-in config [:providers (name provider) :url]) |
| 42 | + (config/get-env (str (-> provider |
| 43 | + (string/replace "-" "_") |
| 44 | + string/upper-case) "_API_URL")))) |
62 | 45 |
|
63 | 46 | (defn extra-models [config] |
64 | | - (let [ollama-api-url (ollama-api-url config)] |
| 47 | + (let [ollama-api-url (provider-api-url "ollama" config)] |
65 | 48 | (mapv |
66 | 49 | (fn [{:keys [model] :as ollama-model}] |
67 | 50 | (let [capabilities (llm-providers.ollama/model-capabilities {:api-url ollama-api-url :model model})] |
|
86 | 69 | model)) |
87 | 70 | (:models db)))] |
88 | 71 | [:custom-provider-default-model custom-provider-default-model]) |
89 | | - (when (anthropic-api-key config) |
| 72 | + (when (provider-api-key "anthropic" config) |
90 | 73 | [:api-key-found "anthropic/claude-sonnet-4-20250514"]) |
91 | | - (when (openai-api-key config) |
| 74 | + (when (provider-api-key "openai" config) |
92 | 75 | [:api-key-found "openai/gpt-5"]) |
93 | 76 | (when (get-in db [:auth "github-copilot" :api-key]) |
94 | 77 | [:api-key-found "github-copilot/gpt-4.1"]) |
|
133 | 116 | (map #(str (name k) "/" %) (:models v))) |
134 | 117 | custom-providers)) |
135 | 118 | extra-payload (get-in config [:models (keyword model) :extraPayload]) |
| 119 | + provider-api-key (provider-api-key provider config) |
| 120 | + provider-api-url (provider-api-url provider config) |
136 | 121 | callbacks {:on-message-received on-message-received-wrapper |
137 | 122 | :on-error on-error-wrapper |
138 | 123 | :on-prepare-tool-call on-prepare-tool-call-wrapper |
|
152 | 137 | :tools tools |
153 | 138 | :web-search web-search |
154 | 139 | :extra-payload extra-payload |
155 | | - :api-url (openai-api-url config) |
156 | | - :api-key (openai-api-key config)} |
| 140 | + :api-url provider-api-url |
| 141 | + :api-key provider-api-key} |
157 | 142 | callbacks) |
158 | 143 |
|
159 | 144 | (= "anthropic" provider) |
|
167 | 152 | :tools tools |
168 | 153 | :web-search web-search |
169 | 154 | :extra-payload extra-payload |
170 | | - :api-url (anthropic-api-url config) |
171 | | - :api-key (anthropic-api-key config)} |
| 155 | + :api-url provider-api-url |
| 156 | + :api-key provider-api-key} |
172 | 157 | callbacks) |
173 | 158 |
|
174 | 159 | (= "github-copilot" provider) |
|
181 | 166 | :past-messages past-messages |
182 | 167 | :tools tools |
183 | 168 | :extra-payload extra-payload |
184 | | - :api-url (github-copilot-api-url config) |
| 169 | + :api-url provider-api-url |
185 | 170 | :api-key (:api-token provider-auth) |
186 | 171 | :extra-headers {"openai-intent" "conversation-panel" |
187 | 172 | "x-request-id" (str (random-uuid)) |
|
192 | 177 |
|
193 | 178 | (= "ollama" provider) |
194 | 179 | (llm-providers.ollama/completion! |
195 | | - {:api-url (ollama-api-url config) |
| 180 | + {:api-url provider-api-url |
196 | 181 | :reason? (:reason? model-config) |
197 | 182 | :model model |
198 | 183 | :instructions instructions |
|
0 commit comments