|
62 | 62 | (defn ^:private real-model-name [model model-capabilities] |
63 | 63 | (or (:model-name model-capabilities) model)) |
64 | 64 |
|
| 65 | +(defn provider->api-handler [provider config] |
| 66 | + (cond |
| 67 | + (= "openai" provider) {:api :openai-responses |
| 68 | + :handler llm-providers.openai/create-response!} |
| 69 | + (= "anthropic" provider) {:api :anthropic |
| 70 | + :handler llm-providers.anthropic/chat!} |
| 71 | + (= "github-copilot" provider) {:api :openai-chat |
| 72 | + :handler llm-providers.openai-chat/chat-completion!} |
| 73 | + (= "google" provider) {:api :openai-chat |
| 74 | + :handler llm-providers.openai-chat/chat-completion!} |
| 75 | + (= "ollama" provider) {:api :ollama |
| 76 | + :handler llm-providers.ollama/chat!} |
| 77 | + :else (case (get-in config [:providers provider :api]) |
| 78 | + ("openai-responses" "openai") {:api :openai-responses |
| 79 | + :handler llm-providers.openai/create-response!} |
| 80 | + "anthropic" {:api :anthropic |
| 81 | + :handler llm-providers.anthropic/chat!} |
| 82 | + "openai-chat" {:api :openai-chat |
| 83 | + :handler llm-providers.openai-chat/chat-completion!} |
| 84 | + nil))) |
| 85 | + |
65 | 86 | (defn ^:private prompt! |
66 | 87 | [{:keys [provider model model-capabilities instructions user-messages config |
67 | 88 | on-message-received on-error on-prepare-tool-call on-tools-called on-reason on-usage-updated |
|
78 | 99 | extra-payload (:extraPayload model-config) |
79 | 100 | [auth-type api-key] (llm-util/provider-api-key provider provider-auth config) |
80 | 101 | api-url (llm-util/provider-api-url provider config) |
| 102 | + {:keys [handler]} (provider->api-handler provider config) |
81 | 103 | callbacks (when-not sync? |
82 | 104 | {:on-message-received on-message-received |
83 | 105 | :on-error on-error |
|
89 | 111 | (when-not api-url (throw (ex-info (format "API url not found.\nMake sure you have provider '%s' configured properly." provider) {}))) |
90 | 112 | (cond |
91 | 113 | (= "openai" provider) |
92 | | - (llm-providers.openai/create-response! |
| 114 | + (handler |
93 | 115 | {:model real-model |
94 | 116 | :instructions instructions |
95 | 117 | :user-messages user-messages |
|
107 | 129 | callbacks) |
108 | 130 |
|
109 | 131 | (= "anthropic" provider) |
110 | | - (llm-providers.anthropic/chat! |
| 132 | + (handler |
111 | 133 | {:model real-model |
112 | 134 | :instructions instructions |
113 | 135 | :user-messages user-messages |
|
124 | 146 | callbacks) |
125 | 147 |
|
126 | 148 | (= "github-copilot" provider) |
127 | | - (llm-providers.openai-chat/chat-completion! |
| 149 | + (handler |
128 | 150 | {:model real-model |
129 | 151 | :instructions instructions |
130 | 152 | :user-messages user-messages |
|
146 | 168 | callbacks) |
147 | 169 |
|
148 | 170 | (= "google" provider) |
149 | | - (llm-providers.openai-chat/chat-completion! |
| 171 | + (handler |
150 | 172 | {:model real-model |
151 | 173 | :instructions instructions |
152 | 174 | :user-messages user-messages |
|
166 | 188 | callbacks) |
167 | 189 |
|
168 | 190 | (= "ollama" provider) |
169 | | - (llm-providers.ollama/chat! |
| 191 | + (handler |
170 | 192 | {:api-url api-url |
171 | 193 | :reason? (:reason? model-capabilities) |
172 | 194 | :supports-image? supports-image? |
|
178 | 200 | :extra-payload extra-payload} |
179 | 201 | callbacks) |
180 | 202 |
|
181 | | - model-config |
182 | | - (let [provider-fn (case (:api provider-config) |
183 | | - ("openai-responses" |
184 | | - "openai") llm-providers.openai/create-response! |
185 | | - "anthropic" llm-providers.anthropic/chat! |
186 | | - "openai-chat" llm-providers.openai-chat/chat-completion! |
187 | | - (on-error {:message (format "Unknown model %s for provider %s" (:api provider-config) provider)})) |
188 | | - url-relative-path (:completionUrlRelativePath provider-config) |
| 203 | + (and model-config handler) |
| 204 | + (let [url-relative-path (:completionUrlRelativePath provider-config) |
189 | 205 | think-tag-start (:thinkTagStart provider-config) |
190 | 206 | think-tag-end (:thinkTagEnd provider-config) |
191 | 207 | http-client (:httpClient provider-config)] |
192 | | - (provider-fn |
| 208 | + (handler |
193 | 209 | {:model real-model |
194 | 210 | :instructions instructions |
195 | 211 | :user-messages user-messages |
|
0 commit comments