|
21 | 21 |
|
22 | 22 | (defn ^:private anthropic-api-key [config] |
23 | 23 | (or (:anthropicApiKey config) |
24 | | - (System/getenv "ANTHROPIC_API_KEY"))) |
| 24 | + (config/get-env "ANTHROPIC_API_KEY"))) |
| 25 | + |
| 26 | +(defn ^:private anthropic-api-url [] |
| 27 | + (or (System/getenv "ANTHROPIC_API_URL") |
| 28 | + llm-providers.anthropic/base-url)) |
25 | 29 |
|
26 | 30 | (defn ^:private openai-api-key [config] |
27 | | - (or (:openaiApiKey config) |
28 | | - (System/getenv "OPENAI_API_KEY"))) |
| 31 | + (or (:openaiapikey config) |
| 32 | + (config/get-env "openai_api_key"))) |
| 33 | + |
| 34 | +(defn ^:private openai-api-url [] |
| 35 | + (or (config/get-env "OPENAI_API_URL") |
| 36 | + llm-providers.openai/base-url)) |
29 | 37 |
|
30 | 38 | (defn default-model |
31 | 39 | "Returns the default LLM model checking this waterfall: |
|
68 | 76 | (on-error args))) |
69 | 77 | tools (when (:tools model-config) |
70 | 78 | (mapv tool->llm-tool tools)) |
71 | | - web-search (:web-search model-config)] |
| 79 | + web-search (:web-search model-config) |
| 80 | + custom-providers (:customProviders config) |
| 81 | + custom-models (set (mapcat (fn [[k v]] |
| 82 | + (map #(str (name k) "/" %) (:models v))) |
| 83 | + custom-providers)) |
| 84 | + callbacks {:on-message-received on-message-received-wrapper |
| 85 | + :on-error on-error-wrapper |
| 86 | + :on-prepare-tool-call on-prepare-tool-call-wrapper |
| 87 | + :on-tool-called on-tool-called |
| 88 | + :on-reason on-reason}] |
72 | 89 | (cond |
73 | 90 | (contains? #{"o4-mini" |
74 | 91 | "o3" |
|
80 | 97 | :past-messages past-messages |
81 | 98 | :tools tools |
82 | 99 | :web-search web-search |
| 100 | + :api-url (openai-api-url) |
83 | 101 | :api-key (openai-api-key config)} |
84 | | - {:on-message-received on-message-received-wrapper |
85 | | - :on-error on-error-wrapper |
86 | | - :on-prepare-tool-call on-prepare-tool-call-wrapper |
87 | | - :on-tool-called on-tool-called |
88 | | - :on-reason on-reason}) |
| 102 | + callbacks) |
89 | 103 |
|
90 | 104 | (contains? #{"claude-sonnet-4-0" |
91 | 105 | "claude-opus-4-0" |
|
97 | 111 | :past-messages past-messages |
98 | 112 | :tools tools |
99 | 113 | :web-search web-search |
| 114 | + :api-url (anthropic-api-url) |
100 | 115 | :api-key (anthropic-api-key config)} |
101 | | - {:on-message-received on-message-received-wrapper |
102 | | - :on-error on-error-wrapper |
103 | | - :on-prepare-tool-call on-prepare-tool-call-wrapper |
104 | | - :on-tool-called on-tool-called |
105 | | - :on-reason on-reason}) |
| 116 | + callbacks) |
106 | 117 |
|
107 | 118 | (string/starts-with? model config/ollama-model-prefix) |
108 | 119 | (llm-providers.ollama/completion! |
109 | 120 | {:host (-> config :ollama :host) |
110 | 121 | :port (-> config :ollama :port) |
111 | 122 | :model (string/replace-first model config/ollama-model-prefix "") |
112 | | - :past-messages past-messages |
113 | 123 | :context context |
114 | | - :tools tools |
115 | | - :user-prompt user-prompt} |
116 | | - {:on-message-received on-message-received-wrapper |
117 | | - :on-error on-error-wrapper |
118 | | - :on-prepare-tool-call on-prepare-tool-call-wrapper |
119 | | - :on-tool-called on-tool-called |
120 | | - :on-reason on-reason}) |
| 124 | + :user-prompt user-prompt |
| 125 | + :past-messages past-messages |
| 126 | + :tools tools} |
| 127 | + callbacks) |
| 128 | + |
| 129 | + (contains? custom-models model) |
| 130 | + (let [[provider model] (string/split model #"/") |
| 131 | + provider-config (get custom-providers (keyword provider)) |
| 132 | + provider-fn (case (:api provider-config) |
| 133 | + "openai" llm-providers.openai/completion! |
| 134 | + "anthropic" llm-providers.anthropic/completion! |
| 135 | + (on-error-wrapper {:msg (format "Unknown custom model %s for provider %s" (:api provider-config) provider)})) |
| 136 | + url (or (:url provider-config) (config/get-env (:urlEnv provider-config))) |
| 137 | + key (or (:key provider-config) (config/get-env (:keyEnv provider-config)))] |
| 138 | + (provider-fn |
| 139 | + {:model model |
| 140 | + :context context |
| 141 | + :user-prompt user-prompt |
| 142 | + :past-messages past-messages |
| 143 | + :tools tools |
| 144 | + :api-url url |
| 145 | + :api-key key} |
| 146 | + callbacks)) |
121 | 147 |
|
122 | 148 | :else |
123 | 149 | (on-error-wrapper {:msg (str "ECA Unsupported model: " model)})))) |
0 commit comments