ai.libx.js
Version:
Unified API bridge for various AI models (LLMs, image/video generation, TTS, STT) - stateless, edge-compatible
256 lines • 17.5 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.supportedModels = void 0;
exports.getProviderFromModel = getProviderFromModel;
exports.getModelInfo = getModelInfo;
exports.listModels = listModels;
exports.isModelSupported = isModelSupported;
exports.resolveModel = resolveModel;
exports.supportedModels = {
'openai/gpt-5': { displayName: 'GPT-5', usesMaxCompletionTokens: true, reasoning: true, knownIssues: 'Highly unpredictable reasoning token usage (can use 1000+ tokens); recommend 1500+ max_completion_tokens for reliability' },
'openai/gpt-5-mini': { displayName: 'GPT-5 mini', usesMaxCompletionTokens: true, reasoning: true },
'openai/gpt-5-nano': { displayName: 'GPT-5 nano', usesMaxCompletionTokens: true, reasoning: true },
'openai/gpt-5-chat-latest': { displayName: 'GPT-5 Chat', usesMaxCompletionTokens: true },
'openai/gpt-4.1': { displayName: 'GPT 4.1', usesMaxCompletionTokens: true },
'openai/gpt-4.1-mini': { displayName: 'GPT 4.1 mini', usesMaxCompletionTokens: true },
'openai/gpt-4.1-nano': { displayName: 'GPT 4.1 nano', usesMaxCompletionTokens: true },
'openai/gpt-4.5-preview': { displayName: 'gpt 4.5 preview' },
'openai/o3-mini': { displayName: 'gpt o3 mini', noSystem: true, usesMaxCompletionTokens: true },
'openai/gpt-4o-audio-preview': { displayName: 'gpt-4o-audio-preview', enabled: false },
'openai/gpt-4o-mini-audio-preview': { displayName: 'gpt-4o-mini-audio-preview', enabled: false },
'openai/gpt-4o-mini-realtime-preview': { displayName: 'gpt-4o-mini-realtime-preview', noChat: true },
'openai/gpt-4o-realtime-preview': { displayName: 'gpt-4o-realtime-preview', noChat: true },
'openai/o1-preview': { displayName: 'o1-preview', noSystem: true, usesMaxCompletionTokens: true },
'openai/o1-mini': { displayName: 'o1-mini', noSystem: true, usesMaxCompletionTokens: true },
'openai/o1': { displayName: 'o1', noSystem: true, enabled: false, usesMaxCompletionTokens: true },
'openai/chatgpt-4o-latest': { displayName: ' ChatGPT GPT-4o' },
'openai/gpt-4o-mini': { displayName: 'GPT-4o mini' },
'openai/gpt-4o': { displayName: ' GPT-4o' },
'openai/gpt-4o-2024-05-13': { displayName: ' GPT-4o (2024-05-13)' },
'openai/gpt-4-turbo': { displayName: 'GPT-4 Turbo with Vision' },
'openai/gpt-4-turbo-2024-04-09': { displayName: 'GPT-4 Turbo with Vision (2024-04-09)' },
'openai/gpt-4-turbo-preview': { displayName: 'GPT-4 Turbo (gpt-4-turbo-preview)' },
'openai/gpt-4-0125-preview': { displayName: 'GPT-4 25-01 (gpt-4-0125-preview)' },
'openai/gpt-4-1106-preview': { displayName: 'GPT-4 06-11 (gpt-4-1106-preview)' },
'openai/gpt-4-vision-preview': { displayName: 'GPT-4 Vision', enabled: false },
'openai/gpt-4-32k': { displayName: 'gpt-4-32k' },
'openai/gpt-4-0613': { displayName: 'gpt-4-0613' },
'openai/gpt-4-32k-0613': { displayName: 'gpt-4-32k-0613' },
'openai/gpt-4': { displayName: 'gpt-4' },
'openai/gpt-4-0314': { displayName: 'gpt-4-0314' },
'openai/gpt-3.5-turbo': { displayName: 'gpt-3.5-turbo' },
'openai/gpt-3.5-turbo-0125': { displayName: 'gpt-3.5-turbo-0125' },
'openai/gpt-3.5-turbo-1106': { displayName: 'gpt-3.5-turbo-1106' },
'openai/gpt-3.5-turbo-instruct': { displayName: 'gpt-3.5-turbo-instruct' },
'openai/gpt-3.5-turbo-16k': { displayName: 'gpt-3.5-turbo-16k' },
'openai/gpt-3.5-turbo-0613': { displayName: 'gpt-3.5-turbo-0613', enabled: false },
'openai/gpt-3.5-turbo-16k-0613': { displayName: 'gpt-3.5-turbo-16k-0613', enabled: false },
'openai/text-davinci-003': { displayName: 'text-davinci-003' },
'openai/text-davinci-002': { displayName: 'text-davinci-002' },
'google/models/gemini-2.5-flash': { displayName: 'Gemini 2.5 Flash', reasoning: true },
'google/models/gemini-2.5-flash-lite-preview-06-17': { displayName: 'Gemini 2.5 Flash-Lite Preview 06-17', reasoning: true },
'google/models/gemini-2.5-pro': { displayName: 'Gemini 2.5 Pro', reasoning: true },
'google/models/gemini-2.5-pro-exp-03-25': { displayName: 'Gemini 2.5 Pro Experimental 03-25', reasoning: true },
'google/models/gemini-2.0-flash': { displayName: 'Gemini 2.0 Flash' },
'google/models/gemini-2.0-flash-lite': { displayName: 'Gemini 2.0 Flash-Lite' },
'google/models/gemini-2.0-flash-preview-image-generation': { displayName: 'Gemini 2.0 Flash Preview Image Generation', responseModalities: ['Text', 'Image'] },
'google/models/gemini-2.0-pro-exp-02-05': { displayName: 'Gemini 2.0 Pro Experimental 02-05' },
'google/models/gemini-2.0-flash-thinking-exp-01-21': { displayName: 'Gemini 2.0 Flash Thinking Experimental 01-21' },
'google/models/gemini-2.0-flash-exp': { displayName: 'Gemini 2.0 Flash Experimental', responseModalities: ['Text', 'Image'] },
'google/models/gemini-2.0-flash-thinking-exp-1219': { displayName: 'Gemini 2.0 Flash Thinking Mode' },
'google/models/gemma-3n-e4b-it': { displayName: 'Gemma 3n E4B' },
'google/models/gemma-3n-e2b-it': { displayName: 'Gemma 3n E2B' },
'google/models/gemma-3-27b-it': { displayName: 'Gemma 3 27B' },
'google/models/learnlm-1.5-pro-experimental': { displayName: 'LearnLM 1.5 Pro Experimental' },
'google/models/gemini-exp-1206': { displayName: 'Gemini (exp-1206)' },
'google/models/gemini-1.5-flash-8b': { displayName: 'Gemini 1.5 Flash-8B' },
'google/models/gemini-1.5-pro-002': { displayName: 'Gemini 1.5 Pro 2' },
'google/models/gemini-1.5-flash-002': { displayName: 'Gemini 1.5 Flash 2' },
'google/models/gemini-1.5-flash-latest': { displayName: 'Gemini 1.5 Flash' },
'google/models/gemini-1.5-pro-latest': { displayName: 'Gemini 1.5 Pro' },
'google/models/gemini-1.0-pro-latest': { displayName: 'Gemini 1.0 Pro' },
'google/models/gemini-pro-vision': { displayName: 'Gemini 1.0 Pro Vision' },
'google/models/chat-bison-001': { displayName: 'PaLM 2 Chat (Legacy)' },
'anthropic/claude-haiku-4-5': { displayName: 'Claude Haiku 4.5', url: 'https://api.anthropic.com/v1/messages' },
'anthropic/claude-opus-4-1': { displayName: 'Claude Opus 4.1', url: 'https://api.anthropic.com/v1/messages' },
'anthropic/claude-opus-4-0': { displayName: 'Claude Opus 4', url: 'https://api.anthropic.com/v1/messages' },
'anthropic/claude-sonnet-4-5': { displayName: 'Claude Sonnet 4.5', url: 'https://api.anthropic.com/v1/messages' },
'anthropic/claude-sonnet-4-0': { displayName: 'Claude Sonnet 4', url: 'https://api.anthropic.com/v1/messages' },
'anthropic/claude-3-7-sonnet-latest': { displayName: 'Claude 3.7 Sonnet', url: 'https://api.anthropic.com/v1/messages' },
'anthropic/claude-3-5-sonnet-latest': { displayName: 'Claude 3.5 Sonnet v2', url: 'https://api.anthropic.com/v1/messages' },
'anthropic/claude-3-5-haiku-latest': { displayName: 'Claude 3.5 Haiku', url: 'https://api.anthropic.com/v1/messages' },
'anthropic/claude-3-haiku-20240307': { displayName: 'Claude 3 Haiku', url: 'https://api.anthropic.com/v1/messages' },
'anthropic/claude-3-sonnet-20240229': { displayName: 'Claude 3 Sonnet', url: 'https://api.anthropic.com/v1/messages' },
'anthropic/claude-3-opus-20240229': { displayName: 'Claude 3 Opus', url: 'https://api.anthropic.com/v1/messages' },
'anthropic/claude-2.1': { displayName: 'Claude 2.1' },
'anthropic/claude-instant-1.2': { displayName: 'Claude Instant' },
'ai21/jamba-large': { displayName: 'Jamba Large', enabled: false },
'ai21/jamba-mini': { displayName: 'Jamba Mini', enabled: false },
'ai21/j2-ultra': { displayName: 'Jurassic-2 Ultra', enabled: false },
'ai21/j2-mid': { displayName: 'Jurassic-2 Mid', enabled: false },
'ai21/j2-light': { displayName: 'Jurassic-2 Light', enabled: false },
'xai/grok-4-0709': { displayName: 'Grok 4' },
'xai/grok-3-beta': { displayName: 'Grok 3' },
'xai/grok-3-mini-beta': { displayName: 'Grok 3 Mini' },
'xai/grok-3-fast-beta': { displayName: 'Grok 3 Fast' },
'xai/grok-3-mini-fast-beta': { displayName: 'Grok 3 Mini Fast' },
'xai/grok-2-image-1212': { displayName: 'Grok 2 Image Gen', imageGen: true },
'xai/grok-2-vision-1212': { displayName: 'Grok 2 Vision' },
'xai/grok-2-1212': { displayName: 'Grok 2' },
'xai/grok-vision-beta': { displayName: 'Grok Vision' },
'xai/grok-beta': { displayName: 'Grok Beta' },
'deepseek/deepseek-chat': { displayName: 'Deepseek V3 - Chat' },
'deepseek/deepseek-reasoner': { displayName: 'Deepseek R1 - Reasoner' },
'openai/gpt-oss-120b': { displayName: 'GPT OSS 120B' },
'openai/gpt-oss-20b': { displayName: 'GPT OSS 20B' },
'groq/moonshotai/kimi-k2-instruct': { displayName: 'kimi-k2-instruct' },
'groq/mistral-saba-24b': { displayName: 'mistral-saba-24b' },
'groq/meta-llama/llama-4-scout-17b-16e-instruct': { displayName: 'Llama 4 Scout', imageInput: true },
'groq/meta-llama/llama-4-maverick-17b-128e-instruct': { displayName: 'Llama 4 Maverick', imageInput: true },
'groq/qwen-qwq-32b': { displayName: 'QwQ-32B', reasoning: true },
'groq/deepseek-r1-distill-llama-70b': { displayName: 'DeepSeek R1 70b (llama)', reasoning: true },
'groq/deepseek-r1-distill-qwen-32b': { displayName: 'DeepSeek R1 32b (qwen)', reasoning: true, enabled: false },
'groq/deepseek-r1-distill-llama-70b-specdec': { displayName: 'DeepSeek R1 70b (llama, specdec)', reasoning: true, enabled: false },
'groq/llama-3.3-70b-versatile': { displayName: 'Llama 3.3 70b Versatile' },
'groq/llama-3.2-90b-vision-preview': { displayName: 'Llama 3.2 90b Vision preview', enabled: false },
'groq/llama-3.3-70b-specdec': { displayName: 'Llama 3.3 70B (SpecDec)', enabled: false },
'groq/llama-3.2-11b-vision-preview': { displayName: 'Llama 3.2 11B Vision Preview', enabled: false },
'groq/llama-3.2-3b-preview': { displayName: 'Llama 3.2 3B Preview', enabled: false },
'groq/llama-3.2-1b-preview': { displayName: 'Llama 3.2 1B Preview', enabled: false },
'groq/llama-3.1-8b-instant': { displayName: 'Llama 3.1 8B' },
'groq/llama3-70b-8192': { displayName: 'LLaMA3 70b' },
'groq/llama3-8b-8192': { displayName: 'LLaMA3 8b' },
'groq/llama-guard-3-8b': { displayName: 'Llama 3 Guard 8b' },
'groq/gemma2-9b-it': { displayName: 'Gemma 2 9b' },
'groq/qwen-2.5-coder-32b': { displayName: 'QwQ-2.5 coder 32b', enabled: false },
'groq/qwen-2.5-32b': { displayName: 'QWEN 2.5 32b', enabled: false },
'groq/mixtral-8x7b-32768': { displayName: 'Mixtral-8x7b' },
'groq/llama-3.1-405b-reasoning': { displayName: 'Llama 3.1 405B', enabled: false },
'groq/llama-3.1-70b-versatile': { displayName: 'Llama 3.1 70B', enabled: false },
'groq/llama2-70b-4096': { displayName: 'LLaMA2 70b', enabled: false },
'groq/gemma-7b-it': { displayName: 'Gemma 7B 8K', enabled: false },
'openrouter/qwen/qwen3-coder': { displayName: 'Qwen: Qwen3 Coder' },
'openrouter/qwen/qwen3-235b-a22b-07-25': { displayName: 'Qwen: Qwen3 235B A22B 2507' },
'openrouter/openrouter/optimus-alpha': { displayName: 'Optimus Alpha' },
'openrouter/openrouter/quasar-alpha': { displayName: 'Quasar Alpha', enabled: false },
'openrouter/qwen/qwq-32b': { displayName: 'Qwen: QwQ-32B' },
'openrouter/qwen/qwen-max': { displayName: 'Qwen: Qwen-Max' },
'openrouter/deepseek/deepseek-r1': { displayName: 'DeepSeek: R1 (671B)' },
'openrouter/deepseek/deepseek-chat': { displayName: 'DeepSeek V3' },
'openrouter/meta-llama/llama-3.3-70b-instruct': { displayName: 'Llama 3.3 70B Instruct' },
'openrouter/meta-llama/llama-3.2-90b-vision-instruct': { displayName: 'Llama 3.2 90B Vision model' },
'openrouter/meta-llama/llama-3.2-11b-vision-instruct': { displayName: 'Llama 3.2 11B Vision model' },
'openrouter/mattshumer/reflection-70b': { displayName: 'Reflection 70B' },
'openrouter/meta-llama/llama-3.1-405b-instruct': { displayName: 'Meta: Llama 3.1 405B Instruct' },
'openrouter/meta-llama/llama-3-70b-instruct': { displayName: 'Meta: Llama 3 70B Instruct' },
'openrouter/meta-llama/llama-3-8b-instruct': { displayName: 'Meta: Llama 3 8B Instruct' },
'openrouter/openchat/openchat-7b:free': { displayName: 'Openchat-7b' },
'openrouter/huggingfaceh4/zephyr-7b-beta:free': { displayName: 'HuggingFace: Zephyr 7B' },
'openrouter/openrouter/cinematika-7b:free': { displayName: 'Cinematika 7B' },
'openrouter/mistralai/mistral-7b-instruct:free': { displayName: 'Mistral 7B Instruct' },
'openrouter/nousresearch/nous-capybara-7b:free': { displayName: 'Nous: Capybara 7B' },
'openrouter/google/gemma-7b-it:free': { displayName: 'Google: Gemma 7B' },
'openrouter/mistralai/mixtral-8x7b-instruct': { displayName: 'Mixtral-8x7b-instruct' },
'openrouter/snowflake/snowflake-arctic-instruct': { displayName: 'Snowflake: Arctic Instruct' },
'openrouter/perplexity/sonar-medium-chat': { displayName: 'Perplexity: Sonar 8x7B' },
'openrouter/perplexity/sonar-medium-online': { displayName: 'Perplexity: Sonar 8x7B Online' },
'mistral/devstral-small-2505': { displayName: 'Devstral Small - free' },
'mistral/codestral-latest': { displayName: 'Codestral' },
'mistral/pixtral-large-latest': { displayName: 'Pixtral Large', imageInput: true },
'mistral/pixtral-12b-2409': { displayName: 'Pixtral - free', imageInput: true },
'mistral/mistral-medium-latest': { displayName: 'Mistral Medium 3' },
'mistral/mistral-saba-latest': { displayName: 'Mistral Saba' },
'mistral/ministral-3b-latest': { displayName: 'Ministral 3B' },
'mistral/ministral-8b-latest': { displayName: 'Ministral 8B' },
'mistral/mistral-small-latest': { displayName: 'Mistral Small - latest - free' },
'mistral/mistral-large-2407': { displayName: 'Mistral Large 2' },
'mistral/mistral-large-latest': { displayName: 'Mistral Large' },
'mistral/open-mistral-7b': { displayName: 'Open Mistral 7b' },
'mistral/open-mixtral-8x7b': { displayName: 'Open Mixtral 8x7b' },
'mistral/mistral-tiny': { displayName: 'Mistral Tiny' },
'mistral/mistral-small': { displayName: 'Mistral Small (old)' },
'mistral/mistral-medium': { displayName: 'Mistral Medium' },
'cohere/command-r': { displayName: 'Command-R' },
'cohere/command-r-plus': { displayName: 'Command-R-Plus' },
'cohere/command-light': { displayName: 'Command Light' },
'cohere/c4ai-aya-23': { displayName: 'Aya 23' },
'cloudflare/@cf/deepseek-ai/deepseek-r1-distill-qwen-32b': { displayName: 'deepseek-r1-distill-qwen-32b' },
'cloudflare/@cf/meta/llama-2-7b-chat-fp16': { displayName: 'llama-2-7b-chat' },
'cloudflare/@hf/meta-llama/meta-llama-3-8b-instruct': { displayName: 'llama-3-8b-instruct' },
'cloudflare/@cf/tinyllama/tinyllama-1.1b-chat-v1.0': { displayName: 'tinyllama-1.1b-chat-v1.0' },
};
function getProviderFromModel(model) {
const parts = model.split('/');
return parts.length > 1 ? parts[0] : null;
}
function getModelInfo(model) {
return exports.supportedModels[model];
}
function listModels(provider) {
const models = Object.keys(exports.supportedModels);
if (!provider) {
return models;
}
return models.filter((m) => m.startsWith(`${provider}/`));
}
function isModelSupported(model) {
return model in exports.supportedModels;
}
function resolveModel(modelInput) {
var _a;
if (!modelInput)
return modelInput;
const models = exports.supportedModels;
const searchTerm = modelInput.toLowerCase().trim();
if (models[modelInput]) {
return modelInput;
}
for (const [key] of Object.entries(models)) {
if (key.toLowerCase() === searchTerm) {
return key;
}
}
const matches = [];
const normalize = (str) => str.replace(/[-_.]/g, '').toLowerCase();
const normalizedSearchTerm = normalize(searchTerm);
for (const [key, model] of Object.entries(models)) {
if ('enabled' in model && model.enabled === false)
continue;
const keyLower = key.toLowerCase();
const displayNameLower = (model.displayName || '').toLowerCase();
const modelPart = ((_a = key.split('/').pop()) === null || _a === void 0 ? void 0 : _a.toLowerCase()) || '';
const normalizedModelPart = normalize(modelPart);
const normalizedDisplayName = normalize(displayNameLower);
let score = 0;
if (modelPart === searchTerm || normalizedModelPart === normalizedSearchTerm) {
score = 1000;
}
else if (displayNameLower === searchTerm || normalizedDisplayName === normalizedSearchTerm) {
score = 900;
}
else if (modelPart.startsWith(searchTerm) || normalizedModelPart.startsWith(normalizedSearchTerm)) {
score = 800;
}
else if (displayNameLower.startsWith(searchTerm) || normalizedDisplayName.startsWith(normalizedSearchTerm)) {
score = 700;
}
else if (modelPart.includes(searchTerm) || normalizedModelPart.includes(normalizedSearchTerm)) {
score = 600;
}
else if (displayNameLower.includes(searchTerm) || normalizedDisplayName.includes(normalizedSearchTerm)) {
score = 500;
}
else if (keyLower.includes(searchTerm)) {
score = 400;
}
if (score > 0) {
matches.push({ key, score });
}
}
if (matches.length > 0) {
matches.sort((a, b) => b.score - a.score);
return matches[0].key;
}
return modelInput;
}
//# sourceMappingURL=models.js.map