| 1 | import { ModelConfig } from "@continuedev/config-yaml"; |
| 2 | import * as dotenv from "dotenv"; |
| 3 | import { DEEPSEEK_API_BASE } from "../apis/DeepSeek.js"; |
| 4 | import { INCEPTION_API_BASE } from "../apis/Inception.js"; |
| 5 | import { OpenAIApi } from "../apis/OpenAI.js"; |
| 6 | import { constructLlmApi } from "../index.js"; |
| 7 | import { getLlmApi, testChat, testCompletion, testEmbed } from "./util.js"; |
| 8 | |
| 9 | dotenv.config(); |
| 10 | |
| 11 | function testConfig(config: ModelConfig) { |
| 12 | const model = config.model; |
| 13 | const api = getLlmApi({ |
| 14 | provider: config.provider as any, |
| 15 | apiKey: config.apiKey, |
| 16 | apiBase: config.apiBase, |
| 17 | env: config.env, |
| 18 | }); |
| 19 | |
| 20 | if (false) { |
| 21 | testCompletion(api, model); |
| 22 | } |
| 23 | |
| 24 | if ( |
| 25 | ["chat", "summarize", "edit", "apply"].some((role) => |
| 26 | config.roles?.includes(role as any), |
| 27 | ) |
| 28 | ) { |
| 29 | testChat(api, model); |
| 30 | } |
| 31 | |
| 32 | if (config.roles?.includes("embed")) { |
| 33 | testEmbed(api, model); |
| 34 | } |
| 35 | |
| 36 | if (config.roles?.includes("embed")) { |
| 37 | testEmbed(api, model); |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | const TESTS: Omit<ModelConfig, "name">[] = [ |
| 42 | { |
| 43 | provider: "openai", |
| 44 | model: "gpt-4o", |
| 45 | apiKey: process.env.OPENAI_API_KEY!, |
| 46 | roles: ["chat"], |
| 47 | }, |
| 48 | { |
| 49 | provider: "anthropic", |
| 50 | model: "claude-3-5-haiku-latest", |
| 51 | apiKey: process.env.ANTHROPIC_API_KEY!, |
| 52 | roles: ["chat"], |
| 53 | }, |
| 54 | { |
| 55 | provider: "gemini", |
| 56 | model: "gemini-1.5-flash-latest", |
| 57 | apiKey: process.env.GEMINI_API_KEY!, |
| 58 | roles: ["chat"], |
| 59 | }, |
| 60 | { |
| 61 | provider: "mistral", |
| 62 | model: "codestral-latest", |
| 63 | apiKey: process.env.MISTRAL_API_KEY!, |
| 64 | apiBase: "https://api.mistral.ai/v1", |
| 65 | roles: ["autocomplete"], |
| 66 | }, |
| 67 | { |
| 68 | provider: "deepseek", |
| 69 | model: "deepseek-coder", |
| 70 | apiKey: process.env.DEEPSEEK_API_KEY!, |
| 71 | roles: ["autocomplete"], |
| 72 | }, |
| 73 | { |
| 74 | provider: "openai", |
| 75 | model: "text-embedding-3-small", |
| 76 | apiKey: process.env.OPENAI_API_KEY!, |
| 77 | roles: ["embed"], |
| 78 | }, |
| 79 | { |
| 80 | provider: "voyage", |
| 81 | model: "voyage-code-3", |
| 82 | apiKey: process.env.VOYAGE_API_KEY!, |
| 83 | roles: ["embed"], |
| 84 | }, |
| 85 | // { |
| 86 | // provider: "cohere", |
| 87 | // model: "embed-english-v3.0", |
| 88 | // apiKey: process.env.COHERE_API_KEY!, |
| 89 | // roles: ["embed"], |
| 90 | // }, |
| 91 | // { |
| 92 | // provider: "gemini", |
| 93 | // model: "models/text-embedding-004", |
| 94 | // apiKey: process.env.GEMINI_API_KEY!, |
| 95 | // roles: ["embed"], |
| 96 | // }, |
| 97 | { |
| 98 | provider: "voyage", |
| 99 | model: "rerank-lite-1", |
| 100 | apiKey: process.env.VOYAGE_API_KEY!, |
| 101 | roles: ["rerank"], |
| 102 | }, |
| 103 | // { |
| 104 | // provider: "cohere", |
| 105 | // model: "rerank-english-v3.0", |
| 106 | // apiKey: process.env.COHERE_API_KEY!, |
| 107 | // roles: ["rerank"], |
| 108 | // }, |
| 109 | ]; |
| 110 | |
| 111 | TESTS.forEach((config) => { |
| 112 | describe(`${config.provider}/${config.model}`, () => { |
| 113 | testConfig({ name: config.model, ...config }); |
| 114 | }); |
| 115 | }); |
| 116 | |
| 117 | describe("Configuration", () => { |
| 118 | it("should configure DeepSeek OpenAI client with correct apiBase and apiKey", () => { |
| 119 | const deepseek = constructLlmApi({ |
| 120 | provider: "deepseek", |
| 121 | apiKey: "sk-xxx", |
| 122 | }); |
| 123 | |
| 124 | expect((deepseek as OpenAIApi).openai.baseURL).toBe(DEEPSEEK_API_BASE); |
| 125 | expect((deepseek as OpenAIApi).openai.apiKey).toBe("sk-xxx"); |
| 126 | |
| 127 | const deepseek2 = constructLlmApi({ |
| 128 | provider: "deepseek", |
| 129 | apiKey: "sk-xxx", |
| 130 | apiBase: "https://api.example.com", |
| 131 | }); |
| 132 | expect((deepseek2 as OpenAIApi).openai.baseURL).toBe( |
| 133 | "https://api.example.com", |
| 134 | ); |
| 135 | }); |
| 136 | |
| 137 | it("should configure Inception OpenAI client with correct apiBase and apiKey", () => { |
| 138 | const inception = constructLlmApi({ |
| 139 | provider: "inception", |
| 140 | apiKey: "sk-xxx", |
| 141 | }); |
| 142 | |
| 143 | expect((inception as OpenAIApi).openai.baseURL).toBe(INCEPTION_API_BASE); |
| 144 | expect((inception as OpenAIApi).openai.apiKey).toBe("sk-xxx"); |
| 145 | |
| 146 | const inception2 = constructLlmApi({ |
| 147 | provider: "inception", |
| 148 | apiKey: "sk-xxx", |
| 149 | apiBase: "https://api.example.com", |
| 150 | }); |
| 151 | expect((inception2 as OpenAIApi).openai.baseURL).toBe( |
| 152 | "https://api.example.com", |
| 153 | ); |
| 154 | }); |
| 155 | }); |