Elffuss BraidHub

kikocis/continue public

9875eaa07e45 · 7.2 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 },
55 {
56 provider: "anthropic",
57 model: "claude-3-5-haiku-latest",
58 apiKey: process.env.ANTHROPIC_API_KEY!,
59 roles: ["chat"],
60 options: {
61 skipTools: false,
62 expectUsage: true,
63 },
64 },
65 {
66 provider: "gemini",
67 model: "gemini-1.5-flash-latest",
68 apiKey: process.env.GEMINI_API_KEY!,
69 roles: ["chat"],
70 },
71 // {
72 // provider: "mistral",
73 // model: "codestral-latest",
74 // apiKey: process.env.MISTRAL_API_KEY!,
75 // apiBase: "https://api.mistral.ai/v1",
76 // roles: ["autocomplete"],
77 // },
78 // {
79 // provider: "deepseek",
80 // model: "deepseek-coder",
81 // apiKey: process.env.DEEPSEEK_API_KEY!,
82 // roles: ["autocomplete"],
83 // },
84 {
85 provider: "openai",
86 model: "text-embedding-3-small",
87 apiKey: process.env.OPENAI_API_KEY!,
88 roles: ["embed"],
89 },
90 {
91 provider: "voyage",
92 model: "voyage-code-3",
93 apiKey: process.env.VOYAGE_API_KEY!,
94 roles: ["embed"],
95 },
96 // {
97 // provider: "cohere",
98 // model: "embed-v4.0",
99 // apiKey: process.env.COHERE_API_KEY!,
100 // roles: ["embed"],
101 // },
102 // {
103 // provider: "gemini",
104 // model: "models/text-embedding-004",
105 // apiKey: process.env.GEMINI_API_KEY!,
106 // roles: ["embed"],
107 // },
108 {
109 provider: "voyage",
110 model: "rerank-lite-1",
111 apiKey: process.env.VOYAGE_API_KEY!,
112 roles: ["rerank"],
113 },
114 // {
115 // provider: "cohere",
116 // model: "rerank-v3.5",
117 // apiKey: process.env.COHERE_API_KEY!,
118 // roles: ["rerank"],
119 // },
120 {
121 provider: "azure",
122 model: "gpt-4.1",
123 apiBase: "https://continue-openai.openai.azure.com",
124 apiKey: process.env.AZURE_OPENAI_GPT41_API_KEY,
125 roles: ["chat"],
126 env: {
127 deployment: "gpt-4.1",
128 apiVersion: "2024-02-15-preview",
129 apiType: "azure-openai",
130 },
131 },
132];
133
134if (process.env.IGNORE_API_KEY_TESTS === "true") {
135 test("Skipping API key tests", () => {
136 console.log("Skipping API key tests due to IGNORE_API_KEY_TESTS being set");
137 });
138} else {
139 TESTS.forEach((config) => {
140 describe(`${config.provider}/${config.model}`, () => {
141 vi.setConfig({ testTimeout: 30000 });
142 testConfig({ name: config.model, ...config });
143 });
144 });
145}
146
147describe("Configuration", () => {
148 it("should configure DeepSeek OpenAI client with correct apiBase and apiKey", () => {
149 const deepseek = constructLlmApi({
150 provider: "deepseek",
151 apiKey: "sk-xxx",
152 });
153
154 expect((deepseek as OpenAIApi).openai.baseURL).toBe(DEEPSEEK_API_BASE);
155 expect((deepseek as OpenAIApi).openai.apiKey).toBe("sk-xxx");
156
157 const deepseek2 = constructLlmApi({
158 provider: "deepseek",
159 apiKey: "sk-xxx",
160 apiBase: "https://api.example.com",
161 });
162 expect((deepseek2 as OpenAIApi).openai.baseURL).toBe(
163 "https://api.example.com",
164 );
165 });
166
167 it("should configure Inception OpenAI client with correct apiBase and apiKey", () => {
168 const inception = constructLlmApi({
169 provider: "inception",
170 apiKey: "sk-xxx",
171 });
172
173 expect((inception as OpenAIApi).openai.baseURL).toBe(INCEPTION_API_BASE);
174 expect((inception as OpenAIApi).openai.apiKey).toBe("sk-xxx");
175
176 const inception2 = constructLlmApi({
177 provider: "inception",
178 apiKey: "sk-xxx",
179 apiBase: "https://api.example.com",
180 });
181 expect((inception2 as OpenAIApi).openai.baseURL).toBe(
182 "https://api.example.com",
183 );
184 });
185
186 it("should configure Azure OpenAI client with root URL and trailing slash", () => {
187 const azure = constructLlmApi({
188 provider: "azure",
189 apiKey: "sk-xxx",
190 apiBase: "https://test-azure-openai.azure.com/",
191 env: {
192 deployment: "gpt-4.1",
193 apiType: "azure-openai",
194 apiVersion: "2023-05-15",
195 },
196 });
197
198 // The Azure client modifies the baseURL to include the deployment
199 expect((azure as OpenAIApi).openai.baseURL).toBe(
200 "https://test-azure-openai.azure.com/openai/deployments/gpt-4.1",
201 );
202 expect((azure as OpenAIApi).openai.apiKey).toBe("sk-xxx");
203 });
204
205 it("should configure Azure OpenAI client with path and trailing slash", () => {
206 const azure = constructLlmApi({
207 provider: "azure",
208 apiKey: "sk-xxx",
209 apiBase: "https://test-azure-openai.azure.com/v1/",
210 env: {
211 deployment: "gpt-4.1",
212 apiType: "azure-openai",
213 apiVersion: "2023-05-15",
214 },
215 });
216
217 // The Azure client modifies the baseURL to include the deployment
218 expect((azure as OpenAIApi).openai.baseURL).toBe(
219 "https://test-azure-openai.azure.com/v1/openai/deployments/gpt-4.1",
220 );
221 expect((azure as OpenAIApi).openai.apiKey).toBe("sk-xxx");
222 });
223
224 it("should configure Azure OpenAI client with root URL and no trailing slash", () => {
225 const azure = constructLlmApi({
226 provider: "azure",
227 apiKey: "sk-xxx",
228 apiBase: "https://test-azure-openai.azure.com",
229 env: {
230 deployment: "gpt-4.1",
231 apiType: "azure-openai",
232 apiVersion: "2023-05-15",
233 },
234 });
235
236 // The Azure client modifies the baseURL to include the deployment
237 expect((azure as OpenAIApi).openai.baseURL).toBe(
238 "https://test-azure-openai.azure.com/openai/deployments/gpt-4.1",
239 );
240 expect((azure as OpenAIApi).openai.apiKey).toBe("sk-xxx");
241 });
242
243 it("should configure Azure OpenAI client with path and no trailing slash", () => {
244 const azure = constructLlmApi({
245 provider: "azure",
246 apiKey: "sk-xxx",
247 apiBase: "https://test-azure-openai.azure.com/v1",
248 env: {
249 deployment: "gpt-4.1",
250 apiType: "azure-openai",
251 apiVersion: "2023-05-15",
252 },
253 });
254
255 // The Azure client modifies the baseURL to include the deployment
256 expect((azure as OpenAIApi).openai.baseURL).toBe(
257 "https://test-azure-openai.azure.com/v1/openai/deployments/gpt-4.1",
258 );
259 expect((azure as OpenAIApi).openai.apiKey).toBe("sk-xxx");
260 });
261});