Elffuss BraidHub

kikocis/continue public

9c134d8c1202 · 8.1 KiBRawPermalink
1import { ModelConfig } from "@continuedev/config-yaml";
2import * as dotenv from "dotenv";
3import { vi } from "vitest";
4import { DEEPSEEK_API_BASE } from "../apis/DeepSeek.js";
5import { INCEPTION_API_BASE } from "../apis/Inception.js";
6import { OpenAIApi } from "../apis/OpenAI.js";
7import { constructLlmApi } from "../index.js";
8import { getLlmApi, testChat, testEmbed, testFim, testRerank } from "./util.js";
9
10dotenv.config();
11
12export interface TestConfigOptions {
13 skipTools: boolean;
14 expectUsage?: boolean;
15}
16
17function testConfig(_config: ModelConfig & { options?: TestConfigOptions }) {
18 const { options, ...config } = _config;
19 const model = config.model;
20 const api = getLlmApi({
21 provider: config.provider as any,
22 apiKey: config.apiKey,
23 apiBase: config.apiBase,
24 env: config.env,
25 });
26
27 if (
28 ["chat", "summarize", "edit", "apply"].some((role) =>
29 config.roles?.includes(role as any),
30 )
31 ) {
32 testChat(api, model, options);
33 }
34
35 if (config.roles?.includes("embed")) {
36 testEmbed(api, model);
37 }
38
39 if (config.roles?.includes("rerank")) {
40 testRerank(api, model);
41 }
42
43 if (config.roles?.includes("autocomplete")) {
44 testFim(api, model);
45 }
46}
47
48const TESTS: Omit<ModelConfig & { options?: TestConfigOptions }, "name">[] = [
49 {
50 provider: "openai",
51 model: "gpt-4o",
52 apiKey: process.env.OPENAI_API_KEY!,
53 roles: ["chat"],
54 options: {
55 skipTools: false,
56 expectUsage: true,
57 },
58 },
59 {
60 provider: "openai",
61 model: "gpt-4o-mini",
62 apiKey: process.env.OPENAI_API_KEY!,
63 roles: ["chat"],
64 options: {
65 skipTools: false,
66 expectUsage: true,
67 },
68 },
69 {
70 provider: "anthropic",
71 model: "claude-3-5-haiku-latest",
72 apiKey: process.env.ANTHROPIC_API_KEY!,
73 roles: ["chat"],
74 options: {
75 skipTools: false,
76 expectUsage: true,
77 },
78 },
79 {
80 provider: "gemini",
81 model: "gemini-1.5-flash-latest",
82 apiKey: process.env.GEMINI_API_KEY!,
83 roles: ["chat"],
84 options: {
85 skipTools: false,
86 expectUsage: true,
87 },
88 },
89 {
90 provider: "gemini",
91 model: "gemini-2.5-flash",
92 apiKey: process.env.GEMINI_API_KEY!,
93 roles: ["chat"],
94 options: {
95 skipTools: false,
96 expectUsage: true,
97 },
98 },
99 {
100 provider: "mistral",
101 model: "codestral",
102 apiKey: process.env.MISTRAL_API_KEY!,
103 roles: ["chat"],
104 options: {
105 skipTools: false,
106 expectUsage: true,
107 },
108 },
109 // {
110 // provider: "deepseek",
111 // model: "deepseek-coder",
112 // apiKey: process.env.DEEPSEEK_API_KEY!,
113 // roles: ["autocomplete"],
114 // },
115 {
116 provider: "openai",
117 model: "text-embedding-3-small",
118 apiKey: process.env.OPENAI_API_KEY!,
119 roles: ["embed"],
120 },
121 {
122 provider: "voyage",
123 model: "voyage-code-3",
124 apiKey: process.env.VOYAGE_API_KEY!,
125 roles: ["embed"],
126 },
127 // {
128 // provider: "cohere",
129 // model: "embed-v4.0",
130 // apiKey: process.env.COHERE_API_KEY!,
131 // roles: ["embed"],
132 // },
133 // {
134 // provider: "gemini",
135 // model: "models/text-embedding-004",
136 // apiKey: process.env.GEMINI_API_KEY!,
137 // roles: ["embed"],
138 // },
139 {
140 provider: "voyage",
141 model: "rerank-lite-1",
142 apiKey: process.env.VOYAGE_API_KEY!,
143 roles: ["rerank"],
144 },
145 {
146 provider: "relace",
147 model: "instant-apply",
148 apiKey: process.env.RELACE_API_KEY!,
149 roles: ["chat"],
150 options: {
151 skipTools: true,
152 expectUsage: true,
153 },
154 },
155 {
156 provider: "inception",
157 model: "mercury-coder",
158 apiKey: process.env.INCEPTION_API_KEY!,
159 roles: ["chat"],
160 options: {
161 skipTools: false,
162 expectUsage: true,
163 },
164 },
165 // {
166 // provider: "cohere",
167 // model: "rerank-v3.5",
168 // apiKey: process.env.COHERE_API_KEY!,
169 // roles: ["rerank"],
170 // },
171 {
172 provider: "azure",
173 model: "gpt-4.1",
174 apiBase: "https://continue-openai.openai.azure.com",
175 apiKey: process.env.AZURE_OPENAI_GPT41_API_KEY,
176 roles: ["chat"],
177 env: {
178 deployment: "gpt-4.1",
179 apiVersion: "2024-02-15-preview",
180 apiType: "azure-openai",
181 },
182 },
183];
184
185if (process.env.IGNORE_API_KEY_TESTS === "true") {
186 test("Skipping API key tests", () => {
187 console.log("Skipping API key tests due to IGNORE_API_KEY_TESTS being set");
188 });
189} else {
190 TESTS.forEach((config) => {
191 describe(`${config.provider}/${config.model}`, () => {
192 vi.setConfig({ testTimeout: 30000 });
193 testConfig({ name: config.model, ...config });
194 });
195 });
196}
197
198describe("Configuration", () => {
199 it("should configure DeepSeek OpenAI client with correct apiBase and apiKey", () => {
200 const deepseek = constructLlmApi({
201 provider: "deepseek",
202 apiKey: "sk-xxx",
203 });
204
205 expect((deepseek as OpenAIApi).openai.baseURL).toBe(DEEPSEEK_API_BASE);
206 expect((deepseek as OpenAIApi).openai.apiKey).toBe("sk-xxx");
207
208 const deepseek2 = constructLlmApi({
209 provider: "deepseek",
210 apiKey: "sk-xxx",
211 apiBase: "https://api.example.com",
212 });
213 expect((deepseek2 as OpenAIApi).openai.baseURL).toBe(
214 "https://api.example.com",
215 );
216 });
217
218 it("should configure Inception OpenAI client with correct apiBase and apiKey", () => {
219 const inception = constructLlmApi({
220 provider: "inception",
221 apiKey: "sk-xxx",
222 });
223
224 expect((inception as OpenAIApi).openai.baseURL).toBe(INCEPTION_API_BASE);
225 expect((inception as OpenAIApi).openai.apiKey).toBe("sk-xxx");
226
227 const inception2 = constructLlmApi({
228 provider: "inception",
229 apiKey: "sk-xxx",
230 apiBase: "https://api.example.com",
231 });
232 expect((inception2 as OpenAIApi).openai.baseURL).toBe(
233 "https://api.example.com",
234 );
235 });
236
237 it("should configure Azure OpenAI client with root URL and trailing slash", () => {
238 const azure = constructLlmApi({
239 provider: "azure",
240 apiKey: "sk-xxx",
241 apiBase: "https://test-azure-openai.azure.com/",
242 env: {
243 deployment: "gpt-4.1",
244 apiType: "azure-openai",
245 apiVersion: "2023-05-15",
246 },
247 });
248
249 // The Azure client modifies the baseURL to include the deployment
250 expect((azure as OpenAIApi).openai.baseURL).toBe(
251 "https://test-azure-openai.azure.com/openai/deployments/gpt-4.1",
252 );
253 expect((azure as OpenAIApi).openai.apiKey).toBe("sk-xxx");
254 });
255
256 it("should configure Azure OpenAI client with path and trailing slash", () => {
257 const azure = constructLlmApi({
258 provider: "azure",
259 apiKey: "sk-xxx",
260 apiBase: "https://test-azure-openai.azure.com/v1/",
261 env: {
262 deployment: "gpt-4.1",
263 apiType: "azure-openai",
264 apiVersion: "2023-05-15",
265 },
266 });
267
268 // The Azure client modifies the baseURL to include the deployment
269 expect((azure as OpenAIApi).openai.baseURL).toBe(
270 "https://test-azure-openai.azure.com/v1/openai/deployments/gpt-4.1",
271 );
272 expect((azure as OpenAIApi).openai.apiKey).toBe("sk-xxx");
273 });
274
275 it("should configure Azure OpenAI client with root URL and no trailing slash", () => {
276 const azure = constructLlmApi({
277 provider: "azure",
278 apiKey: "sk-xxx",
279 apiBase: "https://test-azure-openai.azure.com",
280 env: {
281 deployment: "gpt-4.1",
282 apiType: "azure-openai",
283 apiVersion: "2023-05-15",
284 },
285 });
286
287 // The Azure client modifies the baseURL to include the deployment
288 expect((azure as OpenAIApi).openai.baseURL).toBe(
289 "https://test-azure-openai.azure.com/openai/deployments/gpt-4.1",
290 );
291 expect((azure as OpenAIApi).openai.apiKey).toBe("sk-xxx");
292 });
293
294 it("should configure Azure OpenAI client with path and no trailing slash", () => {
295 const azure = constructLlmApi({
296 provider: "azure",
297 apiKey: "sk-xxx",
298 apiBase: "https://test-azure-openai.azure.com/v1",
299 env: {
300 deployment: "gpt-4.1",
301 apiType: "azure-openai",
302 apiVersion: "2023-05-15",
303 },
304 });
305
306 // The Azure client modifies the baseURL to include the deployment
307 expect((azure as OpenAIApi).openai.baseURL).toBe(
308 "https://test-azure-openai.azure.com/v1/openai/deployments/gpt-4.1",
309 );
310 expect((azure as OpenAIApi).openai.apiKey).toBe("sk-xxx");
311 });
312});