Elffuss BraidHub

kikocis/continue public

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