Elffuss BraidHub

kikocis/continue public

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