|
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] |
7 | 8 | [eca.llm-providers.ollama :as llm-providers.ollama] |
8 | 9 | [eca.llm-providers.openai :as llm-providers.openai] |
9 | 10 | [eca.llm-providers.openai-chat :as llm-providers.openai-chat] |
|
49 | 50 | (config/get-env "OPENAI_API_URL") |
50 | 51 | llm-providers.openai/base-url)) |
51 | 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 | + |
52 | 58 | (defn ^:private ollama-api-url [config] |
53 | 59 | (or (:ollamaApiUrl config) |
54 | 60 | (config/get-env "OLLAMA_API_URL") |
|
82 | 88 | (:models db)))] |
83 | 89 | [:custom-provider-default-model custom-provider-default-model]) |
84 | 90 | (when (anthropic-api-key config) |
85 | | - [:api-key-found "claude-sonnet-4-20250514"]) |
| 91 | + [:api-key-found "anthropic/claude-sonnet-4"]) |
86 | 92 | (when (openai-api-key config) |
87 | | - [:api-key-found "gpt-5"]) |
| 93 | + [:api-key-found "openai/gpt-5"]) |
88 | 94 | (when-let [ollama-model (first (filter #(string/starts-with? % config/ollama-model-prefix) (keys (:models db))))] |
89 | 95 | [:ollama-running ollama-model]) |
90 | | - [:default "claude-sonnet-4-20250514"])] |
| 96 | + [:default "anthropic/claude-sonnet-4"])] |
91 | 97 | (logger/info logger-tag (format "Default LLM model '%s' decision '%s'" model decision)) |
92 | 98 | model)) |
93 | 99 |
|
|
96 | 102 | :type "function")) |
97 | 103 |
|
98 | 104 | (defn complete! |
99 | | - [{:keys [model provider model-config instructions user-messages config on-first-response-received |
| 105 | + [{:keys [provider model model-config instructions user-messages config on-first-response-received |
100 | 106 | on-message-received on-error on-prepare-tool-call on-tools-called on-reason on-usage-updated |
101 | | - past-messages tools]}] |
| 107 | + past-messages tools provider-auth]}] |
102 | 108 | (let [first-response-received* (atom false) |
103 | 109 | emit-first-message-fn (fn [& args] |
104 | 110 | (when-not @first-response-received* |
|
164 | 170 | :api-key (anthropic-api-key config)} |
165 | 171 | callbacks) |
166 | 172 |
|
| 173 | + (= "github-copilot" provider) |
| 174 | + (llm-providers.openai-chat/completion! |
| 175 | + {:model model |
| 176 | + :instructions instructions |
| 177 | + :user-messages user-messages |
| 178 | + :max-output-tokens max-output-tokens |
| 179 | + :reason? (:reason? model-config) |
| 180 | + :past-messages past-messages |
| 181 | + :tools tools |
| 182 | + :extra-payload extra-payload |
| 183 | + :api-url (github-copilot-api-url config) |
| 184 | + :api-key (:api-token provider-auth) |
| 185 | + :extra-headers {"openai-intent" "conversation-panel" |
| 186 | + "x-request-id" (str (random-uuid)) |
| 187 | + "vscode-sessionid" "" |
| 188 | + "vscode-machineid" "" |
| 189 | + "copilot-integration-id" "vscode-chat"}} |
| 190 | + callbacks) |
| 191 | + |
167 | 192 | (string/starts-with? model config/ollama-model-prefix) |
168 | 193 | (llm-providers.ollama/completion! |
169 | 194 | {:api-url (ollama-api-url config) |
|
206 | 231 | (on-error-wrapper {:message (str "ECA Unsupported model: " model)})) |
207 | 232 | (catch Exception e |
208 | 233 | (on-error-wrapper {:exception e}))))) |
| 234 | + |
| 235 | +(defn auth-start [{:keys [provider]}] |
| 236 | + (try |
| 237 | + (case provider |
| 238 | + "github-copilot" (let [auth (llm-providers.copilot/auth-url)] |
| 239 | + {:auth-type :oauth/simple |
| 240 | + :url (:url auth) |
| 241 | + :device-code (:device-code auth) |
| 242 | + :user-code (:user-code auth)}) |
| 243 | + {:error-message (str "Unknown provider: " provider)}) |
| 244 | + (catch Exception e |
| 245 | + {:error-message (format "Error log into provider %s: %s" provider (.getMessage e))}))) |
| 246 | + |
| 247 | +(defn auth-continue [{:keys [provider db*]}] |
| 248 | + (try |
| 249 | + (case provider |
| 250 | + "github-copilot" (let [{:keys [api-token expires-at]} (llm-providers.copilot/auth-exchange (get-in @db* [:auth provider :device-code]))] |
| 251 | + {:api-token api-token |
| 252 | + :expires-at expires-at}) |
| 253 | + {:error-message (str "Unknown provider: " provider)}) |
| 254 | + (catch Exception e |
| 255 | + (logger/error logger-tag "Error on login: " e) |
| 256 | + {:error-message (format "Error log into provider %s: %s" provider (.getMessage e))}))) |
0 commit comments