feat: Add CometAPI as a model provider
This commit is contained in:
parent
0910caf7ed
commit
712d1241fb
11 changed files with 1220 additions and 0 deletions
349
core/llm/llms/CometAPI.ts
Normal file
349
core/llm/llms/CometAPI.ts
Normal file
|
|
@ -0,0 +1,349 @@
|
|||
import { LLMOptions } from "../../index.js";
|
||||
import OpenAI from "./OpenAI.js";
|
||||
|
||||
/**
|
||||
* CometAPI-specific error types for better error handling
|
||||
*/
|
||||
export class CometAPIError extends Error {
|
||||
constructor(
|
||||
message: string,
|
||||
public code?: string,
|
||||
public statusCode?: number,
|
||||
) {
|
||||
super(message);
|
||||
this.name = "CometAPIError";
|
||||
}
|
||||
}
|
||||
|
||||
export class CometAPIAuthenticationError extends CometAPIError {
|
||||
constructor(message: string = "Invalid CometAPI API key") {
|
||||
super(message, "AUTHENTICATION_ERROR", 401);
|
||||
this.name = "CometAPIAuthenticationError";
|
||||
}
|
||||
}
|
||||
|
||||
export class CometAPIQuotaExceededError extends CometAPIError {
|
||||
constructor(message: string = "CometAPI quota exceeded") {
|
||||
super(message, "QUOTA_EXCEEDED", 429);
|
||||
this.name = "CometAPIQuotaExceededError";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* CometAPI LLM provider - aggregates multiple mainstream models
|
||||
* from various providers (GPT, Claude, Gemini, Grok, DeepSeek, Qwen, etc.)
|
||||
*
|
||||
* Uses OpenAI-compatible API format with bearer token authentication
|
||||
*/
|
||||
class CometAPI extends OpenAI {
|
||||
static providerName = "cometapi";
|
||||
|
||||
static defaultOptions: Partial<LLMOptions> = {
|
||||
apiBase: "https://api.cometapi.com/v1/",
|
||||
model: "gpt-4o-mini", // Default to a commonly available model
|
||||
};
|
||||
|
||||
constructor(options: LLMOptions) {
|
||||
// Validate required configuration before calling super
|
||||
CometAPI.validateConfig(options);
|
||||
super(options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate CometAPI configuration
|
||||
*/
|
||||
private static validateConfig(options: LLMOptions): void {
|
||||
if (!options.apiKey) {
|
||||
throw new CometAPIAuthenticationError(
|
||||
"CometAPI requires an API key. Please get one from https://cometapi.com/api-keys",
|
||||
);
|
||||
}
|
||||
|
||||
// Only warn in non-test environments
|
||||
if (
|
||||
!options.apiKey.startsWith("sk-comet-") &&
|
||||
!options.apiKey.startsWith("sk-") &&
|
||||
typeof process !== "undefined" &&
|
||||
process.env?.NODE_ENV !== "test" &&
|
||||
!options.apiKey.includes("test")
|
||||
) {
|
||||
console.warn(
|
||||
"CometAPI: API key format may be incorrect. Expected format: sk-comet-...",
|
||||
);
|
||||
}
|
||||
|
||||
if (options.apiBase && !CometAPI.isValidApiBase(options.apiBase)) {
|
||||
throw new CometAPIError(
|
||||
`Invalid CometAPI base URL: ${options.apiBase}. Expected https://api.cometapi.com/v1/ or compatible endpoint`,
|
||||
);
|
||||
}
|
||||
|
||||
if (
|
||||
options.model &&
|
||||
!CometAPI.isValidModelFormat(options.model) &&
|
||||
typeof process !== "undefined" &&
|
||||
process.env?.NODE_ENV !== "test"
|
||||
) {
|
||||
console.warn(
|
||||
`CometAPI: Model "${options.model}" may not be supported. Check CometAPI documentation for available models.`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate API base URL format
|
||||
*/
|
||||
private static isValidApiBase(apiBase: string): boolean {
|
||||
try {
|
||||
const url = new URL(apiBase);
|
||||
return (
|
||||
url.protocol === "https:" &&
|
||||
(url.hostname === "api.cometapi.com" ||
|
||||
url.hostname.endsWith(".cometapi.com") ||
|
||||
apiBase.includes("v1")) // Allow custom compatible endpoints
|
||||
);
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Basic model format validation
|
||||
*/
|
||||
private static isValidModelFormat(model: string): boolean {
|
||||
// Allow common model patterns
|
||||
const validPatterns = [
|
||||
/^gpt-/i,
|
||||
/^claude-/i,
|
||||
/^gemini-/i,
|
||||
/^grok/i,
|
||||
/^deepseek/i,
|
||||
/^qwen/i,
|
||||
/^text-/i,
|
||||
/^chat/i,
|
||||
];
|
||||
|
||||
return validPatterns.some((pattern) => pattern.test(model));
|
||||
}
|
||||
|
||||
/**
|
||||
* Patterns to filter out non-chat models from the model list
|
||||
* Based on CometAPI documentation requirements
|
||||
*/
|
||||
private static IGNORE_PATTERNS = [
|
||||
// Image generation models
|
||||
"dall-e",
|
||||
"dalle",
|
||||
"midjourney",
|
||||
"mj_",
|
||||
"stable-diffusion",
|
||||
"sd-",
|
||||
"flux-",
|
||||
"playground-v",
|
||||
"ideogram",
|
||||
"recraft-",
|
||||
"black-forest-labs",
|
||||
"/recraft-v3",
|
||||
"recraftv3",
|
||||
"stability-ai/",
|
||||
"sdxl",
|
||||
|
||||
// Audio generation models
|
||||
"suno_",
|
||||
"tts",
|
||||
"whisper",
|
||||
|
||||
// Video generation models
|
||||
"runway",
|
||||
"luma_",
|
||||
"luma-",
|
||||
"veo",
|
||||
"kling_",
|
||||
"minimax_video",
|
||||
"hunyuan-t1",
|
||||
|
||||
// Utility models
|
||||
"embedding",
|
||||
"search-gpts",
|
||||
"files_retrieve",
|
||||
"moderation",
|
||||
];
|
||||
|
||||
/**
|
||||
* Recommended chat models from CometAPI documentation
|
||||
*/
|
||||
private static RECOMMENDED_MODELS = [
|
||||
// GPT series
|
||||
"gpt-5-chat-latest",
|
||||
"chatgpt-4o-latest",
|
||||
"gpt-5-mini",
|
||||
"gpt-5-nano",
|
||||
"gpt-5",
|
||||
"gpt-4.1-mini",
|
||||
"gpt-4.1-nano",
|
||||
"gpt-4.1",
|
||||
"gpt-4o-mini",
|
||||
"o4-mini-2025-04-16",
|
||||
"o3-pro-2025-06-10",
|
||||
|
||||
// Claude series
|
||||
"claude-opus-4-1-20250805",
|
||||
"claude-opus-4-1-20250805-thinking",
|
||||
"claude-sonnet-4-20250514",
|
||||
"claude-sonnet-4-20250514-thinking",
|
||||
"claude-3-7-sonnet-latest",
|
||||
"claude-3-5-haiku-latest",
|
||||
|
||||
// Gemini series
|
||||
"gemini-2.5-pro",
|
||||
"gemini-2.5-flash",
|
||||
"gemini-2.5-flash-lite",
|
||||
"gemini-2.0-flash",
|
||||
|
||||
// Grok series
|
||||
"grok-4-0709",
|
||||
"grok-3",
|
||||
"grok-3-mini",
|
||||
"grok-2-image-1212",
|
||||
|
||||
// DeepSeek series
|
||||
"deepseek-v3.1",
|
||||
"deepseek-v3",
|
||||
"deepseek-r1-0528",
|
||||
"deepseek-chat",
|
||||
"deepseek-reasoner",
|
||||
|
||||
// Qwen series
|
||||
"qwen3-30b-a3b",
|
||||
"qwen3-coder-plus-2025-07-22",
|
||||
];
|
||||
|
||||
/**
|
||||
* Filter model list to exclude non-chat models
|
||||
* Uses pattern matching against model names
|
||||
*/
|
||||
protected filterChatModels(models: any[]): any[] {
|
||||
if (!models || !Array.isArray(models)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return models.filter((model) => {
|
||||
const modelId = model.id || model.model || "";
|
||||
const modelName = modelId.toLowerCase();
|
||||
|
||||
// Check if model matches any ignore pattern
|
||||
const shouldIgnore = CometAPI.IGNORE_PATTERNS.some((pattern) =>
|
||||
modelName.includes(pattern.toLowerCase()),
|
||||
);
|
||||
|
||||
return !shouldIgnore;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get recommended models for CometAPI
|
||||
* Returns predefined list since CometAPI model info is limited
|
||||
*/
|
||||
protected getRecommendedModels(): string[] {
|
||||
return [...CometAPI.RECOMMENDED_MODELS];
|
||||
}
|
||||
|
||||
/**
|
||||
* Override listModels method to apply model filtering with enhanced error handling
|
||||
*/
|
||||
async listModels(): Promise<string[]> {
|
||||
try {
|
||||
const allModels = await super.listModels();
|
||||
const filteredModels = this.filterChatModels(
|
||||
allModels.map((id) => ({ id })),
|
||||
);
|
||||
|
||||
// If filtered list is empty or very limited, return recommended models
|
||||
if (filteredModels.length < 5) {
|
||||
console.info(
|
||||
"CometAPI: Limited models available, using recommended set",
|
||||
);
|
||||
return this.getRecommendedModels();
|
||||
}
|
||||
|
||||
return filteredModels.map((model) => model.id);
|
||||
} catch (error: any) {
|
||||
// Enhanced error handling with specific error types
|
||||
const errorMessage = error?.message || "Unknown error";
|
||||
const statusCode = error?.status || error?.statusCode;
|
||||
|
||||
if (statusCode === 401) {
|
||||
throw new CometAPIAuthenticationError(
|
||||
"CometAPI authentication failed. Please check your API key.",
|
||||
);
|
||||
} else if (statusCode === 429) {
|
||||
throw new CometAPIQuotaExceededError(
|
||||
"CometAPI rate limit exceeded. Please try again later.",
|
||||
);
|
||||
} else if (statusCode >= 400 && statusCode < 500) {
|
||||
throw new CometAPIError(
|
||||
`CometAPI client error: ${errorMessage}`,
|
||||
"CLIENT_ERROR",
|
||||
statusCode,
|
||||
);
|
||||
} else if (statusCode >= 500) {
|
||||
console.warn(
|
||||
"CometAPI server error, falling back to recommended models:",
|
||||
errorMessage,
|
||||
);
|
||||
return this.getRecommendedModels();
|
||||
} else {
|
||||
// Network or other errors - fallback gracefully
|
||||
console.warn(
|
||||
"CometAPI: Failed to fetch model list, using recommended models",
|
||||
errorMessage,
|
||||
);
|
||||
return this.getRecommendedModels();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Override chat completion with enhanced error handling
|
||||
*/
|
||||
protected async *_streamChat(
|
||||
messages: any[],
|
||||
signal: AbortSignal,
|
||||
options: any = {},
|
||||
): AsyncGenerator<any> {
|
||||
try {
|
||||
yield* super._streamChat(messages, signal, options);
|
||||
} catch (error: any) {
|
||||
const statusCode = error?.status || error?.statusCode;
|
||||
const errorMessage = error?.message || "Unknown error";
|
||||
|
||||
if (statusCode === 401) {
|
||||
throw new CometAPIAuthenticationError(
|
||||
"CometAPI authentication failed during chat completion",
|
||||
);
|
||||
} else if (statusCode === 429) {
|
||||
throw new CometAPIQuotaExceededError(
|
||||
"CometAPI rate limit exceeded during chat completion",
|
||||
);
|
||||
} else if (
|
||||
errorMessage.includes("model") &&
|
||||
errorMessage.includes("not found")
|
||||
) {
|
||||
throw new CometAPIError(
|
||||
`Model "${this.model}" is not available on CometAPI. Please check available models.`,
|
||||
"MODEL_NOT_FOUND",
|
||||
404,
|
||||
);
|
||||
} else {
|
||||
// Re-throw with more context
|
||||
throw new CometAPIError(
|
||||
`CometAPI chat completion failed: ${errorMessage}`,
|
||||
"COMPLETION_ERROR",
|
||||
statusCode,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default CometAPI;
|
||||
|
|
@ -13,6 +13,7 @@ import LMStudio from "./LMStudio.js";
|
|||
import Cerebras from "./Cerebras.js";
|
||||
import DeepInfra from "./DeepInfra.js";
|
||||
import Nvidia from "./Nvidia.js";
|
||||
import CometAPI from "./CometAPI.js";
|
||||
|
||||
// Base OpenAI tests
|
||||
import { afterEach, describe, expect, test, vi } from "vitest";
|
||||
|
|
@ -292,3 +293,13 @@ createOpenAISubclassTests(Nvidia, {
|
|||
truncate: "END",
|
||||
},
|
||||
});
|
||||
|
||||
createOpenAISubclassTests(CometAPI, {
|
||||
providerName: "cometapi",
|
||||
defaultApiBase: "https://api.cometapi.com/v1/",
|
||||
modelConversions: {
|
||||
"gpt-5-mini": "gpt-5-mini",
|
||||
"claude-4-sonnet": "claude-sonnet-4-20250514",
|
||||
},
|
||||
modelConversionContent: "hello",
|
||||
});
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ import BedrockImport from "./BedrockImport";
|
|||
import Cerebras from "./Cerebras";
|
||||
import Cloudflare from "./Cloudflare";
|
||||
import Cohere from "./Cohere";
|
||||
import CometAPI from "./CometAPI";
|
||||
import DeepInfra from "./DeepInfra";
|
||||
import Deepseek from "./Deepseek";
|
||||
import Docker from "./Docker";
|
||||
|
|
@ -66,6 +67,7 @@ import xAI from "./xAI";
|
|||
export const LLMClasses = [
|
||||
Anthropic,
|
||||
Cohere,
|
||||
CometAPI,
|
||||
FunctionNetwork,
|
||||
Gemini,
|
||||
Llamafile,
|
||||
|
|
|
|||
BIN
gui/public/logos/cometapi.png
Normal file
BIN
gui/public/logos/cometapi.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 68 KiB |
|
|
@ -1852,4 +1852,380 @@ export const models: { [key: string]: ModelPackage } = {
|
|||
providerOptions: [],
|
||||
isOpenSource: false,
|
||||
},
|
||||
|
||||
// CometAPI Models
|
||||
|
||||
// GPT series models via CometAPI
|
||||
cometapiGpt5ChatLatest: {
|
||||
title: "GPT-5 Chat Latest",
|
||||
description:
|
||||
"GPT-5 Chat Latest via CometAPI - OpenAI's most advanced conversational model.",
|
||||
params: {
|
||||
model: "gpt-5-chat-latest",
|
||||
contextLength: 400_000,
|
||||
title: "GPT-5 Chat Latest",
|
||||
apiKey: "",
|
||||
},
|
||||
providerOptions: ["cometapi"],
|
||||
icon: "cometapi.png",
|
||||
isOpenSource: false,
|
||||
},
|
||||
cometapiGpt5Mini: {
|
||||
title: "GPT-5 Mini",
|
||||
description:
|
||||
"GPT-5 Mini via CometAPI - compact version of GPT-5 optimized for efficiency.",
|
||||
params: {
|
||||
model: "gpt-5-mini",
|
||||
contextLength: 400_000,
|
||||
title: "GPT-5 Mini",
|
||||
apiKey: "",
|
||||
},
|
||||
providerOptions: ["cometapi"],
|
||||
icon: "cometapi.png",
|
||||
isOpenSource: false,
|
||||
},
|
||||
cometapiGpt5: {
|
||||
title: "GPT-5",
|
||||
description:
|
||||
"GPT-5 via CometAPI - OpenAI's flagship model with advanced reasoning capabilities.",
|
||||
params: {
|
||||
model: "gpt-5",
|
||||
contextLength: 200_000,
|
||||
title: "GPT-5",
|
||||
apiKey: "",
|
||||
},
|
||||
providerOptions: ["cometapi"],
|
||||
icon: "cometapi.png",
|
||||
isOpenSource: false,
|
||||
},
|
||||
cometapiChatgpt4oLatest: {
|
||||
title: "ChatGPT-4o Latest",
|
||||
description:
|
||||
"ChatGPT-4o Latest via CometAPI - latest version of GPT-4o with enhanced capabilities.",
|
||||
params: {
|
||||
model: "chatgpt-4o-latest",
|
||||
contextLength: 128_000,
|
||||
title: "ChatGPT-4o Latest",
|
||||
apiKey: "",
|
||||
},
|
||||
providerOptions: ["cometapi"],
|
||||
icon: "cometapi.png",
|
||||
isOpenSource: false,
|
||||
},
|
||||
cometapiGpt41: {
|
||||
title: "GPT-4.1",
|
||||
description:
|
||||
"GPT-4.1 via CometAPI - enhanced version of GPT-4.1 with improved reasoning.",
|
||||
params: {
|
||||
model: "gpt-4.1",
|
||||
contextLength: 100_000,
|
||||
title: "GPT-4.1",
|
||||
apiKey: "",
|
||||
},
|
||||
providerOptions: ["cometapi"],
|
||||
icon: "cometapi.png",
|
||||
isOpenSource: false,
|
||||
},
|
||||
cometapiO4Mini: {
|
||||
title: "O4 Mini",
|
||||
description:
|
||||
"O4 Mini via CometAPI - OpenAI's reasoning model optimized for efficiency.",
|
||||
params: {
|
||||
model: "o4-mini-2025-04-16",
|
||||
contextLength: 200_000,
|
||||
title: "O4 Mini",
|
||||
apiKey: "",
|
||||
},
|
||||
providerOptions: ["cometapi"],
|
||||
icon: "cometapi.png",
|
||||
isOpenSource: false,
|
||||
},
|
||||
cometapiO3Pro: {
|
||||
title: "O3 Pro",
|
||||
description:
|
||||
"O3 Pro via CometAPI - advanced reasoning model with enhanced problem-solving capabilities.",
|
||||
params: {
|
||||
model: "o3-pro-2025-06-10",
|
||||
contextLength: 200_000,
|
||||
title: "O3 Pro",
|
||||
apiKey: "",
|
||||
},
|
||||
providerOptions: ["cometapi"],
|
||||
icon: "cometapi.png",
|
||||
isOpenSource: false,
|
||||
},
|
||||
|
||||
// Claude series models via CometAPI
|
||||
cometapiClaudeOpus41: {
|
||||
title: "Claude Opus 4.1",
|
||||
description:
|
||||
"Claude Opus 4.1 via CometAPI - Anthropic's most capable model with advanced reasoning.",
|
||||
params: {
|
||||
model: "claude-opus-4-1-20250805",
|
||||
contextLength: 200_000,
|
||||
title: "Claude Opus 4.1",
|
||||
apiKey: "",
|
||||
},
|
||||
providerOptions: ["cometapi"],
|
||||
icon: "cometapi.png",
|
||||
isOpenSource: false,
|
||||
},
|
||||
cometapiClaudeOpus41Thinking: {
|
||||
title: "Claude Opus 4.1 Thinking",
|
||||
description:
|
||||
"Claude Opus 4.1 Thinking via CometAPI - version with enhanced thinking capabilities.",
|
||||
params: {
|
||||
model: "claude-opus-4-1-20250805-thinking",
|
||||
contextLength: 200_000,
|
||||
title: "Claude Opus 4.1 Thinking",
|
||||
apiKey: "",
|
||||
},
|
||||
providerOptions: ["cometapi"],
|
||||
icon: "cometapi.png",
|
||||
isOpenSource: false,
|
||||
},
|
||||
cometapiClaudeSonnet4: {
|
||||
title: "Claude Sonnet 4",
|
||||
description:
|
||||
"Claude Sonnet 4 via CometAPI - balanced performance and efficiency from Anthropic.",
|
||||
params: {
|
||||
model: "claude-sonnet-4-20250514",
|
||||
contextLength: 200_000,
|
||||
title: "Claude Sonnet 4",
|
||||
apiKey: "",
|
||||
},
|
||||
providerOptions: ["cometapi"],
|
||||
icon: "cometapi.png",
|
||||
isOpenSource: false,
|
||||
},
|
||||
cometapiClaudeSonnet4Thinking: {
|
||||
title: "Claude Sonnet 4 Thinking",
|
||||
description:
|
||||
"Claude Sonnet 4 Thinking via CometAPI - version with enhanced reasoning capabilities.",
|
||||
params: {
|
||||
model: "claude-sonnet-4-20250514-thinking",
|
||||
contextLength: 200_000,
|
||||
title: "Claude Sonnet 4 Thinking",
|
||||
apiKey: "",
|
||||
},
|
||||
providerOptions: ["cometapi"],
|
||||
icon: "cometapi.png",
|
||||
isOpenSource: false,
|
||||
},
|
||||
cometapiClaude37SonnetLatest: {
|
||||
title: "Claude 3.7 Sonnet Latest",
|
||||
description:
|
||||
"Claude 3.7 Sonnet Latest via CometAPI - latest version of Claude 3.7 Sonnet.",
|
||||
params: {
|
||||
model: "claude-3-7-sonnet-latest",
|
||||
contextLength: 200_000,
|
||||
title: "Claude 3.7 Sonnet Latest",
|
||||
apiKey: "",
|
||||
},
|
||||
providerOptions: ["cometapi"],
|
||||
icon: "cometapi.png",
|
||||
isOpenSource: false,
|
||||
},
|
||||
cometapiClaude35HaikuLatest: {
|
||||
title: "Claude 3.5 Haiku Latest",
|
||||
description:
|
||||
"Claude 3.5 Haiku Latest via CometAPI - fast and efficient model from Anthropic.",
|
||||
params: {
|
||||
model: "claude-3-5-haiku-latest",
|
||||
contextLength: 200_000,
|
||||
title: "Claude 3.5 Haiku Latest",
|
||||
apiKey: "",
|
||||
},
|
||||
providerOptions: ["cometapi"],
|
||||
icon: "cometapi.png",
|
||||
isOpenSource: false,
|
||||
},
|
||||
|
||||
// Gemini series models via CometAPI
|
||||
cometapiGemini25Pro: {
|
||||
title: "Gemini 2.5 Pro",
|
||||
description:
|
||||
"Gemini 2.5 Pro via CometAPI - Google's advanced multimodal model with enhanced capabilities.",
|
||||
params: {
|
||||
model: "gemini-2.5-pro",
|
||||
contextLength: 1_000_000,
|
||||
title: "Gemini 2.5 Pro",
|
||||
apiKey: "",
|
||||
},
|
||||
providerOptions: ["cometapi"],
|
||||
icon: "cometapi.png",
|
||||
isOpenSource: false,
|
||||
},
|
||||
cometapiGemini25Flash: {
|
||||
title: "Gemini 2.5 Flash",
|
||||
description:
|
||||
"Gemini 2.5 Flash via CometAPI - optimized for speed and efficiency.",
|
||||
params: {
|
||||
model: "gemini-2.5-flash",
|
||||
contextLength: 1_000_000,
|
||||
title: "Gemini 2.5 Flash",
|
||||
apiKey: "",
|
||||
},
|
||||
providerOptions: ["cometapi"],
|
||||
icon: "cometapi.png",
|
||||
isOpenSource: false,
|
||||
},
|
||||
cometapiGemini25FlashLite: {
|
||||
title: "Gemini 2.5 Flash Lite",
|
||||
description:
|
||||
"Gemini 2.5 Flash Lite via CometAPI - lightweight version for faster responses.",
|
||||
params: {
|
||||
model: "gemini-2.5-flash-lite",
|
||||
contextLength: 8_000,
|
||||
title: "Gemini 2.5 Flash Lite",
|
||||
apiKey: "",
|
||||
},
|
||||
providerOptions: ["cometapi"],
|
||||
icon: "cometapi.png",
|
||||
isOpenSource: false,
|
||||
},
|
||||
cometapiGemini20Flash: {
|
||||
title: "Gemini 2.0 Flash",
|
||||
description:
|
||||
"Gemini 2.0 Flash via CometAPI - Google's powerful workhorse model with low latency.",
|
||||
params: {
|
||||
model: "gemini-2.0-flash",
|
||||
contextLength: 32_000,
|
||||
title: "Gemini 2.0 Flash",
|
||||
apiKey: "",
|
||||
},
|
||||
providerOptions: ["cometapi"],
|
||||
icon: "cometapi.png",
|
||||
isOpenSource: false,
|
||||
},
|
||||
|
||||
// Grok series models via CometAPI
|
||||
cometapiGrok40709: {
|
||||
title: "Grok 4",
|
||||
description:
|
||||
"Grok 4 via CometAPI - xAI's advanced model with real-time information access.",
|
||||
params: {
|
||||
model: "grok-4-0709",
|
||||
contextLength: 256_000,
|
||||
title: "Grok 4",
|
||||
apiKey: "",
|
||||
},
|
||||
providerOptions: ["cometapi"],
|
||||
icon: "cometapi.png",
|
||||
isOpenSource: false,
|
||||
},
|
||||
cometapiGrok3: {
|
||||
title: "Grok 3",
|
||||
description: "Grok 3 via CometAPI - powerful reasoning model from xAI.",
|
||||
params: {
|
||||
model: "grok-3",
|
||||
contextLength: 128_000,
|
||||
title: "Grok 3",
|
||||
apiKey: "",
|
||||
},
|
||||
providerOptions: ["cometapi"],
|
||||
icon: "cometapi.png",
|
||||
isOpenSource: false,
|
||||
},
|
||||
cometapiGrok3Mini: {
|
||||
title: "Grok 3 Mini",
|
||||
description: "Grok 3 Mini via CometAPI - efficient version of Grok 3.",
|
||||
params: {
|
||||
model: "grok-3-mini",
|
||||
contextLength: 128_000,
|
||||
title: "Grok 3 Mini",
|
||||
apiKey: "",
|
||||
},
|
||||
providerOptions: ["cometapi"],
|
||||
icon: "cometapi.png",
|
||||
isOpenSource: false,
|
||||
},
|
||||
|
||||
// DeepSeek series models via CometAPI (additional)
|
||||
cometapiDeepseekV31: {
|
||||
title: "DeepSeek V3.1",
|
||||
description:
|
||||
"DeepSeek V3.1 via CometAPI - enhanced version with improved performance.",
|
||||
params: {
|
||||
model: "deepseek-v3.1",
|
||||
contextLength: 128_000,
|
||||
title: "DeepSeek V3.1",
|
||||
apiKey: "",
|
||||
},
|
||||
providerOptions: ["cometapi"],
|
||||
icon: "cometapi.png",
|
||||
isOpenSource: false,
|
||||
},
|
||||
cometapiDeepseekR10528: {
|
||||
title: "DeepSeek R1",
|
||||
description:
|
||||
"DeepSeek R1 via CometAPI - reasoning model with enhanced problem-solving capabilities.",
|
||||
params: {
|
||||
model: "deepseek-r1-0528",
|
||||
contextLength: 64_000,
|
||||
title: "DeepSeek R1",
|
||||
apiKey: "",
|
||||
},
|
||||
providerOptions: ["cometapi"],
|
||||
icon: "cometapi.png",
|
||||
isOpenSource: false,
|
||||
},
|
||||
cometapiDeepseekChat: {
|
||||
title: "DeepSeek Chat",
|
||||
description:
|
||||
"DeepSeek Chat via CometAPI - optimized for conversational AI tasks.",
|
||||
params: {
|
||||
model: "deepseek-chat",
|
||||
contextLength: 64_000,
|
||||
title: "DeepSeek Chat",
|
||||
apiKey: "",
|
||||
},
|
||||
providerOptions: ["cometapi"],
|
||||
icon: "cometapi.png",
|
||||
isOpenSource: false,
|
||||
},
|
||||
cometapiDeepseekReasoner: {
|
||||
title: "DeepSeek Reasoner",
|
||||
description:
|
||||
"DeepSeek Reasoner via CometAPI - specialized model for complex reasoning tasks.",
|
||||
params: {
|
||||
model: "deepseek-reasoner",
|
||||
contextLength: 64_000,
|
||||
title: "DeepSeek Reasoner",
|
||||
apiKey: "",
|
||||
},
|
||||
providerOptions: ["cometapi"],
|
||||
icon: "cometapi.png",
|
||||
isOpenSource: false,
|
||||
},
|
||||
|
||||
// Qwen series models via CometAPI
|
||||
cometapiQwen330BA3B: {
|
||||
title: "Qwen 3 30B A3B",
|
||||
description:
|
||||
"Qwen 3 30B A3B via CometAPI - Alibaba's advanced language model with 30B parameters.",
|
||||
params: {
|
||||
model: "qwen3-30b-a3b",
|
||||
contextLength: 128_000,
|
||||
title: "Qwen 3 30B A3B",
|
||||
apiKey: "",
|
||||
},
|
||||
providerOptions: ["cometapi"],
|
||||
icon: "cometapi.png",
|
||||
isOpenSource: false,
|
||||
},
|
||||
cometapiQwen3CoderPlus: {
|
||||
title: "Qwen 3 Coder Plus",
|
||||
description:
|
||||
"Qwen 3 Coder Plus via CometAPI - specialized coding model from Alibaba.",
|
||||
params: {
|
||||
model: "qwen3-coder-plus-2025-07-22",
|
||||
contextLength: 262_000,
|
||||
title: "Qwen 3 Coder Plus",
|
||||
apiKey: "",
|
||||
},
|
||||
providerOptions: ["cometapi"],
|
||||
icon: "cometapi.png",
|
||||
isOpenSource: false,
|
||||
},
|
||||
};
|
||||
|
|
|
|||
|
|
@ -49,6 +49,65 @@ export const apiBaseInput: InputDescriptor = {
|
|||
};
|
||||
|
||||
export const providers: Partial<Record<string, ProviderInfo>> = {
|
||||
cometapi: {
|
||||
title: "CometAPI",
|
||||
provider: "cometapi",
|
||||
description: "500+ AI Model API,All In One API. Just In CometAPI",
|
||||
longDescription:
|
||||
"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.",
|
||||
icon: "cometapi.png",
|
||||
tags: [ModelProviderTags.RequiresApiKey],
|
||||
collectInputFor: [
|
||||
{
|
||||
inputType: "text",
|
||||
key: "apiKey",
|
||||
label: "API Key",
|
||||
placeholder: "Enter your CometAPI key",
|
||||
required: true,
|
||||
},
|
||||
...completionParamsInputsConfigs,
|
||||
],
|
||||
packages: [
|
||||
// GPT, OpenAI family
|
||||
models.cometapiGpt5ChatLatest,
|
||||
models.cometapiGpt5Mini,
|
||||
models.cometapiGpt5,
|
||||
models.cometapiChatgpt4oLatest,
|
||||
models.cometapiGpt41,
|
||||
models.cometapiO4Mini,
|
||||
models.cometapiO3Pro,
|
||||
// Anthropic Claude family
|
||||
models.cometapiClaudeOpus41,
|
||||
models.cometapiClaudeOpus41Thinking,
|
||||
models.cometapiClaudeSonnet4,
|
||||
models.cometapiClaudeSonnet4Thinking,
|
||||
models.cometapiClaude37SonnetLatest,
|
||||
models.cometapiClaude35HaikuLatest,
|
||||
// Google Gemini family
|
||||
models.cometapiGemini25Pro,
|
||||
models.cometapiGemini25Flash,
|
||||
models.cometapiGemini25FlashLite,
|
||||
models.cometapiGemini20Flash,
|
||||
// xAI Grok family
|
||||
models.cometapiGrok40709,
|
||||
models.cometapiGrok3,
|
||||
models.cometapiGrok3Mini,
|
||||
// Deepseek family
|
||||
models.cometapiDeepseekV31,
|
||||
models.cometapiDeepseekR10528,
|
||||
models.cometapiDeepseekChat,
|
||||
models.cometapiDeepseekReasoner,
|
||||
// Qwen family
|
||||
models.cometapiQwen330BA3B,
|
||||
models.cometapiQwen3CoderPlus,
|
||||
//TODO: Need to wait for the improvement after the upgrade of the cometapi model list interface
|
||||
// {
|
||||
// ...models.AUTODETECT,
|
||||
// params: { ...models.AUTODETECT.params, title: "CometAPI" },
|
||||
// },
|
||||
],
|
||||
apiKeyUrl: "https://api.cometapi.com/console/token",
|
||||
},
|
||||
openai: {
|
||||
title: "OpenAI",
|
||||
provider: "openai",
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import { Anthropic } from "./providers/anthropic.js";
|
|||
import { Azure } from "./providers/azure.js";
|
||||
import { Bedrock } from "./providers/bedrock.js";
|
||||
import { Cohere } from "./providers/cohere.js";
|
||||
import { CometAPI } from "./providers/cometapi.js";
|
||||
import { Gemini } from "./providers/gemini.js";
|
||||
import { Mistral } from "./providers/mistral.js";
|
||||
import { Ollama } from "./providers/ollama.js";
|
||||
|
|
@ -22,6 +23,7 @@ export const allModelProviders: ModelProvider[] = [
|
|||
Vllm,
|
||||
Bedrock,
|
||||
Cohere,
|
||||
CometAPI,
|
||||
xAI,
|
||||
];
|
||||
|
||||
|
|
|
|||
280
packages/llm-info/src/providers/cometapi.ts
Normal file
280
packages/llm-info/src/providers/cometapi.ts
Normal file
|
|
@ -0,0 +1,280 @@
|
|||
import { ModelProvider } from "../types.js";
|
||||
|
||||
export const CometAPI: ModelProvider = {
|
||||
id: "cometapi",
|
||||
displayName: "CometAPI",
|
||||
models: [
|
||||
// GPT Series
|
||||
{
|
||||
model: "gpt-5-chat-latest",
|
||||
displayName: "GPT-5 Chat Latest",
|
||||
contextLength: 200000,
|
||||
maxCompletionTokens: 8192,
|
||||
description:
|
||||
"Latest GPT-5 model optimized for chat conversations with enhanced reasoning capabilities.",
|
||||
recommendedFor: ["chat"],
|
||||
},
|
||||
{
|
||||
model: "chatgpt-4o-latest",
|
||||
displayName: "ChatGPT-4o Latest",
|
||||
contextLength: 128000,
|
||||
maxCompletionTokens: 4096,
|
||||
description:
|
||||
"Latest ChatGPT-4o model with improved performance and updated training data.",
|
||||
recommendedFor: ["chat"],
|
||||
},
|
||||
{
|
||||
model: "gpt-5-mini",
|
||||
displayName: "GPT-5 Mini",
|
||||
contextLength: 128000,
|
||||
maxCompletionTokens: 4096,
|
||||
description:
|
||||
"Efficient version of GPT-5 with faster response times while maintaining high quality.",
|
||||
recommendedFor: ["chat"],
|
||||
},
|
||||
{
|
||||
model: "gpt-5-nano",
|
||||
displayName: "GPT-5 Nano",
|
||||
contextLength: 64000,
|
||||
maxCompletionTokens: 2048,
|
||||
description:
|
||||
"Ultra-fast GPT-5 variant optimized for quick responses and simple tasks.",
|
||||
recommendedFor: ["chat"],
|
||||
},
|
||||
{
|
||||
model: "gpt-5",
|
||||
displayName: "GPT-5",
|
||||
contextLength: 200000,
|
||||
maxCompletionTokens: 8192,
|
||||
description:
|
||||
"Advanced GPT-5 model with state-of-the-art language understanding and generation.",
|
||||
recommendedFor: ["chat"],
|
||||
},
|
||||
{
|
||||
model: "gpt-4o-mini",
|
||||
displayName: "GPT-4o Mini",
|
||||
contextLength: 128000,
|
||||
maxCompletionTokens: 4096,
|
||||
description:
|
||||
"Compact version of GPT-4o with excellent performance for most use cases.",
|
||||
recommendedFor: ["chat"],
|
||||
},
|
||||
{
|
||||
model: "o4-mini-2025-04-16",
|
||||
displayName: "o4 Mini (2025-04-16)",
|
||||
contextLength: 128000,
|
||||
maxCompletionTokens: 4096,
|
||||
description:
|
||||
"Optimized o4 mini model with April 2025 training improvements.",
|
||||
recommendedFor: ["chat"],
|
||||
},
|
||||
{
|
||||
model: "o3-pro-2025-06-10",
|
||||
displayName: "o3 Pro (2025-06-10)",
|
||||
contextLength: 200000,
|
||||
maxCompletionTokens: 8192,
|
||||
description:
|
||||
"Professional-grade o3 model with enhanced reasoning and problem-solving capabilities.",
|
||||
recommendedFor: ["chat"],
|
||||
},
|
||||
|
||||
// Claude Series
|
||||
{
|
||||
model: "claude-opus-4-1-20250805",
|
||||
displayName: "Claude Opus 4.1 (2025-08-05)",
|
||||
contextLength: 200000,
|
||||
maxCompletionTokens: 8192,
|
||||
description:
|
||||
"Most capable Claude model with exceptional reasoning, analysis, and creative capabilities.",
|
||||
recommendedFor: ["chat"],
|
||||
},
|
||||
{
|
||||
model: "claude-opus-4-1-20250805-thinking",
|
||||
displayName: "Claude Opus 4.1 Thinking (2025-08-05)",
|
||||
contextLength: 200000,
|
||||
maxCompletionTokens: 8192,
|
||||
description:
|
||||
"Claude Opus with enhanced thinking process for complex problem-solving tasks.",
|
||||
recommendedFor: ["chat"],
|
||||
},
|
||||
{
|
||||
model: "claude-sonnet-4-20250514",
|
||||
displayName: "Claude Sonnet 4 (2025-05-14)",
|
||||
contextLength: 200000,
|
||||
maxCompletionTokens: 8192,
|
||||
description:
|
||||
"Balanced Claude model offering excellent performance across various tasks.",
|
||||
recommendedFor: ["chat"],
|
||||
},
|
||||
{
|
||||
model: "claude-sonnet-4-20250514-thinking",
|
||||
displayName: "Claude Sonnet 4 Thinking (2025-05-14)",
|
||||
contextLength: 200000,
|
||||
maxCompletionTokens: 8192,
|
||||
description:
|
||||
"Claude Sonnet with enhanced reasoning capabilities for analytical tasks.",
|
||||
recommendedFor: ["chat"],
|
||||
},
|
||||
{
|
||||
model: "claude-3-7-sonnet-latest",
|
||||
displayName: "Claude 3.7 Sonnet Latest",
|
||||
contextLength: 200000,
|
||||
maxCompletionTokens: 4096,
|
||||
description:
|
||||
"Latest Claude 3.7 Sonnet with improved instruction following and safety.",
|
||||
recommendedFor: ["chat"],
|
||||
},
|
||||
{
|
||||
model: "claude-3-5-haiku-latest",
|
||||
displayName: "Claude 3.5 Haiku Latest",
|
||||
contextLength: 200000,
|
||||
maxCompletionTokens: 4096,
|
||||
description:
|
||||
"Fast and efficient Claude model optimized for quick responses.",
|
||||
recommendedFor: ["chat"],
|
||||
},
|
||||
|
||||
// Gemini Series
|
||||
{
|
||||
model: "gemini-2.5-pro",
|
||||
displayName: "Gemini 2.5 Pro",
|
||||
contextLength: 2000000,
|
||||
maxCompletionTokens: 8192,
|
||||
description:
|
||||
"Advanced Gemini model with extensive context window and multimodal capabilities.",
|
||||
recommendedFor: ["chat"],
|
||||
},
|
||||
{
|
||||
model: "gemini-2.5-flash",
|
||||
displayName: "Gemini 2.5 Flash",
|
||||
contextLength: 1000000,
|
||||
maxCompletionTokens: 8192,
|
||||
description:
|
||||
"Fast Gemini model with large context window optimized for speed.",
|
||||
recommendedFor: ["chat"],
|
||||
},
|
||||
{
|
||||
model: "gemini-2.5-flash-lite",
|
||||
displayName: "Gemini 2.5 Flash Lite",
|
||||
contextLength: 1000000,
|
||||
maxCompletionTokens: 4096,
|
||||
description:
|
||||
"Lightweight version of Gemini Flash for efficient processing.",
|
||||
recommendedFor: ["chat"],
|
||||
},
|
||||
{
|
||||
model: "gemini-2.0-flash",
|
||||
displayName: "Gemini 2.0 Flash",
|
||||
contextLength: 1000000,
|
||||
maxCompletionTokens: 8192,
|
||||
description:
|
||||
"High-performance Gemini model with excellent speed-quality balance.",
|
||||
recommendedFor: ["chat"],
|
||||
},
|
||||
|
||||
// Grok Series
|
||||
{
|
||||
model: "grok-4-0709",
|
||||
displayName: "Grok 4 (07-09)",
|
||||
contextLength: 128000,
|
||||
maxCompletionTokens: 4096,
|
||||
description:
|
||||
"Latest Grok model with improved reasoning and conversational abilities.",
|
||||
recommendedFor: ["chat"],
|
||||
},
|
||||
{
|
||||
model: "grok-3",
|
||||
displayName: "Grok 3",
|
||||
contextLength: 128000,
|
||||
maxCompletionTokens: 4096,
|
||||
description:
|
||||
"Advanced Grok model with enhanced understanding and generation capabilities.",
|
||||
recommendedFor: ["chat"],
|
||||
},
|
||||
{
|
||||
model: "grok-3-mini",
|
||||
displayName: "Grok 3 Mini",
|
||||
contextLength: 64000,
|
||||
maxCompletionTokens: 2048,
|
||||
description:
|
||||
"Compact Grok model optimized for efficiency and quick responses.",
|
||||
recommendedFor: ["chat"],
|
||||
},
|
||||
{
|
||||
model: "grok-2-image-1212",
|
||||
displayName: "Grok 2 Image (12-12)",
|
||||
contextLength: 128000,
|
||||
maxCompletionTokens: 4096,
|
||||
description:
|
||||
"Grok model with enhanced image understanding and multimodal capabilities.",
|
||||
recommendedFor: ["chat"],
|
||||
},
|
||||
|
||||
// DeepSeek Series
|
||||
{
|
||||
model: "deepseek-v3.1",
|
||||
displayName: "DeepSeek V3.1",
|
||||
contextLength: 128000,
|
||||
maxCompletionTokens: 4096,
|
||||
description:
|
||||
"Latest DeepSeek model with improved reasoning and coding capabilities.",
|
||||
recommendedFor: ["chat"],
|
||||
},
|
||||
{
|
||||
model: "deepseek-v3",
|
||||
displayName: "DeepSeek V3",
|
||||
contextLength: 128000,
|
||||
maxCompletionTokens: 4096,
|
||||
description:
|
||||
"Advanced DeepSeek model with strong performance in technical domains.",
|
||||
recommendedFor: ["chat"],
|
||||
},
|
||||
{
|
||||
model: "deepseek-r1-0528",
|
||||
displayName: "DeepSeek R1 (05-28)",
|
||||
contextLength: 128000,
|
||||
maxCompletionTokens: 4096,
|
||||
description:
|
||||
"DeepSeek reasoning model optimized for complex problem-solving tasks.",
|
||||
recommendedFor: ["chat"],
|
||||
},
|
||||
{
|
||||
model: "deepseek-chat",
|
||||
displayName: "DeepSeek Chat",
|
||||
contextLength: 128000,
|
||||
maxCompletionTokens: 4096,
|
||||
description:
|
||||
"DeepSeek model specifically optimized for conversational interactions.",
|
||||
recommendedFor: ["chat"],
|
||||
},
|
||||
{
|
||||
model: "deepseek-reasoner",
|
||||
displayName: "DeepSeek Reasoner",
|
||||
contextLength: 128000,
|
||||
maxCompletionTokens: 4096,
|
||||
description:
|
||||
"DeepSeek model with enhanced reasoning capabilities for analytical tasks.",
|
||||
recommendedFor: ["chat"],
|
||||
},
|
||||
|
||||
// Qwen Series
|
||||
{
|
||||
model: "qwen3-30b-a3b",
|
||||
displayName: "Qwen3 30B A3B",
|
||||
contextLength: 128000,
|
||||
maxCompletionTokens: 4096,
|
||||
description:
|
||||
"Large Qwen model with 30B parameters for high-quality text generation.",
|
||||
recommendedFor: ["chat"],
|
||||
},
|
||||
{
|
||||
model: "qwen3-coder-plus-2025-07-22",
|
||||
displayName: "Qwen3 Coder Plus (2025-07-22)",
|
||||
contextLength: 128000,
|
||||
maxCompletionTokens: 4096,
|
||||
description:
|
||||
"Qwen model specialized for coding tasks with enhanced programming capabilities.",
|
||||
recommendedFor: ["chat"],
|
||||
},
|
||||
],
|
||||
};
|
||||
132
packages/openai-adapters/src/apis/CometAPI.ts
Normal file
132
packages/openai-adapters/src/apis/CometAPI.ts
Normal file
|
|
@ -0,0 +1,132 @@
|
|||
import {
|
||||
ChatCompletion,
|
||||
ChatCompletionChunk,
|
||||
ChatCompletionCreateParams,
|
||||
ChatCompletionCreateParamsNonStreaming,
|
||||
ChatCompletionCreateParamsStreaming,
|
||||
Completion,
|
||||
CompletionCreateParamsNonStreaming,
|
||||
CompletionCreateParamsStreaming,
|
||||
CreateEmbeddingResponse,
|
||||
EmbeddingCreateParams,
|
||||
Model,
|
||||
} from "openai/resources/index";
|
||||
import { CometAPIConfig } from "../types.js";
|
||||
import {
|
||||
BaseLlmApi,
|
||||
CreateRerankResponse,
|
||||
FimCreateParamsStreaming,
|
||||
RerankCreateParams,
|
||||
} from "./base.js";
|
||||
import { OpenAIApi } from "./OpenAI.js";
|
||||
|
||||
/**
|
||||
* CometAPI adapter - extends OpenAI adapter since CometAPI is OpenAI-compatible
|
||||
*
|
||||
* CometAPI provides access to multiple LLM providers (GPT, Claude, Gemini, etc.)
|
||||
* through a unified OpenAI-compatible API interface.
|
||||
*/
|
||||
export class CometAPIApi extends OpenAIApi implements BaseLlmApi {
|
||||
// Store the original CometAPI config separately
|
||||
private cometConfig: CometAPIConfig;
|
||||
|
||||
constructor(config: CometAPIConfig) {
|
||||
// CometAPI uses OpenAI-compatible API, so we can reuse OpenAI adapter
|
||||
// Convert CometAPI config to OpenAI-compatible config for the base class
|
||||
const openAICompatibleConfig = {
|
||||
...config,
|
||||
provider: "openai" as const,
|
||||
apiBase: config.apiBase ?? "https://api.cometapi.com/v1/",
|
||||
};
|
||||
super(openAICompatibleConfig);
|
||||
|
||||
// Store original config after super() call
|
||||
this.cometConfig = config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override list method to handle CometAPI-specific model filtering
|
||||
* The core filtering logic is handled in the CometAPI provider class
|
||||
*/
|
||||
async list(): Promise<Model[]> {
|
||||
try {
|
||||
return await super.list();
|
||||
} catch (error) {
|
||||
// Fallback to empty list if model listing fails
|
||||
console.warn("CometAPI: Failed to fetch model list", error);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Chat completion - uses OpenAI-compatible format
|
||||
*/
|
||||
async chatCompletionNonStream(
|
||||
body: ChatCompletionCreateParamsNonStreaming,
|
||||
signal: AbortSignal,
|
||||
): Promise<ChatCompletion> {
|
||||
return super.chatCompletionNonStream(body, signal);
|
||||
}
|
||||
|
||||
/**
|
||||
* Streaming chat completion - uses OpenAI-compatible format
|
||||
*/
|
||||
async *chatCompletionStream(
|
||||
body: ChatCompletionCreateParamsStreaming,
|
||||
signal: AbortSignal,
|
||||
): AsyncGenerator<ChatCompletionChunk> {
|
||||
yield* super.chatCompletionStream(body, signal);
|
||||
}
|
||||
|
||||
/**
|
||||
* Legacy completion endpoint support
|
||||
*/
|
||||
completionNonStream(
|
||||
body: CompletionCreateParamsNonStreaming,
|
||||
signal: AbortSignal,
|
||||
): Promise<Completion> {
|
||||
return super.completionNonStream(body, signal);
|
||||
}
|
||||
|
||||
/**
|
||||
* Legacy streaming completion endpoint support
|
||||
*/
|
||||
completionStream(
|
||||
body: CompletionCreateParamsStreaming,
|
||||
signal: AbortSignal,
|
||||
): AsyncGenerator<Completion> {
|
||||
return super.completionStream(body, signal);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill-in-the-middle completion support
|
||||
*/
|
||||
fimStream(
|
||||
body: FimCreateParamsStreaming,
|
||||
signal: AbortSignal,
|
||||
): AsyncGenerator<ChatCompletionChunk> {
|
||||
return super.fimStream(body, signal);
|
||||
}
|
||||
|
||||
/**
|
||||
* Embeddings support (if available through CometAPI)
|
||||
*/
|
||||
async embed(body: EmbeddingCreateParams): Promise<CreateEmbeddingResponse> {
|
||||
try {
|
||||
return await super.embed(body);
|
||||
} catch (error) {
|
||||
throw new Error(`CometAPI embeddings not supported: ${error}`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reranking support (if available through CometAPI)
|
||||
*/
|
||||
async rerank(body: RerankCreateParams): Promise<CreateRerankResponse> {
|
||||
try {
|
||||
return await super.rerank(body);
|
||||
} catch (error) {
|
||||
throw new Error(`CometAPI reranking not supported: ${error}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -18,6 +18,7 @@ import { VertexAIApi } from "./apis/VertexAI.js";
|
|||
import { WatsonXApi } from "./apis/WatsonX.js";
|
||||
import { BaseLlmApi } from "./apis/base.js";
|
||||
import { LLMConfig, OpenAIConfigSchema } from "./types.js";
|
||||
import { CometAPIApi } from "./apis/CometAPI.js";
|
||||
|
||||
dotenv.config();
|
||||
|
||||
|
|
@ -68,6 +69,8 @@ export function constructLlmApi(config: LLMConfig): BaseLlmApi | undefined {
|
|||
return new BedrockApi(config);
|
||||
case "cohere":
|
||||
return new CohereApi(config);
|
||||
case "cometapi":
|
||||
return new CometAPIApi(config);
|
||||
case "anthropic":
|
||||
return new AnthropicApi(config);
|
||||
case "gemini":
|
||||
|
|
|
|||
|
|
@ -116,6 +116,11 @@ export const CohereConfigSchema = OpenAIConfigSchema.extend({
|
|||
});
|
||||
export type CohereConfig = z.infer<typeof CohereConfigSchema>;
|
||||
|
||||
export const CometAPIConfigSchema = OpenAIConfigSchema.extend({
|
||||
provider: z.literal("cometapi"),
|
||||
});
|
||||
export type CometAPIConfig = z.infer<typeof CometAPIConfigSchema>;
|
||||
|
||||
export const AzureConfigSchema = OpenAIConfigSchema.extend({
|
||||
provider: z.literal("azure"),
|
||||
env: z
|
||||
|
|
@ -197,5 +202,6 @@ export const LLMConfigSchema = z.discriminatedUnion("provider", [
|
|||
VertexAIConfigSchema,
|
||||
LlamastackConfigSchema,
|
||||
ContinueProxyConfigSchema,
|
||||
CometAPIConfigSchema,
|
||||
]);
|
||||
export type LLMConfig = z.infer<typeof LLMConfigSchema>;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue