|
116 | 116 | :on-tools-called on-tools-called |
117 | 117 | :on-reason on-reason-wrapper |
118 | 118 | :on-usage-updated on-usage-updated}] |
119 | | - (cond |
120 | | - (= "openai" provider) |
121 | | - (llm-providers.openai/completion! |
122 | | - {:model model |
123 | | - :instructions instructions |
124 | | - :user-messages user-messages |
125 | | - :max-output-tokens max-output-tokens |
126 | | - :reason? (and reason? (:reason? model-config)) |
127 | | - :past-messages past-messages |
128 | | - :tools tools |
129 | | - :web-search web-search |
130 | | - :extra-payload extra-payload |
131 | | - :api-url (openai-api-url) |
132 | | - :api-key (openai-api-key config)} |
133 | | - callbacks) |
134 | | - |
135 | | - (= "anthropic" provider) |
136 | | - (llm-providers.anthropic/completion! |
137 | | - {:model model |
138 | | - :instructions instructions |
139 | | - :user-messages user-messages |
140 | | - :max-output-tokens max-output-tokens |
141 | | - :reason? (and reason? (:reason? model-config)) |
142 | | - :past-messages past-messages |
143 | | - :tools tools |
144 | | - :web-search web-search |
145 | | - :extra-payload extra-payload |
146 | | - :api-url (anthropic-api-url) |
147 | | - :api-key (anthropic-api-key config)} |
148 | | - callbacks) |
149 | | - |
150 | | - (string/starts-with? model config/ollama-model-prefix) |
151 | | - (llm-providers.ollama/completion! |
152 | | - {:host (-> config :ollama :host) |
153 | | - :port (-> config :ollama :port) |
154 | | - :reason? (and reason? (:reason? model-config)) |
155 | | - :model (string/replace-first model config/ollama-model-prefix "") |
156 | | - :instructions instructions |
157 | | - :user-messages user-messages |
158 | | - :past-messages past-messages |
159 | | - :tools tools |
160 | | - :extra-payload extra-payload} |
161 | | - callbacks) |
162 | | - |
163 | | - (contains? custom-models model) |
164 | | - (let [[provider model] (string/split model #"/" 2) |
165 | | - provider-config (get custom-providers (keyword provider)) |
166 | | - provider-fn (case (:api provider-config) |
167 | | - "openai" llm-providers.openai/completion! |
168 | | - "anthropic" llm-providers.anthropic/completion! |
169 | | - (on-error-wrapper {:message (format "Unknown custom model %s for provider %s" (:api provider-config) provider)})) |
170 | | - url (or (:url provider-config) (config/get-env (:urlEnv provider-config))) |
171 | | - key (or (:key provider-config) (config/get-env (:keyEnv provider-config)))] |
172 | | - (provider-fn |
| 119 | + (try |
| 120 | + (cond |
| 121 | + (= "openai" provider) |
| 122 | + (llm-providers.openai/completion! |
173 | 123 | {:model model |
174 | 124 | :instructions instructions |
175 | 125 | :user-messages user-messages |
176 | 126 | :max-output-tokens max-output-tokens |
177 | 127 | :reason? (and reason? (:reason? model-config)) |
178 | 128 | :past-messages past-messages |
| 129 | + :tools tools |
179 | 130 | :web-search web-search |
| 131 | + :extra-payload extra-payload |
| 132 | + :api-url (openai-api-url) |
| 133 | + :api-key (openai-api-key config)} |
| 134 | + callbacks) |
| 135 | + |
| 136 | + (= "anthropic" provider) |
| 137 | + (llm-providers.anthropic/completion! |
| 138 | + {:model model |
| 139 | + :instructions instructions |
| 140 | + :user-messages user-messages |
| 141 | + :max-output-tokens max-output-tokens |
| 142 | + :reason? (and reason? (:reason? model-config)) |
| 143 | + :past-messages past-messages |
180 | 144 | :tools tools |
| 145 | + :web-search web-search |
181 | 146 | :extra-payload extra-payload |
182 | | - :api-url url |
183 | | - :api-key key} |
184 | | - callbacks)) |
| 147 | + :api-url (anthropic-api-url) |
| 148 | + :api-key (anthropic-api-key config)} |
| 149 | + callbacks) |
| 150 | + |
| 151 | + (string/starts-with? model config/ollama-model-prefix) |
| 152 | + (llm-providers.ollama/completion! |
| 153 | + {:host (-> config :ollama :host) |
| 154 | + :port (-> config :ollama :port) |
| 155 | + :reason? (and reason? (:reason? model-config)) |
| 156 | + :model (string/replace-first model config/ollama-model-prefix "") |
| 157 | + :instructions instructions |
| 158 | + :user-messages user-messages |
| 159 | + :past-messages past-messages |
| 160 | + :tools tools |
| 161 | + :extra-payload extra-payload} |
| 162 | + callbacks) |
| 163 | + |
| 164 | + (contains? custom-models model) |
| 165 | + (let [[provider model] (string/split model #"/" 2) |
| 166 | + provider-config (get custom-providers (keyword provider)) |
| 167 | + provider-fn (case (:api provider-config) |
| 168 | + "openai" llm-providers.openai/completion! |
| 169 | + "anthropic" llm-providers.anthropic/completion! |
| 170 | + (on-error-wrapper {:message (format "Unknown custom model %s for provider %s" (:api provider-config) provider)})) |
| 171 | + url (or (:url provider-config) (config/get-env (:urlEnv provider-config))) |
| 172 | + key (or (:key provider-config) (config/get-env (:keyEnv provider-config)))] |
| 173 | + (provider-fn |
| 174 | + {:model model |
| 175 | + :instructions instructions |
| 176 | + :user-messages user-messages |
| 177 | + :max-output-tokens max-output-tokens |
| 178 | + :reason? (and reason? (:reason? model-config)) |
| 179 | + :past-messages past-messages |
| 180 | + :web-search web-search |
| 181 | + :tools tools |
| 182 | + :extra-payload extra-payload |
| 183 | + :api-url url |
| 184 | + :api-key key} |
| 185 | + callbacks)) |
185 | 186 |
|
186 | | - :else |
187 | | - (on-error-wrapper {:message (str "ECA Unsupported model: " model)})))) |
| 187 | + :else |
| 188 | + (on-error-wrapper {:message (str "ECA Unsupported model: " model)})) |
| 189 | + (catch Exception e |
| 190 | + (on-error-wrapper {:exception e}))))) |
0 commit comments