|
| 1 | +(ns eca.llm-api-test |
| 2 | + (:require |
| 3 | + [clojure.test :refer [deftest is testing]] |
| 4 | + [eca.config :as config] |
| 5 | + [eca.llm-api :as llm-api] |
| 6 | + [eca.test-helper :as h])) |
| 7 | + |
| 8 | +(h/reset-components-before-test) |
| 9 | + |
| 10 | +(deftest default-model-test |
| 11 | + (testing "Custom provider default-model? present" |
| 12 | + (with-redefs [config/get-env (constantly nil)] |
| 13 | + (let [db {:models {"my-model" {:custom-provider? true :default-model? true}}} |
| 14 | + config {}] |
| 15 | + (is (= "my-model" (llm-api/default-model db config)))))) |
| 16 | + |
| 17 | + (testing "Ollama running model present" |
| 18 | + (with-redefs [config/get-env (constantly nil)] |
| 19 | + (let [db {:models {"ollama/foo" {:tools true} |
| 20 | + "gpt-4.1" {:tools true} |
| 21 | + "other-model" {:tools true}}} |
| 22 | + config {}] |
| 23 | + (is (= "ollama/foo" (llm-api/default-model db config)))))) |
| 24 | + |
| 25 | + (testing "Anthropic API key present in config" |
| 26 | + (with-redefs [config/get-env (constantly nil)] |
| 27 | + (let [db {:models {}} |
| 28 | + config {:anthropicApiKey "something"}] |
| 29 | + (is (= "claude-sonnet-4-0" (llm-api/default-model db config)))))) |
| 30 | + |
| 31 | + (testing "Anthropic API key present in ENV" |
| 32 | + (with-redefs [config/get-env (fn [k] (when (= k "ANTHROPIC_API_KEY") "env-anthropic"))] |
| 33 | + (let [db {:models {}} |
| 34 | + config {}] |
| 35 | + (is (= "claude-sonnet-4-0" (llm-api/default-model db config)))))) |
| 36 | + |
| 37 | + (testing "OpenAI API key present in config" |
| 38 | + (with-redefs [config/get-env (constantly nil)] |
| 39 | + (let [db {:models {}} |
| 40 | + config {:openaiapikey "yes!"}] |
| 41 | + (is (= "o4-mini" (llm-api/default-model db config)))))) |
| 42 | + |
| 43 | + (testing "OpenAI API key present in ENV" |
| 44 | + (with-redefs [config/get-env (fn [k] (when (= k "OPENAI_API_KEY") "env-openai"))] |
| 45 | + (let [db {:models {}} |
| 46 | + config {}] |
| 47 | + (is (= "o4-mini" (llm-api/default-model db config)))))) |
| 48 | + |
| 49 | + (testing "Fallback default (no keys anywhere)" |
| 50 | + (with-redefs [config/get-env (constantly nil)] |
| 51 | + (let [db {:models {}} |
| 52 | + config {}] |
| 53 | + (is (= "claude-sonnet-4-0" (llm-api/default-model db config))))))) |
0 commit comments