Elffuss BraidHub

kikocis/continue public

Merge pull request #7809 from TensorNull/feat/cometapi

✨ add CometAPI as Model Provider
Changeset5a63c83f67c345df0e6b4061a2bb666f411c6187221baf3b5956accc23cbfbe3
AuthorTing-Wai <40179554+tingwai@users.noreply.github.com> · 2025-09-24 14:11 -07:00
CommitterGitHub <noreply@github.com> · 2025-09-24 14:11 -07:00
Parentsf85d5090010d, 1171e76e7c71

Browse the files at this changeset

11 files changed

added core/llm/llms/CometAPI.ts +358 −0
@@ -0,0 +1,358 @@
1+import { LLMOptions } from "../../index.js";
2+import { allModelProviders } from "@continuedev/llm-info";
3+import OpenAI from "./OpenAI.js";
4+
5+/**
6+ * CometAPI-specific error types for better error handling
7+ */
8+export class CometAPIError extends Error {
9+ constructor(
10+ message: string,
11+ public code?: string,
12+ public statusCode?: number,
13+ ) {
14+ super(message);
15+ this.name = "CometAPIError";
16+ }
17+}
18+
19+export class CometAPIAuthenticationError extends CometAPIError {
20+ constructor(message: string = "Invalid CometAPI API key") {
21+ super(message, "AUTHENTICATION_ERROR", 401);
22+ this.name = "CometAPIAuthenticationError";
23+ }
24+}
25+
26+export class CometAPIQuotaExceededError extends CometAPIError {
27+ constructor(message: string = "CometAPI quota exceeded") {
28+ super(message, "QUOTA_EXCEEDED", 429);
29+ this.name = "CometAPIQuotaExceededError";
30+ }
31+}
32+
33+/**
34+ * CometAPI LLM provider - aggregates multiple mainstream models
35+ * from various providers (GPT, Claude, Gemini, Grok, DeepSeek, Qwen, etc.)
36+ *
37+ * Uses OpenAI-compatible API format with bearer token authentication
38+ */
39+class CometAPI extends OpenAI {
40+ static providerName = "cometapi";
41+
42+ static defaultOptions: Partial<LLMOptions> = {
43+ apiBase: "https://api.cometapi.com/v1/",
44+ model: "gpt-4o-mini", // Default to a commonly available model
45+ };
46+
47+ constructor(options: LLMOptions) {
48+ // Validate required configuration before calling super
49+ CometAPI.validateConfig(options);
50+ super(options);
51+
52+ // Align contextLength with llm-info for cometapi specifically (non-breaking for others)
53+ try {
54+ const cometProvider = allModelProviders.find((p) => p.id === "cometapi");
55+ const info = cometProvider?.models.find((m) =>
56+ m.regex ? m.regex.test(this.model) : m.model === this.model,
57+ );
58+ if (info?.contextLength) {
59+ // Always prefer cometapi-specific llm-info over generic provider matches
60+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
61+ // @ts-ignore - accessing protected for targeted fix
62+ this._contextLength = info.contextLength;
63+ }
64+ } catch {
65+ // no-op: do not fail construction on metadata issues
66+ }
67+ }
68+
69+ /**
70+ * Validate CometAPI configuration
71+ */
72+ private static validateConfig(options: LLMOptions): void {
73+ // Allow constructing without API key (tests that only instantiate should pass).
74+ // Enforce credentials at request time instead.
75+ if (!options.apiKey) {
76+ if (typeof process !== "undefined" && process.env?.NODE_ENV !== "test") {
77+ console.warn(
78+ "CometAPI: No API key provided. Requests will fail until an API key is configured. Get one at https://api.cometapi.com/console/token",
79+ );
80+ }
81+ return;
82+ }
83+
84+ if (options.apiBase && !CometAPI.isValidApiBase(options.apiBase)) {
85+ throw new CometAPIError(
86+ `Invalid CometAPI base URL: ${options.apiBase}. Expected https://api.cometapi.com/v1/ or compatible endpoint`,
87+ );
88+ }
89+
90+ if (
91+ options.model &&
92+ !CometAPI.isValidModelFormat(options.model) &&
93+ typeof process !== "undefined" &&
94+ process.env?.NODE_ENV !== "test"
95+ ) {
96+ console.warn(
97+ `CometAPI: Model "${options.model}" may not be supported. Check CometAPI documentation for available models.`,
98+ );
99+ }
100+ }
101+
102+ /**
103+ * Validate API base URL format
104+ */
105+ private static isValidApiBase(apiBase: string): boolean {
106+ try {
107+ const url = new URL(apiBase);
108+ return (
109+ url.protocol === "https:" &&
110+ (url.hostname === "api.cometapi.com" ||
111+ url.hostname.endsWith(".cometapi.com") ||
112+ apiBase.includes("v1")) // Allow custom compatible endpoints
113+ );
114+ } catch {
115+ return false;
116+ }
117+ }
118+
119+ /**
120+ * Basic model format validation
121+ */
122+ private static isValidModelFormat(model: string): boolean {
123+ // Allow common model patterns
124+ const validPatterns = [
125+ /^gpt-/i,
126+ /^claude-/i,
127+ /^gemini-/i,
128+ /^grok/i,
129+ /^deepseek/i,
130+ /^qwen/i,
131+ /^text-/i,
132+ /^chat/i,
133+ ];
134+
135+ return validPatterns.some((pattern) => pattern.test(model));
136+ }
137+
138+ /**
139+ * Patterns to filter out non-chat models from the model list
140+ * Based on CometAPI documentation requirements
141+ */
142+ private static IGNORE_PATTERNS = [
143+ // Image generation models
144+ "dall-e",
145+ "dalle",
146+ "midjourney",
147+ "mj_",
148+ "stable-diffusion",
149+ "sd-",
150+ "flux-",
151+ "playground-v",
152+ "ideogram",
153+ "recraft-",
154+ "black-forest-labs",
155+ "/recraft-v3",
156+ "recraftv3",
157+ "stability-ai/",
158+ "sdxl",
159+
160+ // Audio generation models
161+ "suno_",
162+ "tts",
163+ "whisper",
164+
165+ // Video generation models
166+ "runway",
167+ "luma_",
168+ "luma-",
169+ "veo",
170+ "kling_",
171+ "minimax_video",
172+ "hunyuan-t1",
173+
174+ // Utility models
175+ "embedding",
176+ "search-gpts",
177+ "files_retrieve",
178+ "moderation",
179+ ];
180+
181+ /**
182+ * Recommended chat models from CometAPI documentation
183+ */
184+ private static RECOMMENDED_MODELS = [
185+ // GPT series
186+ "gpt-5-chat-latest",
187+ "chatgpt-4o-latest",
188+ "gpt-5-mini",
189+ "gpt-5-nano",
190+ "gpt-5",
191+ "gpt-4.1-mini",
192+ "gpt-4.1-nano",
193+ "gpt-4.1",
194+ "gpt-4o-mini",
195+ "o4-mini-2025-04-16",
196+ "o3-pro-2025-06-10",
197+
198+ // Claude series
199+ "claude-opus-4-1-20250805",
200+ "claude-opus-4-1-20250805-thinking",
201+ "claude-sonnet-4-20250514",
202+ "claude-sonnet-4-20250514-thinking",
203+ "claude-3-7-sonnet-latest",
204+ "claude-3-5-haiku-latest",
205+
206+ // Gemini series
207+ "gemini-2.5-pro",
208+ "gemini-2.5-flash",
209+ "gemini-2.5-flash-lite",
210+ "gemini-2.0-flash",
211+
212+ // Grok series
213+ "grok-4-0709",
214+ "grok-3",
215+ "grok-3-mini",
216+ "grok-2-image-1212",
217+
218+ // DeepSeek series
219+ "deepseek-v3.1",
220+ "deepseek-v3",
221+ "deepseek-r1-0528",
222+ "deepseek-chat",
223+ "deepseek-reasoner",
224+
225+ // Qwen series
226+ "qwen3-30b-a3b",
227+ "qwen3-coder-plus-2025-07-22",
228+ ];
229+
230+ /**
231+ * Filter model list to exclude non-chat models
232+ * Uses pattern matching against model names
233+ */
234+ protected filterChatModels(models: any[]): any[] {
235+ if (!models || !Array.isArray(models)) {
236+ return [];
237+ }
238+
239+ return models.filter((model) => {
240+ const modelId = model.id || model.model || "";
241+ const modelName = modelId.toLowerCase();
242+
243+ // Check if model matches any ignore pattern
244+ const shouldIgnore = CometAPI.IGNORE_PATTERNS.some((pattern) =>
245+ modelName.includes(pattern.toLowerCase()),
246+ );
247+
248+ return !shouldIgnore;
249+ });
250+ }
251+
252+ /**
253+ * Get recommended models for CometAPI
254+ * Returns predefined list since CometAPI model info is limited
255+ */
256+ protected getRecommendedModels(): string[] {
257+ return [...CometAPI.RECOMMENDED_MODELS];
258+ }
259+
260+ /**
261+ * Override listModels method to apply model filtering with enhanced error handling
262+ */
263+ async listModels(): Promise<string[]> {
264+ try {
265+ const allModels = await super.listModels();
266+ const filteredModels = this.filterChatModels(
267+ allModels.map((id) => ({ id })),
268+ );
269+
270+ // If filtered list is empty or very limited, return recommended models
271+ if (filteredModels.length < 5) {
272+ console.info(
273+ "CometAPI: Limited models available, using recommended set",
274+ );
275+ return this.getRecommendedModels();
276+ }
277+
278+ return filteredModels.map((model) => model.id);
279+ } catch (error: any) {
280+ // Enhanced error handling with specific error types
281+ const errorMessage = error?.message || "Unknown error";
282+ const statusCode = error?.status || error?.statusCode;
283+
284+ if (statusCode === 401) {
285+ throw new CometAPIAuthenticationError(
286+ "CometAPI authentication failed. Please check your API key.",
287+ );
288+ } else if (statusCode === 429) {
289+ throw new CometAPIQuotaExceededError(
290+ "CometAPI rate limit exceeded. Please try again later.",
291+ );
292+ } else if (statusCode >= 400 && statusCode < 500) {
293+ throw new CometAPIError(
294+ `CometAPI client error: ${errorMessage}`,
295+ "CLIENT_ERROR",
296+ statusCode,
297+ );
298+ } else if (statusCode >= 500) {
299+ console.warn(
300+ "CometAPI server error, falling back to recommended models:",
301+ errorMessage,
302+ );
303+ return this.getRecommendedModels();
304+ } else {
305+ // Network or other errors - fallback gracefully
306+ console.warn(
307+ "CometAPI: Failed to fetch model list, using recommended models",
308+ errorMessage,
309+ );
310+ return this.getRecommendedModels();
311+ }
312+ }
313+ }
314+
315+ /**
316+ * Override chat completion with enhanced error handling
317+ */
318+ protected async *_streamChat(
319+ messages: any[],
320+ signal: AbortSignal,
321+ options: any = {},
322+ ): AsyncGenerator<any> {
323+ try {
324+ yield* super._streamChat(messages, signal, options);
325+ } catch (error: any) {
326+ const statusCode = error?.status || error?.statusCode;
327+ const errorMessage = error?.message || "Unknown error";
328+
329+ if (statusCode === 401) {
330+ throw new CometAPIAuthenticationError(
331+ "CometAPI authentication failed during chat completion",
332+ );
333+ } else if (statusCode === 429) {
334+ throw new CometAPIQuotaExceededError(
335+ "CometAPI rate limit exceeded during chat completion",
336+ );
337+ } else if (
338+ errorMessage.includes("model") &&
339+ errorMessage.includes("not found")
340+ ) {
341+ throw new CometAPIError(
342+ `Model "${this.model}" is not available on CometAPI. Please check available models.`,
343+ "MODEL_NOT_FOUND",
344+ 404,
345+ );
346+ } else {
347+ // Re-throw with more context
348+ throw new CometAPIError(
349+ `CometAPI chat completion failed: ${errorMessage}`,
350+ "COMPLETION_ERROR",
351+ statusCode,
352+ );
353+ }
354+ }
355+ }
356+}
357+
358+export default CometAPI;
modified core/llm/llms/OpenAI-compatible-core.vitest.ts +11 −0
@@ -13,6 +13,7 @@
1313 import Cerebras from "./Cerebras.js";
1414 import DeepInfra from "./DeepInfra.js";
1515 import Nvidia from "./Nvidia.js";
16+import CometAPI from "./CometAPI.js";
1617
1718 // Base OpenAI tests
1819 import { afterEach, describe, expect, test, vi } from "vitest";
@@ -292,3 +293,13 @@
292293 truncate: "END",
293294 },
294295 });
296+
297+createOpenAISubclassTests(CometAPI, {
298+ providerName: "cometapi",
299+ defaultApiBase: "https://api.cometapi.com/v1/",
300+ modelConversions: {
301+ "gpt-5-mini": "gpt-5-mini",
302+ "claude-4-sonnet": "claude-sonnet-4-20250514",
303+ },
304+ modelConversionContent: "hello",
305+});
modified core/llm/llms/index.ts +2 −0
@@ -17,6 +17,7 @@
1717 import Cerebras from "./Cerebras";
1818 import Cloudflare from "./Cloudflare";
1919 import Cohere from "./Cohere";
20+import CometAPI from "./CometAPI";
2021 import DeepInfra from "./DeepInfra";
2122 import Deepseek from "./Deepseek";
2223 import Docker from "./Docker";
@@ -67,6 +68,7 @@
6768 export const LLMClasses = [
6869 Anthropic,
6970 Cohere,
71+ CometAPI,
7072 FunctionNetwork,
7173 Gemini,
7274 Llamafile,
added gui/public/logos/cometapi.png +0 −0

Binary content is not shown. View the file.

modified gui/src/pages/AddNewModel/configs/models.ts +376 −0
@@ -1836,4 +1836,380 @@
18361836 providerOptions: [],
18371837 isOpenSource: false,
18381838 },
1839+
1840+ // CometAPI Models
1841+
1842+ // GPT series models via CometAPI
1843+ cometapiGpt5ChatLatest: {
1844+ title: "GPT-5 Chat Latest",
1845+ description:
1846+ "GPT-5 Chat Latest via CometAPI - OpenAI's most advanced conversational model.",
1847+ params: {
1848+ model: "gpt-5-chat-latest",
1849+ contextLength: 400_000,
1850+ title: "GPT-5 Chat Latest",
1851+ apiKey: "",
1852+ },
1853+ providerOptions: ["cometapi"],
1854+ icon: "cometapi.png",
1855+ isOpenSource: false,
1856+ },
1857+ cometapiGpt5Mini: {
1858+ title: "GPT-5 Mini",
1859+ description:
1860+ "GPT-5 Mini via CometAPI - compact version of GPT-5 optimized for efficiency.",
1861+ params: {
1862+ model: "gpt-5-mini",
1863+ contextLength: 400_000,
1864+ title: "GPT-5 Mini",
1865+ apiKey: "",
1866+ },
1867+ providerOptions: ["cometapi"],
1868+ icon: "cometapi.png",
1869+ isOpenSource: false,
1870+ },
1871+ cometapiGpt5: {
1872+ title: "GPT-5",
1873+ description:
1874+ "GPT-5 via CometAPI - OpenAI's flagship model with advanced reasoning capabilities.",
1875+ params: {
1876+ model: "gpt-5",
1877+ contextLength: 200_000,
1878+ title: "GPT-5",
1879+ apiKey: "",
1880+ },
1881+ providerOptions: ["cometapi"],
1882+ icon: "cometapi.png",
1883+ isOpenSource: false,
1884+ },
1885+ cometapiChatgpt4oLatest: {
1886+ title: "ChatGPT-4o Latest",
1887+ description:
1888+ "ChatGPT-4o Latest via CometAPI - latest version of GPT-4o with enhanced capabilities.",
1889+ params: {
1890+ model: "chatgpt-4o-latest",
1891+ contextLength: 128_000,
1892+ title: "ChatGPT-4o Latest",
1893+ apiKey: "",
1894+ },
1895+ providerOptions: ["cometapi"],
1896+ icon: "cometapi.png",
1897+ isOpenSource: false,
1898+ },
1899+ cometapiGpt41: {
1900+ title: "GPT-4.1",
1901+ description:
1902+ "GPT-4.1 via CometAPI - enhanced version of GPT-4.1 with improved reasoning.",
1903+ params: {
1904+ model: "gpt-4.1",
1905+ contextLength: 100_000,
1906+ title: "GPT-4.1",
1907+ apiKey: "",
1908+ },
1909+ providerOptions: ["cometapi"],
1910+ icon: "cometapi.png",
1911+ isOpenSource: false,
1912+ },
1913+ cometapiO4Mini: {
1914+ title: "O4 Mini",
1915+ description:
1916+ "O4 Mini via CometAPI - OpenAI's reasoning model optimized for efficiency.",
1917+ params: {
1918+ model: "o4-mini-2025-04-16",
1919+ contextLength: 200_000,
1920+ title: "O4 Mini",
1921+ apiKey: "",
1922+ },
1923+ providerOptions: ["cometapi"],
1924+ icon: "cometapi.png",
1925+ isOpenSource: false,
1926+ },
1927+ cometapiO3Pro: {
1928+ title: "O3 Pro",
1929+ description:
1930+ "O3 Pro via CometAPI - advanced reasoning model with enhanced problem-solving capabilities.",
1931+ params: {
1932+ model: "o3-pro-2025-06-10",
1933+ contextLength: 200_000,
1934+ title: "O3 Pro",
1935+ apiKey: "",
1936+ },
1937+ providerOptions: ["cometapi"],
1938+ icon: "cometapi.png",
1939+ isOpenSource: false,
1940+ },
1941+
1942+ // Claude series models via CometAPI
1943+ cometapiClaudeOpus41: {
1944+ title: "Claude Opus 4.1",
1945+ description:
1946+ "Claude Opus 4.1 via CometAPI - Anthropic's most capable model with advanced reasoning.",
1947+ params: {
1948+ model: "claude-opus-4-1-20250805",
1949+ contextLength: 200_000,
1950+ title: "Claude Opus 4.1",
1951+ apiKey: "",
1952+ },
1953+ providerOptions: ["cometapi"],
1954+ icon: "cometapi.png",
1955+ isOpenSource: false,
1956+ },
1957+ cometapiClaudeOpus41Thinking: {
1958+ title: "Claude Opus 4.1 Thinking",
1959+ description:
1960+ "Claude Opus 4.1 Thinking via CometAPI - version with enhanced thinking capabilities.",
1961+ params: {
1962+ model: "claude-opus-4-1-20250805-thinking",
1963+ contextLength: 200_000,
1964+ title: "Claude Opus 4.1 Thinking",
1965+ apiKey: "",
1966+ },
1967+ providerOptions: ["cometapi"],
1968+ icon: "cometapi.png",
1969+ isOpenSource: false,
1970+ },
1971+ cometapiClaudeSonnet4: {
1972+ title: "Claude Sonnet 4",
1973+ description:
1974+ "Claude Sonnet 4 via CometAPI - balanced performance and efficiency from Anthropic.",
1975+ params: {
1976+ model: "claude-sonnet-4-20250514",
1977+ contextLength: 200_000,
1978+ title: "Claude Sonnet 4",
1979+ apiKey: "",
1980+ },
1981+ providerOptions: ["cometapi"],
1982+ icon: "cometapi.png",
1983+ isOpenSource: false,
1984+ },
1985+ cometapiClaudeSonnet4Thinking: {
1986+ title: "Claude Sonnet 4 Thinking",
1987+ description:
1988+ "Claude Sonnet 4 Thinking via CometAPI - version with enhanced reasoning capabilities.",
1989+ params: {
1990+ model: "claude-sonnet-4-20250514-thinking",
1991+ contextLength: 200_000,
1992+ title: "Claude Sonnet 4 Thinking",
1993+ apiKey: "",
1994+ },
1995+ providerOptions: ["cometapi"],
1996+ icon: "cometapi.png",
1997+ isOpenSource: false,
1998+ },
1999+ cometapiClaude37SonnetLatest: {
2000+ title: "Claude 3.7 Sonnet Latest",
2001+ description:
2002+ "Claude 3.7 Sonnet Latest via CometAPI - latest version of Claude 3.7 Sonnet.",
2003+ params: {
2004+ model: "claude-3-7-sonnet-latest",
2005+ contextLength: 200_000,
2006+ title: "Claude 3.7 Sonnet Latest",
2007+ apiKey: "",
2008+ },
2009+ providerOptions: ["cometapi"],
2010+ icon: "cometapi.png",
2011+ isOpenSource: false,
2012+ },
2013+ cometapiClaude35HaikuLatest: {
2014+ title: "Claude 3.5 Haiku Latest",
2015+ description:
2016+ "Claude 3.5 Haiku Latest via CometAPI - fast and efficient model from Anthropic.",
2017+ params: {
2018+ model: "claude-3-5-haiku-latest",
2019+ contextLength: 200_000,
2020+ title: "Claude 3.5 Haiku Latest",
2021+ apiKey: "",
2022+ },
2023+ providerOptions: ["cometapi"],
2024+ icon: "cometapi.png",
2025+ isOpenSource: false,
2026+ },
2027+
2028+ // Gemini series models via CometAPI
2029+ cometapiGemini25Pro: {
2030+ title: "Gemini 2.5 Pro",
2031+ description:
2032+ "Gemini 2.5 Pro via CometAPI - Google's advanced multimodal model with enhanced capabilities.",
2033+ params: {
2034+ model: "gemini-2.5-pro",
2035+ contextLength: 1_000_000,
2036+ title: "Gemini 2.5 Pro",
2037+ apiKey: "",
2038+ },
2039+ providerOptions: ["cometapi"],
2040+ icon: "cometapi.png",
2041+ isOpenSource: false,
2042+ },
2043+ cometapiGemini25Flash: {
2044+ title: "Gemini 2.5 Flash",
2045+ description:
2046+ "Gemini 2.5 Flash via CometAPI - optimized for speed and efficiency.",
2047+ params: {
2048+ model: "gemini-2.5-flash",
2049+ contextLength: 1_000_000,
2050+ title: "Gemini 2.5 Flash",
2051+ apiKey: "",
2052+ },
2053+ providerOptions: ["cometapi"],
2054+ icon: "cometapi.png",
2055+ isOpenSource: false,
2056+ },
2057+ cometapiGemini25FlashLite: {
2058+ title: "Gemini 2.5 Flash Lite",
2059+ description:
2060+ "Gemini 2.5 Flash Lite via CometAPI - lightweight version for faster responses.",
2061+ params: {
2062+ model: "gemini-2.5-flash-lite",
2063+ contextLength: 8_000,
2064+ title: "Gemini 2.5 Flash Lite",
2065+ apiKey: "",
2066+ },
2067+ providerOptions: ["cometapi"],
2068+ icon: "cometapi.png",
2069+ isOpenSource: false,
2070+ },
2071+ cometapiGemini20Flash: {
2072+ title: "Gemini 2.0 Flash",
2073+ description:
2074+ "Gemini 2.0 Flash via CometAPI - Google's powerful workhorse model with low latency.",
2075+ params: {
2076+ model: "gemini-2.0-flash",
2077+ contextLength: 32_000,
2078+ title: "Gemini 2.0 Flash",
2079+ apiKey: "",
2080+ },
2081+ providerOptions: ["cometapi"],
2082+ icon: "cometapi.png",
2083+ isOpenSource: false,
2084+ },
2085+
2086+ // Grok series models via CometAPI
2087+ cometapiGrok40709: {
2088+ title: "Grok 4",
2089+ description:
2090+ "Grok 4 via CometAPI - xAI's advanced model with real-time information access.",
2091+ params: {
2092+ model: "grok-4-0709",
2093+ contextLength: 256_000,
2094+ title: "Grok 4",
2095+ apiKey: "",
2096+ },
2097+ providerOptions: ["cometapi"],
2098+ icon: "cometapi.png",
2099+ isOpenSource: false,
2100+ },
2101+ cometapiGrok3: {
2102+ title: "Grok 3",
2103+ description: "Grok 3 via CometAPI - powerful reasoning model from xAI.",
2104+ params: {
2105+ model: "grok-3",
2106+ contextLength: 128_000,
2107+ title: "Grok 3",
2108+ apiKey: "",
2109+ },
2110+ providerOptions: ["cometapi"],
2111+ icon: "cometapi.png",
2112+ isOpenSource: false,
2113+ },
2114+ cometapiGrok3Mini: {
2115+ title: "Grok 3 Mini",
2116+ description: "Grok 3 Mini via CometAPI - efficient version of Grok 3.",
2117+ params: {
2118+ model: "grok-3-mini",
2119+ contextLength: 128_000,
2120+ title: "Grok 3 Mini",
2121+ apiKey: "",
2122+ },
2123+ providerOptions: ["cometapi"],
2124+ icon: "cometapi.png",
2125+ isOpenSource: false,
2126+ },
2127+
2128+ // DeepSeek series models via CometAPI (additional)
2129+ cometapiDeepseekV31: {
2130+ title: "DeepSeek V3.1",
2131+ description:
2132+ "DeepSeek V3.1 via CometAPI - enhanced version with improved performance.",
2133+ params: {
2134+ model: "deepseek-v3.1",
2135+ contextLength: 128_000,
2136+ title: "DeepSeek V3.1",
2137+ apiKey: "",
2138+ },
2139+ providerOptions: ["cometapi"],
2140+ icon: "cometapi.png",
2141+ isOpenSource: false,
2142+ },
2143+ cometapiDeepseekR10528: {
2144+ title: "DeepSeek R1",
2145+ description:
2146+ "DeepSeek R1 via CometAPI - reasoning model with enhanced problem-solving capabilities.",
2147+ params: {
2148+ model: "deepseek-r1-0528",
2149+ contextLength: 64_000,
2150+ title: "DeepSeek R1",
2151+ apiKey: "",
2152+ },
2153+ providerOptions: ["cometapi"],
2154+ icon: "cometapi.png",
2155+ isOpenSource: false,
2156+ },
2157+ cometapiDeepseekChat: {
2158+ title: "DeepSeek Chat",
2159+ description:
2160+ "DeepSeek Chat via CometAPI - optimized for conversational AI tasks.",
2161+ params: {
2162+ model: "deepseek-chat",
2163+ contextLength: 64_000,
2164+ title: "DeepSeek Chat",
2165+ apiKey: "",
2166+ },
2167+ providerOptions: ["cometapi"],
2168+ icon: "cometapi.png",
2169+ isOpenSource: false,
2170+ },
2171+ cometapiDeepseekReasoner: {
2172+ title: "DeepSeek Reasoner",
2173+ description:
2174+ "DeepSeek Reasoner via CometAPI - specialized model for complex reasoning tasks.",
2175+ params: {
2176+ model: "deepseek-reasoner",
2177+ contextLength: 64_000,
2178+ title: "DeepSeek Reasoner",
2179+ apiKey: "",
2180+ },
2181+ providerOptions: ["cometapi"],
2182+ icon: "cometapi.png",
2183+ isOpenSource: false,
2184+ },
2185+
2186+ // Qwen series models via CometAPI
2187+ cometapiQwen330BA3B: {
2188+ title: "Qwen 3 30B A3B",
2189+ description:
2190+ "Qwen 3 30B A3B via CometAPI - Alibaba's advanced language model with 30B parameters.",
2191+ params: {
2192+ model: "qwen3-30b-a3b",
2193+ contextLength: 128_000,
2194+ title: "Qwen 3 30B A3B",
2195+ apiKey: "",
2196+ },
2197+ providerOptions: ["cometapi"],
2198+ icon: "cometapi.png",
2199+ isOpenSource: false,
2200+ },
2201+ cometapiQwen3CoderPlus: {
2202+ title: "Qwen 3 Coder Plus",
2203+ description:
2204+ "Qwen 3 Coder Plus via CometAPI - specialized coding model from Alibaba.",
2205+ params: {
2206+ model: "qwen3-coder-plus-2025-07-22",
2207+ contextLength: 262_000,
2208+ title: "Qwen 3 Coder Plus",
2209+ apiKey: "",
2210+ },
2211+ providerOptions: ["cometapi"],
2212+ icon: "cometapi.png",
2213+ isOpenSource: false,
2214+ },
18392215 };
modified gui/src/pages/AddNewModel/configs/providers.ts +59 −0
@@ -49,6 +49,65 @@
4949 };
5050
5151 export const providers: Partial<Record<string, ProviderInfo>> = {
52+ cometapi: {
53+ title: "CometAPI",
54+ provider: "cometapi",
55+ description: "500+ AI Model API,All In One API. Just In CometAPI",
56+ longDescription:
57+ "Unified Access to Leading AI Models, see [here](https://www.cometapi.com/?utm_source=continue&utm_medium=integration&utm_campaign=cometapi_integration&utm_content=continue_plugin) for more details.",
58+ icon: "cometapi.png",
59+ tags: [ModelProviderTags.RequiresApiKey],
60+ collectInputFor: [
61+ {
62+ inputType: "text",
63+ key: "apiKey",
64+ label: "API Key",
65+ placeholder: "Enter your CometAPI key",
66+ required: true,
67+ },
68+ ...completionParamsInputsConfigs,
69+ ],
70+ packages: [
71+ // GPT, OpenAI family
72+ models.cometapiGpt5ChatLatest,
73+ models.cometapiGpt5Mini,
74+ models.cometapiGpt5,
75+ models.cometapiChatgpt4oLatest,
76+ models.cometapiGpt41,
77+ models.cometapiO4Mini,
78+ models.cometapiO3Pro,
79+ // Anthropic Claude family
80+ models.cometapiClaudeOpus41,
81+ models.cometapiClaudeOpus41Thinking,
82+ models.cometapiClaudeSonnet4,
83+ models.cometapiClaudeSonnet4Thinking,
84+ models.cometapiClaude37SonnetLatest,
85+ models.cometapiClaude35HaikuLatest,
86+ // Google Gemini family
87+ models.cometapiGemini25Pro,
88+ models.cometapiGemini25Flash,
89+ models.cometapiGemini25FlashLite,
90+ models.cometapiGemini20Flash,
91+ // xAI Grok family
92+ models.cometapiGrok40709,
93+ models.cometapiGrok3,
94+ models.cometapiGrok3Mini,
95+ // Deepseek family
96+ models.cometapiDeepseekV31,
97+ models.cometapiDeepseekR10528,
98+ models.cometapiDeepseekChat,
99+ models.cometapiDeepseekReasoner,
100+ // Qwen family
101+ models.cometapiQwen330BA3B,
102+ models.cometapiQwen3CoderPlus,
103+ //TODO: Need to wait for the improvement after the upgrade of the cometapi model list interface
104+ // {
105+ // ...models.AUTODETECT,
106+ // params: { ...models.AUTODETECT.params, title: "CometAPI" },
107+ // },
108+ ],
109+ apiKeyUrl: "https://api.cometapi.com/console/token",
110+ },
52111 openai: {
53112 title: "OpenAI",
54113 provider: "openai",
modified packages/llm-info/src/index.ts +2 −0
@@ -2,6 +2,7 @@
22 import { Azure } from "./providers/azure.js";
33 import { Bedrock } from "./providers/bedrock.js";
44 import { Cohere } from "./providers/cohere.js";
5+import { CometAPI } from "./providers/cometapi.js";
56 import { Gemini } from "./providers/gemini.js";
67 import { Mistral } from "./providers/mistral.js";
78 import { Ollama } from "./providers/ollama.js";
@@ -22,6 +23,7 @@
2223 Vllm,
2324 Bedrock,
2425 Cohere,
26+ CometAPI,
2527 xAI,
2628 ];
2729
added packages/llm-info/src/providers/cometapi.ts +280 −0
@@ -0,0 +1,280 @@
1+import { ModelProvider } from "../types.js";
2+
3+export const CometAPI: ModelProvider = {
4+ id: "cometapi",
5+ displayName: "CometAPI",
6+ models: [
7+ // GPT Series
8+ {
9+ model: "gpt-5-chat-latest",
10+ displayName: "GPT-5 Chat Latest",
11+ contextLength: 200000,
12+ maxCompletionTokens: 8192,
13+ description:
14+ "Latest GPT-5 model optimized for chat conversations with enhanced reasoning capabilities.",
15+ recommendedFor: ["chat"],
16+ },
17+ {
18+ model: "chatgpt-4o-latest",
19+ displayName: "ChatGPT-4o Latest",
20+ contextLength: 128000,
21+ maxCompletionTokens: 4096,
22+ description:
23+ "Latest ChatGPT-4o model with improved performance and updated training data.",
24+ recommendedFor: ["chat"],
25+ },
26+ {
27+ model: "gpt-5-mini",
28+ displayName: "GPT-5 Mini",
29+ contextLength: 128000,
30+ maxCompletionTokens: 4096,
31+ description:
32+ "Efficient version of GPT-5 with faster response times while maintaining high quality.",
33+ recommendedFor: ["chat"],
34+ },
35+ {
36+ model: "gpt-5-nano",
37+ displayName: "GPT-5 Nano",
38+ contextLength: 64000,
39+ maxCompletionTokens: 2048,
40+ description:
41+ "Ultra-fast GPT-5 variant optimized for quick responses and simple tasks.",
42+ recommendedFor: ["chat"],
43+ },
44+ {
45+ model: "gpt-5",
46+ displayName: "GPT-5",
47+ contextLength: 200000,
48+ maxCompletionTokens: 8192,
49+ description:
50+ "Advanced GPT-5 model with state-of-the-art language understanding and generation.",
51+ recommendedFor: ["chat"],
52+ },
53+ {
54+ model: "gpt-4o-mini",
55+ displayName: "GPT-4o Mini",
56+ contextLength: 128000,
57+ maxCompletionTokens: 4096,
58+ description:
59+ "Compact version of GPT-4o with excellent performance for most use cases.",
60+ recommendedFor: ["chat"],
61+ },
62+ {
63+ model: "o4-mini-2025-04-16",
64+ displayName: "o4 Mini (2025-04-16)",
65+ contextLength: 128000,
66+ maxCompletionTokens: 4096,
67+ description:
68+ "Optimized o4 mini model with April 2025 training improvements.",
69+ recommendedFor: ["chat"],
70+ },
71+ {
72+ model: "o3-pro-2025-06-10",
73+ displayName: "o3 Pro (2025-06-10)",
74+ contextLength: 200000,
75+ maxCompletionTokens: 8192,
76+ description:
77+ "Professional-grade o3 model with enhanced reasoning and problem-solving capabilities.",
78+ recommendedFor: ["chat"],
79+ },
80+
81+ // Claude Series
82+ {
83+ model: "claude-opus-4-1-20250805",
84+ displayName: "Claude Opus 4.1 (2025-08-05)",
85+ contextLength: 200000,
86+ maxCompletionTokens: 8192,
87+ description:
88+ "Most capable Claude model with exceptional reasoning, analysis, and creative capabilities.",
89+ recommendedFor: ["chat"],
90+ },
91+ {
92+ model: "claude-opus-4-1-20250805-thinking",
93+ displayName: "Claude Opus 4.1 Thinking (2025-08-05)",
94+ contextLength: 200000,
95+ maxCompletionTokens: 8192,
96+ description:
97+ "Claude Opus with enhanced thinking process for complex problem-solving tasks.",
98+ recommendedFor: ["chat"],
99+ },
100+ {
101+ model: "claude-sonnet-4-20250514",
102+ displayName: "Claude Sonnet 4 (2025-05-14)",
103+ contextLength: 200000,
104+ maxCompletionTokens: 8192,
105+ description:
106+ "Balanced Claude model offering excellent performance across various tasks.",
107+ recommendedFor: ["chat"],
108+ },
109+ {
110+ model: "claude-sonnet-4-20250514-thinking",
111+ displayName: "Claude Sonnet 4 Thinking (2025-05-14)",
112+ contextLength: 200000,
113+ maxCompletionTokens: 8192,
114+ description:
115+ "Claude Sonnet with enhanced reasoning capabilities for analytical tasks.",
116+ recommendedFor: ["chat"],
117+ },
118+ {
119+ model: "claude-3-7-sonnet-latest",
120+ displayName: "Claude 3.7 Sonnet Latest",
121+ contextLength: 200000,
122+ maxCompletionTokens: 4096,
123+ description:
124+ "Latest Claude 3.7 Sonnet with improved instruction following and safety.",
125+ recommendedFor: ["chat"],
126+ },
127+ {
128+ model: "claude-3-5-haiku-latest",
129+ displayName: "Claude 3.5 Haiku Latest",
130+ contextLength: 200000,
131+ maxCompletionTokens: 4096,
132+ description:
133+ "Fast and efficient Claude model optimized for quick responses.",
134+ recommendedFor: ["chat"],
135+ },
136+
137+ // Gemini Series
138+ {
139+ model: "gemini-2.5-pro",
140+ displayName: "Gemini 2.5 Pro",
141+ contextLength: 2000000,
142+ maxCompletionTokens: 8192,
143+ description:
144+ "Advanced Gemini model with extensive context window and multimodal capabilities.",
145+ recommendedFor: ["chat"],
146+ },
147+ {
148+ model: "gemini-2.5-flash",
149+ displayName: "Gemini 2.5 Flash",
150+ contextLength: 1000000,
151+ maxCompletionTokens: 8192,
152+ description:
153+ "Fast Gemini model with large context window optimized for speed.",
154+ recommendedFor: ["chat"],
155+ },
156+ {
157+ model: "gemini-2.5-flash-lite",
158+ displayName: "Gemini 2.5 Flash Lite",
159+ contextLength: 1000000,
160+ maxCompletionTokens: 4096,
161+ description:
162+ "Lightweight version of Gemini Flash for efficient processing.",
163+ recommendedFor: ["chat"],
164+ },
165+ {
166+ model: "gemini-2.0-flash",
167+ displayName: "Gemini 2.0 Flash",
168+ contextLength: 1000000,
169+ maxCompletionTokens: 8192,
170+ description:
171+ "High-performance Gemini model with excellent speed-quality balance.",
172+ recommendedFor: ["chat"],
173+ },
174+
175+ // Grok Series
176+ {
177+ model: "grok-4-0709",
178+ displayName: "Grok 4 (07-09)",
179+ contextLength: 128000,
180+ maxCompletionTokens: 4096,
181+ description:
182+ "Latest Grok model with improved reasoning and conversational abilities.",
183+ recommendedFor: ["chat"],
184+ },
185+ {
186+ model: "grok-3",
187+ displayName: "Grok 3",
188+ contextLength: 128000,
189+ maxCompletionTokens: 4096,
190+ description:
191+ "Advanced Grok model with enhanced understanding and generation capabilities.",
192+ recommendedFor: ["chat"],
193+ },
194+ {
195+ model: "grok-3-mini",
196+ displayName: "Grok 3 Mini",
197+ contextLength: 64000,
198+ maxCompletionTokens: 2048,
199+ description:
200+ "Compact Grok model optimized for efficiency and quick responses.",
201+ recommendedFor: ["chat"],
202+ },
203+ {
204+ model: "grok-2-image-1212",
205+ displayName: "Grok 2 Image (12-12)",
206+ contextLength: 128000,
207+ maxCompletionTokens: 4096,
208+ description:
209+ "Grok model with enhanced image understanding and multimodal capabilities.",
210+ recommendedFor: ["chat"],
211+ },
212+
213+ // DeepSeek Series
214+ {
215+ model: "deepseek-v3.1",
216+ displayName: "DeepSeek V3.1",
217+ contextLength: 128000,
218+ maxCompletionTokens: 4096,
219+ description:
220+ "Latest DeepSeek model with improved reasoning and coding capabilities.",
221+ recommendedFor: ["chat"],
222+ },
223+ {
224+ model: "deepseek-v3",
225+ displayName: "DeepSeek V3",
226+ contextLength: 128000,
227+ maxCompletionTokens: 4096,
228+ description:
229+ "Advanced DeepSeek model with strong performance in technical domains.",
230+ recommendedFor: ["chat"],
231+ },
232+ {
233+ model: "deepseek-r1-0528",
234+ displayName: "DeepSeek R1 (05-28)",
235+ contextLength: 128000,
236+ maxCompletionTokens: 4096,
237+ description:
238+ "DeepSeek reasoning model optimized for complex problem-solving tasks.",
239+ recommendedFor: ["chat"],
240+ },
241+ {
242+ model: "deepseek-chat",
243+ displayName: "DeepSeek Chat",
244+ contextLength: 128000,
245+ maxCompletionTokens: 4096,
246+ description:
247+ "DeepSeek model specifically optimized for conversational interactions.",
248+ recommendedFor: ["chat"],
249+ },
250+ {
251+ model: "deepseek-reasoner",
252+ displayName: "DeepSeek Reasoner",
253+ contextLength: 128000,
254+ maxCompletionTokens: 4096,
255+ description:
256+ "DeepSeek model with enhanced reasoning capabilities for analytical tasks.",
257+ recommendedFor: ["chat"],
258+ },
259+
260+ // Qwen Series
261+ {
262+ model: "qwen3-30b-a3b",
263+ displayName: "Qwen3 30B A3B",
264+ contextLength: 128000,
265+ maxCompletionTokens: 4096,
266+ description:
267+ "Large Qwen model with 30B parameters for high-quality text generation.",
268+ recommendedFor: ["chat"],
269+ },
270+ {
271+ model: "qwen3-coder-plus-2025-07-22",
272+ displayName: "Qwen3 Coder Plus (2025-07-22)",
273+ contextLength: 128000,
274+ maxCompletionTokens: 4096,
275+ description:
276+ "Qwen model specialized for coding tasks with enhanced programming capabilities.",
277+ recommendedFor: ["chat"],
278+ },
279+ ],
280+};
added packages/openai-adapters/src/apis/CometAPI.ts +132 −0
@@ -0,0 +1,132 @@
1+import {
2+ ChatCompletion,
3+ ChatCompletionChunk,
4+ ChatCompletionCreateParams,
5+ ChatCompletionCreateParamsNonStreaming,
6+ ChatCompletionCreateParamsStreaming,
7+ Completion,
8+ CompletionCreateParamsNonStreaming,
9+ CompletionCreateParamsStreaming,
10+ CreateEmbeddingResponse,
11+ EmbeddingCreateParams,
12+ Model,
13+} from "openai/resources/index";
14+import { CometAPIConfig } from "../types.js";
15+import {
16+ BaseLlmApi,
17+ CreateRerankResponse,
18+ FimCreateParamsStreaming,
19+ RerankCreateParams,
20+} from "./base.js";
21+import { OpenAIApi } from "./OpenAI.js";
22+
23+/**
24+ * CometAPI adapter - extends OpenAI adapter since CometAPI is OpenAI-compatible
25+ *
26+ * CometAPI provides access to multiple LLM providers (GPT, Claude, Gemini, etc.)
27+ * through a unified OpenAI-compatible API interface.
28+ */
29+export class CometAPIApi extends OpenAIApi implements BaseLlmApi {
30+ // Store the original CometAPI config separately
31+ private cometConfig: CometAPIConfig;
32+
33+ constructor(config: CometAPIConfig) {
34+ // CometAPI uses OpenAI-compatible API, so we can reuse OpenAI adapter
35+ // Convert CometAPI config to OpenAI-compatible config for the base class
36+ const openAICompatibleConfig = {
37+ ...config,
38+ provider: "openai" as const,
39+ apiBase: config.apiBase ?? "https://api.cometapi.com/v1/",
40+ };
41+ super(openAICompatibleConfig);
42+
43+ // Store original config after super() call
44+ this.cometConfig = config;
45+ }
46+
47+ /**
48+ * Override list method to handle CometAPI-specific model filtering
49+ * The core filtering logic is handled in the CometAPI provider class
50+ */
51+ async list(): Promise<Model[]> {
52+ try {
53+ return await super.list();
54+ } catch (error) {
55+ // Fallback to empty list if model listing fails
56+ console.warn("CometAPI: Failed to fetch model list", error);
57+ return [];
58+ }
59+ }
60+
61+ /**
62+ * Chat completion - uses OpenAI-compatible format
63+ */
64+ async chatCompletionNonStream(
65+ body: ChatCompletionCreateParamsNonStreaming,
66+ signal: AbortSignal,
67+ ): Promise<ChatCompletion> {
68+ return super.chatCompletionNonStream(body, signal);
69+ }
70+
71+ /**
72+ * Streaming chat completion - uses OpenAI-compatible format
73+ */
74+ async *chatCompletionStream(
75+ body: ChatCompletionCreateParamsStreaming,
76+ signal: AbortSignal,
77+ ): AsyncGenerator<ChatCompletionChunk> {
78+ yield* super.chatCompletionStream(body, signal);
79+ }
80+
81+ /**
82+ * Legacy completion endpoint support
83+ */
84+ completionNonStream(
85+ body: CompletionCreateParamsNonStreaming,
86+ signal: AbortSignal,
87+ ): Promise<Completion> {
88+ return super.completionNonStream(body, signal);
89+ }
90+
91+ /**
92+ * Legacy streaming completion endpoint support
93+ */
94+ completionStream(
95+ body: CompletionCreateParamsStreaming,
96+ signal: AbortSignal,
97+ ): AsyncGenerator<Completion> {
98+ return super.completionStream(body, signal);
99+ }
100+
101+ /**
102+ * Fill-in-the-middle completion support
103+ */
104+ fimStream(
105+ body: FimCreateParamsStreaming,
106+ signal: AbortSignal,
107+ ): AsyncGenerator<ChatCompletionChunk> {
108+ return super.fimStream(body, signal);
109+ }
110+
111+ /**
112+ * Embeddings support (if available through CometAPI)
113+ */
114+ async embed(body: EmbeddingCreateParams): Promise<CreateEmbeddingResponse> {
115+ try {
116+ return await super.embed(body);
117+ } catch (error) {
118+ throw new Error(`CometAPI embeddings not supported: ${error}`);
119+ }
120+ }
121+
122+ /**
123+ * Reranking support (if available through CometAPI)
124+ */
125+ async rerank(body: RerankCreateParams): Promise<CreateRerankResponse> {
126+ try {
127+ return await super.rerank(body);
128+ } catch (error) {
129+ throw new Error(`CometAPI reranking not supported: ${error}`);
130+ }
131+ }
132+}
modified packages/openai-adapters/src/index.ts +3 −0
@@ -18,6 +18,7 @@
1818 import { WatsonXApi } from "./apis/WatsonX.js";
1919 import { BaseLlmApi } from "./apis/base.js";
2020 import { LLMConfig, OpenAIConfigSchema } from "./types.js";
21+import { CometAPIApi } from "./apis/CometAPI.js";
2122 import { appendPathToUrlIfNotPresent } from "./util/appendPathToUrl.js";
2223
2324 dotenv.config();
@@ -69,6 +70,8 @@
6970 return new BedrockApi(config);
7071 case "cohere":
7172 return new CohereApi(config);
73+ case "cometapi":
74+ return new CometAPIApi(config);
7275 case "anthropic":
7376 return new AnthropicApi(config);
7477 case "gemini":
modified packages/openai-adapters/src/types.ts +6 −0
@@ -116,6 +116,11 @@
116116 });
117117 export type CohereConfig = z.infer<typeof CohereConfigSchema>;
118118
119+export const CometAPIConfigSchema = OpenAIConfigSchema.extend({
120+ provider: z.literal("cometapi"),
121+});
122+export type CometAPIConfig = z.infer<typeof CometAPIConfigSchema>;
123+
119124 export const AzureConfigSchema = OpenAIConfigSchema.extend({
120125 provider: z.literal("azure"),
121126 env: z
@@ -197,5 +202,6 @@
197202 VertexAIConfigSchema,
198203 LlamastackConfigSchema,
199204 ContinueProxyConfigSchema,
205+ CometAPIConfigSchema,
200206 ]);
201207 export type LLMConfig = z.infer<typeof LLMConfigSchema>;