2024-12-02 20:43:33 +00:00
|
|
|
import Cookies from 'js-cookie';
|
2024-11-14 13:37:41 +00:00
|
|
|
import type { ModelInfo, OllamaApiResponse, OllamaModel } from './types';
|
2024-12-11 08:32:21 +00:00
|
|
|
import type { ProviderInfo, IProviderSetting } from '~/types/model';
|
2024-12-10 17:39:59 +00:00
|
|
|
import { createScopedLogger } from './logger';
|
2024-12-13 00:11:35 +00:00
|
|
|
import { logStore } from '~/lib/stores/logs';
|
2024-10-18 11:34:08 +00:00
|
|
|
|
2024-07-18 21:07:04 +00:00
|
|
|
export const WORK_DIR_NAME = 'project';
|
|
|
|
export const WORK_DIR = `/home/${WORK_DIR_NAME}`;
|
2024-07-25 15:28:23 +00:00
|
|
|
export const MODIFICATIONS_TAG_NAME = 'bolt_file_modifications';
|
2024-10-13 18:53:43 +00:00
|
|
|
export const MODEL_REGEX = /^\[Model: (.*?)\]\n\n/;
|
2024-11-06 20:35:54 +00:00
|
|
|
export const PROVIDER_REGEX = /\[Provider: (.*?)\]\n\n/;
|
2024-11-07 13:38:22 +00:00
|
|
|
export const DEFAULT_MODEL = 'claude-3-5-sonnet-latest';
|
2024-11-26 18:47:00 +00:00
|
|
|
export const PROMPT_COOKIE_KEY = 'cachedPrompt';
|
2024-11-12 09:25:58 +00:00
|
|
|
|
2024-12-10 17:39:59 +00:00
|
|
|
const logger = createScopedLogger('Constants');
|
|
|
|
|
2024-11-11 21:47:12 +00:00
|
|
|
const PROVIDER_LIST: ProviderInfo[] = [
|
2024-11-12 09:25:58 +00:00
|
|
|
{
|
|
|
|
name: 'Anthropic',
|
|
|
|
staticModels: [
|
2024-11-21 21:05:35 +00:00
|
|
|
{
|
|
|
|
name: 'claude-3-5-sonnet-latest',
|
|
|
|
label: 'Claude 3.5 Sonnet (new)',
|
|
|
|
provider: 'Anthropic',
|
|
|
|
maxTokenAllowed: 8000,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'claude-3-5-sonnet-20240620',
|
|
|
|
label: 'Claude 3.5 Sonnet (old)',
|
|
|
|
provider: 'Anthropic',
|
|
|
|
maxTokenAllowed: 8000,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'claude-3-5-haiku-latest',
|
|
|
|
label: 'Claude 3.5 Haiku (new)',
|
|
|
|
provider: 'Anthropic',
|
|
|
|
maxTokenAllowed: 8000,
|
|
|
|
},
|
2024-11-20 16:11:51 +00:00
|
|
|
{ name: 'claude-3-opus-latest', label: 'Claude 3 Opus', provider: 'Anthropic', maxTokenAllowed: 8000 },
|
|
|
|
{ name: 'claude-3-sonnet-20240229', label: 'Claude 3 Sonnet', provider: 'Anthropic', maxTokenAllowed: 8000 },
|
2024-11-21 21:05:35 +00:00
|
|
|
{ name: 'claude-3-haiku-20240307', label: 'Claude 3 Haiku', provider: 'Anthropic', maxTokenAllowed: 8000 },
|
2024-11-12 09:25:58 +00:00
|
|
|
],
|
2024-11-21 21:05:35 +00:00
|
|
|
getApiKeyLink: 'https://console.anthropic.com/settings/keys',
|
2024-11-12 09:25:58 +00:00
|
|
|
},
|
2024-11-11 21:47:12 +00:00
|
|
|
{
|
|
|
|
name: 'Ollama',
|
|
|
|
staticModels: [],
|
2024-11-12 09:25:58 +00:00
|
|
|
getDynamicModels: getOllamaModels,
|
2024-11-21 21:05:35 +00:00
|
|
|
getApiKeyLink: 'https://ollama.com/download',
|
|
|
|
labelForGetApiKey: 'Download Ollama',
|
|
|
|
icon: 'i-ph:cloud-arrow-down',
|
|
|
|
},
|
|
|
|
{
|
2024-11-11 21:47:12 +00:00
|
|
|
name: 'OpenAILike',
|
|
|
|
staticModels: [],
|
2024-11-21 21:05:35 +00:00
|
|
|
getDynamicModels: getOpenAILikeModels,
|
2024-11-11 21:47:12 +00:00
|
|
|
},
|
2024-11-20 15:08:42 +00:00
|
|
|
{
|
|
|
|
name: 'Cohere',
|
|
|
|
staticModels: [
|
2024-11-20 16:11:51 +00:00
|
|
|
{ name: 'command-r-plus-08-2024', label: 'Command R plus Latest', provider: 'Cohere', maxTokenAllowed: 4096 },
|
|
|
|
{ name: 'command-r-08-2024', label: 'Command R Latest', provider: 'Cohere', maxTokenAllowed: 4096 },
|
|
|
|
{ name: 'command-r-plus', label: 'Command R plus', provider: 'Cohere', maxTokenAllowed: 4096 },
|
|
|
|
{ name: 'command-r', label: 'Command R', provider: 'Cohere', maxTokenAllowed: 4096 },
|
|
|
|
{ name: 'command', label: 'Command', provider: 'Cohere', maxTokenAllowed: 4096 },
|
|
|
|
{ name: 'command-nightly', label: 'Command Nightly', provider: 'Cohere', maxTokenAllowed: 4096 },
|
|
|
|
{ name: 'command-light', label: 'Command Light', provider: 'Cohere', maxTokenAllowed: 4096 },
|
|
|
|
{ name: 'command-light-nightly', label: 'Command Light Nightly', provider: 'Cohere', maxTokenAllowed: 4096 },
|
|
|
|
{ name: 'c4ai-aya-expanse-8b', label: 'c4AI Aya Expanse 8b', provider: 'Cohere', maxTokenAllowed: 4096 },
|
|
|
|
{ name: 'c4ai-aya-expanse-32b', label: 'c4AI Aya Expanse 32b', provider: 'Cohere', maxTokenAllowed: 4096 },
|
2024-11-20 15:08:42 +00:00
|
|
|
],
|
2024-11-21 21:05:35 +00:00
|
|
|
getApiKeyLink: 'https://dashboard.cohere.com/api-keys',
|
2024-11-20 15:08:42 +00:00
|
|
|
},
|
2024-11-11 21:47:12 +00:00
|
|
|
{
|
|
|
|
name: 'OpenRouter',
|
|
|
|
staticModels: [
|
2024-11-20 16:11:51 +00:00
|
|
|
{ name: 'gpt-4o', label: 'GPT-4o', provider: 'OpenAI', maxTokenAllowed: 8000 },
|
2024-11-11 21:47:12 +00:00
|
|
|
{
|
|
|
|
name: 'anthropic/claude-3.5-sonnet',
|
|
|
|
label: 'Anthropic: Claude 3.5 Sonnet (OpenRouter)',
|
2024-11-21 21:05:35 +00:00
|
|
|
provider: 'OpenRouter',
|
|
|
|
maxTokenAllowed: 8000,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'anthropic/claude-3-haiku',
|
|
|
|
label: 'Anthropic: Claude 3 Haiku (OpenRouter)',
|
|
|
|
provider: 'OpenRouter',
|
|
|
|
maxTokenAllowed: 8000,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'deepseek/deepseek-coder',
|
|
|
|
label: 'Deepseek-Coder V2 236B (OpenRouter)',
|
|
|
|
provider: 'OpenRouter',
|
|
|
|
maxTokenAllowed: 8000,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'google/gemini-flash-1.5',
|
|
|
|
label: 'Google Gemini Flash 1.5 (OpenRouter)',
|
|
|
|
provider: 'OpenRouter',
|
|
|
|
maxTokenAllowed: 8000,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'google/gemini-pro-1.5',
|
|
|
|
label: 'Google Gemini Pro 1.5 (OpenRouter)',
|
|
|
|
provider: 'OpenRouter',
|
|
|
|
maxTokenAllowed: 8000,
|
2024-11-11 21:47:12 +00:00
|
|
|
},
|
2024-11-20 16:11:51 +00:00
|
|
|
{ name: 'x-ai/grok-beta', label: 'xAI Grok Beta (OpenRouter)', provider: 'OpenRouter', maxTokenAllowed: 8000 },
|
2024-11-21 21:05:35 +00:00
|
|
|
{
|
|
|
|
name: 'mistralai/mistral-nemo',
|
|
|
|
label: 'OpenRouter Mistral Nemo (OpenRouter)',
|
|
|
|
provider: 'OpenRouter',
|
|
|
|
maxTokenAllowed: 8000,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'qwen/qwen-110b-chat',
|
|
|
|
label: 'OpenRouter Qwen 110b Chat (OpenRouter)',
|
|
|
|
provider: 'OpenRouter',
|
|
|
|
maxTokenAllowed: 8000,
|
|
|
|
},
|
|
|
|
{ name: 'cohere/command', label: 'Cohere Command (OpenRouter)', provider: 'OpenRouter', maxTokenAllowed: 4096 },
|
2024-11-11 21:47:12 +00:00
|
|
|
],
|
2024-11-13 20:21:50 +00:00
|
|
|
getDynamicModels: getOpenRouterModels,
|
|
|
|
getApiKeyLink: 'https://openrouter.ai/settings/keys',
|
2024-11-21 21:05:35 +00:00
|
|
|
},
|
|
|
|
{
|
2024-11-11 21:47:12 +00:00
|
|
|
name: 'Google',
|
|
|
|
staticModels: [
|
2024-11-20 16:11:51 +00:00
|
|
|
{ name: 'gemini-1.5-flash-latest', label: 'Gemini 1.5 Flash', provider: 'Google', maxTokenAllowed: 8192 },
|
2024-12-11 19:03:45 +00:00
|
|
|
{ name: 'gemini-2.0-flash-exp', label: 'Gemini 2.0 Flash', provider: 'Google', maxTokenAllowed: 8192 },
|
2024-11-20 16:11:51 +00:00
|
|
|
{ name: 'gemini-1.5-flash-002', label: 'Gemini 1.5 Flash-002', provider: 'Google', maxTokenAllowed: 8192 },
|
|
|
|
{ name: 'gemini-1.5-flash-8b', label: 'Gemini 1.5 Flash-8b', provider: 'Google', maxTokenAllowed: 8192 },
|
|
|
|
{ name: 'gemini-1.5-pro-latest', label: 'Gemini 1.5 Pro', provider: 'Google', maxTokenAllowed: 8192 },
|
|
|
|
{ name: 'gemini-1.5-pro-002', label: 'Gemini 1.5 Pro-002', provider: 'Google', maxTokenAllowed: 8192 },
|
2024-12-06 19:34:14 +00:00
|
|
|
{ name: 'gemini-exp-1206', label: 'Gemini exp-1206', provider: 'Google', maxTokenAllowed: 8192 },
|
2024-11-11 21:47:12 +00:00
|
|
|
],
|
2024-11-21 21:05:35 +00:00
|
|
|
getApiKeyLink: 'https://aistudio.google.com/app/apikey',
|
|
|
|
},
|
|
|
|
{
|
2024-11-11 21:47:12 +00:00
|
|
|
name: 'Groq',
|
|
|
|
staticModels: [
|
2024-11-20 16:11:51 +00:00
|
|
|
{ name: 'llama-3.1-8b-instant', label: 'Llama 3.1 8b (Groq)', provider: 'Groq', maxTokenAllowed: 8000 },
|
|
|
|
{ name: 'llama-3.2-11b-vision-preview', label: 'Llama 3.2 11b (Groq)', provider: 'Groq', maxTokenAllowed: 8000 },
|
2024-12-06 16:08:19 +00:00
|
|
|
{ name: 'llama-3.2-90b-vision-preview', label: 'Llama 3.2 90b (Groq)', provider: 'Groq', maxTokenAllowed: 8000 },
|
2024-11-20 16:11:51 +00:00
|
|
|
{ name: 'llama-3.2-3b-preview', label: 'Llama 3.2 3b (Groq)', provider: 'Groq', maxTokenAllowed: 8000 },
|
2024-11-21 21:05:35 +00:00
|
|
|
{ name: 'llama-3.2-1b-preview', label: 'Llama 3.2 1b (Groq)', provider: 'Groq', maxTokenAllowed: 8000 },
|
2024-12-13 19:48:02 +00:00
|
|
|
{ name: 'llama-3.3-70b-versatile', label: 'Llama 3.3 70b (Groq)', provider: 'Groq', maxTokenAllowed: 8000 },
|
2024-11-11 21:47:12 +00:00
|
|
|
],
|
2024-11-21 21:05:35 +00:00
|
|
|
getApiKeyLink: 'https://console.groq.com/keys',
|
2024-11-17 23:49:02 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'HuggingFace',
|
|
|
|
staticModels: [
|
2024-11-21 21:05:35 +00:00
|
|
|
{
|
|
|
|
name: 'Qwen/Qwen2.5-Coder-32B-Instruct',
|
|
|
|
label: 'Qwen2.5-Coder-32B-Instruct (HuggingFace)',
|
|
|
|
provider: 'HuggingFace',
|
|
|
|
maxTokenAllowed: 8000,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: '01-ai/Yi-1.5-34B-Chat',
|
|
|
|
label: 'Yi-1.5-34B-Chat (HuggingFace)',
|
|
|
|
provider: 'HuggingFace',
|
|
|
|
maxTokenAllowed: 8000,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'codellama/CodeLlama-34b-Instruct-hf',
|
|
|
|
label: 'CodeLlama-34b-Instruct (HuggingFace)',
|
|
|
|
provider: 'HuggingFace',
|
|
|
|
maxTokenAllowed: 8000,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'NousResearch/Hermes-3-Llama-3.1-8B',
|
|
|
|
label: 'Hermes-3-Llama-3.1-8B (HuggingFace)',
|
2024-11-22 19:38:58 +00:00
|
|
|
provider: 'HuggingFace',
|
|
|
|
maxTokenAllowed: 8000,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Qwen/Qwen2.5-Coder-32B-Instruct',
|
|
|
|
label: 'Qwen2.5-Coder-32B-Instruct (HuggingFace)',
|
|
|
|
provider: 'HuggingFace',
|
|
|
|
maxTokenAllowed: 8000,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Qwen/Qwen2.5-72B-Instruct',
|
|
|
|
label: 'Qwen2.5-72B-Instruct (HuggingFace)',
|
|
|
|
provider: 'HuggingFace',
|
|
|
|
maxTokenAllowed: 8000,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'meta-llama/Llama-3.1-70B-Instruct',
|
|
|
|
label: 'Llama-3.1-70B-Instruct (HuggingFace)',
|
|
|
|
provider: 'HuggingFace',
|
|
|
|
maxTokenAllowed: 8000,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'meta-llama/Llama-3.1-405B',
|
|
|
|
label: 'Llama-3.1-405B (HuggingFace)',
|
|
|
|
provider: 'HuggingFace',
|
|
|
|
maxTokenAllowed: 8000,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: '01-ai/Yi-1.5-34B-Chat',
|
|
|
|
label: 'Yi-1.5-34B-Chat (HuggingFace)',
|
|
|
|
provider: 'HuggingFace',
|
|
|
|
maxTokenAllowed: 8000,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'codellama/CodeLlama-34b-Instruct-hf',
|
|
|
|
label: 'CodeLlama-34b-Instruct (HuggingFace)',
|
|
|
|
provider: 'HuggingFace',
|
|
|
|
maxTokenAllowed: 8000,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'NousResearch/Hermes-3-Llama-3.1-8B',
|
|
|
|
label: 'Hermes-3-Llama-3.1-8B (HuggingFace)',
|
2024-11-21 21:05:35 +00:00
|
|
|
provider: 'HuggingFace',
|
|
|
|
maxTokenAllowed: 8000,
|
|
|
|
},
|
2024-11-17 23:49:02 +00:00
|
|
|
],
|
2024-11-21 21:05:35 +00:00
|
|
|
getApiKeyLink: 'https://huggingface.co/settings/tokens',
|
2024-11-17 23:49:02 +00:00
|
|
|
},
|
2024-11-20 16:11:51 +00:00
|
|
|
|
2024-11-17 23:49:02 +00:00
|
|
|
{
|
2024-11-11 21:47:12 +00:00
|
|
|
name: 'OpenAI',
|
|
|
|
staticModels: [
|
2024-11-20 16:11:51 +00:00
|
|
|
{ name: 'gpt-4o-mini', label: 'GPT-4o Mini', provider: 'OpenAI', maxTokenAllowed: 8000 },
|
|
|
|
{ name: 'gpt-4-turbo', label: 'GPT-4 Turbo', provider: 'OpenAI', maxTokenAllowed: 8000 },
|
|
|
|
{ name: 'gpt-4', label: 'GPT-4', provider: 'OpenAI', maxTokenAllowed: 8000 },
|
2024-11-21 21:05:35 +00:00
|
|
|
{ name: 'gpt-3.5-turbo', label: 'GPT-3.5 Turbo', provider: 'OpenAI', maxTokenAllowed: 8000 },
|
2024-11-11 21:47:12 +00:00
|
|
|
],
|
2024-11-21 21:05:35 +00:00
|
|
|
getApiKeyLink: 'https://platform.openai.com/api-keys',
|
|
|
|
},
|
|
|
|
{
|
2024-11-11 21:47:12 +00:00
|
|
|
name: 'xAI',
|
2024-11-21 21:05:35 +00:00
|
|
|
staticModels: [{ name: 'grok-beta', label: 'xAI Grok Beta', provider: 'xAI', maxTokenAllowed: 8000 }],
|
|
|
|
getApiKeyLink: 'https://docs.x.ai/docs/quickstart#creating-an-api-key',
|
|
|
|
},
|
|
|
|
{
|
2024-11-11 21:47:12 +00:00
|
|
|
name: 'Deepseek',
|
|
|
|
staticModels: [
|
2024-11-20 16:11:51 +00:00
|
|
|
{ name: 'deepseek-coder', label: 'Deepseek-Coder', provider: 'Deepseek', maxTokenAllowed: 8000 },
|
2024-11-21 21:05:35 +00:00
|
|
|
{ name: 'deepseek-chat', label: 'Deepseek-Chat', provider: 'Deepseek', maxTokenAllowed: 8000 },
|
2024-11-11 21:47:12 +00:00
|
|
|
],
|
2024-11-21 21:27:29 +00:00
|
|
|
getApiKeyLink: 'https://platform.deepseek.com/apiKeys',
|
2024-11-21 21:05:35 +00:00
|
|
|
},
|
|
|
|
{
|
2024-11-11 21:47:12 +00:00
|
|
|
name: 'Mistral',
|
|
|
|
staticModels: [
|
2024-11-20 16:11:51 +00:00
|
|
|
{ name: 'open-mistral-7b', label: 'Mistral 7B', provider: 'Mistral', maxTokenAllowed: 8000 },
|
|
|
|
{ name: 'open-mixtral-8x7b', label: 'Mistral 8x7B', provider: 'Mistral', maxTokenAllowed: 8000 },
|
|
|
|
{ name: 'open-mixtral-8x22b', label: 'Mistral 8x22B', provider: 'Mistral', maxTokenAllowed: 8000 },
|
|
|
|
{ name: 'open-codestral-mamba', label: 'Codestral Mamba', provider: 'Mistral', maxTokenAllowed: 8000 },
|
|
|
|
{ name: 'open-mistral-nemo', label: 'Mistral Nemo', provider: 'Mistral', maxTokenAllowed: 8000 },
|
|
|
|
{ name: 'ministral-8b-latest', label: 'Mistral 8B', provider: 'Mistral', maxTokenAllowed: 8000 },
|
|
|
|
{ name: 'mistral-small-latest', label: 'Mistral Small', provider: 'Mistral', maxTokenAllowed: 8000 },
|
|
|
|
{ name: 'codestral-latest', label: 'Codestral', provider: 'Mistral', maxTokenAllowed: 8000 },
|
2024-11-21 21:05:35 +00:00
|
|
|
{ name: 'mistral-large-latest', label: 'Mistral Large Latest', provider: 'Mistral', maxTokenAllowed: 8000 },
|
2024-11-11 21:47:12 +00:00
|
|
|
],
|
2024-11-21 21:05:35 +00:00
|
|
|
getApiKeyLink: 'https://console.mistral.ai/api-keys/',
|
|
|
|
},
|
|
|
|
{
|
2024-11-11 21:47:12 +00:00
|
|
|
name: 'LMStudio',
|
|
|
|
staticModels: [],
|
|
|
|
getDynamicModels: getLMStudioModels,
|
|
|
|
getApiKeyLink: 'https://lmstudio.ai/',
|
2024-11-12 09:25:58 +00:00
|
|
|
labelForGetApiKey: 'Get LMStudio',
|
2024-11-21 21:05:35 +00:00
|
|
|
icon: 'i-ph:cloud-arrow-down',
|
|
|
|
},
|
2024-11-23 05:20:35 +00:00
|
|
|
{
|
|
|
|
name: 'Together',
|
2024-12-06 11:28:04 +00:00
|
|
|
getDynamicModels: getTogetherModels,
|
2024-11-23 05:20:35 +00:00
|
|
|
staticModels: [
|
2024-12-01 20:17:02 +00:00
|
|
|
{
|
|
|
|
name: 'Qwen/Qwen2.5-Coder-32B-Instruct',
|
|
|
|
label: 'Qwen/Qwen2.5-Coder-32B-Instruct',
|
|
|
|
provider: 'Together',
|
|
|
|
maxTokenAllowed: 8000,
|
|
|
|
},
|
2024-11-23 05:20:35 +00:00
|
|
|
{
|
|
|
|
name: 'meta-llama/Llama-3.2-90B-Vision-Instruct-Turbo',
|
|
|
|
label: 'meta-llama/Llama-3.2-90B-Vision-Instruct-Turbo',
|
|
|
|
provider: 'Together',
|
|
|
|
maxTokenAllowed: 8000,
|
|
|
|
},
|
|
|
|
|
2024-12-01 20:17:02 +00:00
|
|
|
{
|
|
|
|
name: 'mistralai/Mixtral-8x7B-Instruct-v0.1',
|
|
|
|
label: 'Mixtral 8x7B Instruct',
|
|
|
|
provider: 'Together',
|
|
|
|
maxTokenAllowed: 8192,
|
|
|
|
},
|
2024-11-23 05:20:35 +00:00
|
|
|
],
|
|
|
|
getApiKeyLink: 'https://api.together.xyz/settings/api-keys',
|
|
|
|
},
|
2024-10-18 11:34:08 +00:00
|
|
|
];
|
|
|
|
|
2024-11-12 09:25:58 +00:00
|
|
|
export const DEFAULT_PROVIDER = PROVIDER_LIST[0];
|
2024-11-11 21:47:12 +00:00
|
|
|
|
2024-11-21 21:05:35 +00:00
|
|
|
const staticModels: ModelInfo[] = PROVIDER_LIST.map((p) => p.staticModels).flat();
|
2024-11-11 21:47:12 +00:00
|
|
|
|
2024-10-18 11:34:08 +00:00
|
|
|
export let MODEL_LIST: ModelInfo[] = [...staticModels];
|
|
|
|
|
2024-12-11 08:32:21 +00:00
|
|
|
export async function getModelList(
|
|
|
|
apiKeys: Record<string, string>,
|
|
|
|
providerSettings?: Record<string, IProviderSetting>,
|
|
|
|
) {
|
2024-12-02 20:43:33 +00:00
|
|
|
MODEL_LIST = [
|
|
|
|
...(
|
|
|
|
await Promise.all(
|
|
|
|
PROVIDER_LIST.filter(
|
|
|
|
(p): p is ProviderInfo & { getDynamicModels: () => Promise<ModelInfo[]> } => !!p.getDynamicModels,
|
2024-12-11 08:32:21 +00:00
|
|
|
).map((p) => p.getDynamicModels(apiKeys, providerSettings?.[p.name])),
|
2024-12-02 20:43:33 +00:00
|
|
|
)
|
|
|
|
).flat(),
|
|
|
|
...staticModels,
|
|
|
|
];
|
|
|
|
return MODEL_LIST;
|
|
|
|
}
|
|
|
|
|
2024-12-11 08:32:21 +00:00
|
|
|
async function getTogetherModels(apiKeys?: Record<string, string>, settings?: IProviderSetting): Promise<ModelInfo[]> {
|
2024-12-02 20:43:33 +00:00
|
|
|
try {
|
2024-12-11 08:32:21 +00:00
|
|
|
const baseUrl = settings?.baseUrl || import.meta.env.TOGETHER_API_BASE_URL || '';
|
2024-12-06 11:28:04 +00:00
|
|
|
const provider = 'Together';
|
2024-12-02 20:43:33 +00:00
|
|
|
|
2024-12-06 11:28:04 +00:00
|
|
|
if (!baseUrl) {
|
|
|
|
return [];
|
|
|
|
}
|
2024-12-02 20:43:33 +00:00
|
|
|
|
2024-12-06 11:28:04 +00:00
|
|
|
let apiKey = import.meta.env.OPENAI_LIKE_API_KEY ?? '';
|
|
|
|
|
|
|
|
if (apiKeys && apiKeys[provider]) {
|
|
|
|
apiKey = apiKeys[provider];
|
|
|
|
}
|
2024-12-02 20:43:33 +00:00
|
|
|
|
2024-12-06 11:28:04 +00:00
|
|
|
if (!apiKey) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
const response = await fetch(`${baseUrl}/models`, {
|
|
|
|
headers: {
|
|
|
|
Authorization: `Bearer ${apiKey}`,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
const res = (await response.json()) as any;
|
|
|
|
const data: any[] = (res || []).filter((model: any) => model.type == 'chat');
|
|
|
|
|
|
|
|
return data.map((m: any) => ({
|
|
|
|
name: m.id,
|
|
|
|
label: `${m.display_name} - in:$${m.pricing.input.toFixed(
|
|
|
|
2,
|
|
|
|
)} out:$${m.pricing.output.toFixed(2)} - context ${Math.floor(m.context_length / 1000)}k`,
|
|
|
|
provider,
|
|
|
|
maxTokenAllowed: 8000,
|
|
|
|
}));
|
|
|
|
} catch (e) {
|
|
|
|
console.error('Error getting OpenAILike models:', e);
|
2024-12-02 20:43:33 +00:00
|
|
|
return [];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-12-11 08:32:21 +00:00
|
|
|
const getOllamaBaseUrl = (settings?: IProviderSetting) => {
|
|
|
|
const defaultBaseUrl = settings?.baseUrl || import.meta.env.OLLAMA_API_BASE_URL || 'http://localhost:11434';
|
2024-11-21 21:05:35 +00:00
|
|
|
|
2024-11-05 15:42:49 +00:00
|
|
|
// Check if we're in the browser
|
|
|
|
if (typeof window !== 'undefined') {
|
|
|
|
// Frontend always uses localhost
|
|
|
|
return defaultBaseUrl;
|
|
|
|
}
|
2024-11-06 20:35:54 +00:00
|
|
|
|
2024-11-05 15:42:49 +00:00
|
|
|
// Backend: Check if we're running in Docker
|
|
|
|
const isDocker = process.env.RUNNING_IN_DOCKER === 'true';
|
2024-11-06 20:35:54 +00:00
|
|
|
|
2024-11-21 21:05:35 +00:00
|
|
|
return isDocker ? defaultBaseUrl.replace('localhost', 'host.docker.internal') : defaultBaseUrl;
|
2024-11-05 15:42:49 +00:00
|
|
|
};
|
|
|
|
|
2024-12-11 08:32:21 +00:00
|
|
|
async function getOllamaModels(apiKeys?: Record<string, string>, settings?: IProviderSetting): Promise<ModelInfo[]> {
|
2024-10-18 11:34:08 +00:00
|
|
|
try {
|
2024-12-11 08:32:21 +00:00
|
|
|
const baseUrl = getOllamaBaseUrl(settings);
|
2024-11-21 21:27:29 +00:00
|
|
|
const response = await fetch(`${baseUrl}/api/tags`);
|
2024-11-21 21:05:35 +00:00
|
|
|
const data = (await response.json()) as OllamaApiResponse;
|
2024-10-18 11:34:08 +00:00
|
|
|
|
2024-10-22 09:19:08 +00:00
|
|
|
return data.models.map((model: OllamaModel) => ({
|
2024-10-18 11:34:08 +00:00
|
|
|
name: model.name,
|
|
|
|
label: `${model.name} (${model.details.parameter_size})`,
|
2024-11-20 16:11:51 +00:00
|
|
|
provider: 'Ollama',
|
2024-11-21 21:05:35 +00:00
|
|
|
maxTokenAllowed: 8000,
|
2024-10-18 11:34:08 +00:00
|
|
|
}));
|
2024-12-10 17:39:59 +00:00
|
|
|
} catch (e: any) {
|
2024-12-13 00:11:35 +00:00
|
|
|
logStore.logError('Failed to get Ollama models', e, { baseUrl: settings?.baseUrl });
|
2024-12-10 17:39:59 +00:00
|
|
|
logger.warn('Failed to get Ollama models: ', e.message || '');
|
2024-12-13 00:11:35 +00:00
|
|
|
|
2024-10-18 11:34:08 +00:00
|
|
|
return [];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-12-11 08:32:21 +00:00
|
|
|
async function getOpenAILikeModels(
|
|
|
|
apiKeys?: Record<string, string>,
|
|
|
|
settings?: IProviderSetting,
|
|
|
|
): Promise<ModelInfo[]> {
|
2024-11-06 20:35:54 +00:00
|
|
|
try {
|
2024-12-11 08:32:21 +00:00
|
|
|
const baseUrl = settings?.baseUrl || import.meta.env.OPENAI_LIKE_API_BASE_URL || '';
|
2024-11-21 21:05:35 +00:00
|
|
|
|
2024-11-21 21:27:29 +00:00
|
|
|
if (!baseUrl) {
|
2024-10-23 15:36:12 +00:00
|
|
|
return [];
|
2024-11-06 20:35:54 +00:00
|
|
|
}
|
2024-12-06 11:28:04 +00:00
|
|
|
|
2024-12-11 08:32:21 +00:00
|
|
|
let apiKey = '';
|
2024-12-06 11:28:04 +00:00
|
|
|
|
2024-12-11 08:32:21 +00:00
|
|
|
if (apiKeys && apiKeys.OpenAILike) {
|
|
|
|
apiKey = apiKeys.OpenAILike;
|
2024-12-02 20:43:33 +00:00
|
|
|
}
|
2024-11-21 21:05:35 +00:00
|
|
|
|
2024-11-21 21:27:29 +00:00
|
|
|
const response = await fetch(`${baseUrl}/models`, {
|
2024-11-06 20:35:54 +00:00
|
|
|
headers: {
|
2024-11-21 21:27:29 +00:00
|
|
|
Authorization: `Bearer ${apiKey}`,
|
2024-11-21 21:05:35 +00:00
|
|
|
},
|
2024-11-06 20:35:54 +00:00
|
|
|
});
|
2024-11-21 21:05:35 +00:00
|
|
|
const res = (await response.json()) as any;
|
|
|
|
|
2024-10-23 15:36:12 +00:00
|
|
|
return res.data.map((model: any) => ({
|
|
|
|
name: model.id,
|
|
|
|
label: model.id,
|
2024-11-21 21:05:35 +00:00
|
|
|
provider: 'OpenAILike',
|
2024-10-23 15:36:12 +00:00
|
|
|
}));
|
2024-11-06 20:35:54 +00:00
|
|
|
} catch (e) {
|
2024-11-25 08:30:18 +00:00
|
|
|
console.error('Error getting OpenAILike models:', e);
|
2024-11-11 21:47:12 +00:00
|
|
|
return [];
|
2024-11-06 20:35:54 +00:00
|
|
|
}
|
2024-11-13 20:21:50 +00:00
|
|
|
}
|
2024-10-23 15:36:12 +00:00
|
|
|
|
2024-11-13 20:21:50 +00:00
|
|
|
type OpenRouterModelsResponse = {
|
|
|
|
data: {
|
|
|
|
name: string;
|
|
|
|
id: string;
|
|
|
|
context_length: number;
|
|
|
|
pricing: {
|
|
|
|
prompt: number;
|
|
|
|
completion: number;
|
2024-11-21 21:05:35 +00:00
|
|
|
};
|
|
|
|
}[];
|
2024-11-13 20:21:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
async function getOpenRouterModels(): Promise<ModelInfo[]> {
|
2024-11-21 21:05:35 +00:00
|
|
|
const data: OpenRouterModelsResponse = await (
|
|
|
|
await fetch('https://openrouter.ai/api/v1/models', {
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
},
|
|
|
|
})
|
|
|
|
).json();
|
2024-11-13 20:21:50 +00:00
|
|
|
|
2024-11-21 21:05:35 +00:00
|
|
|
return data.data
|
|
|
|
.sort((a, b) => a.name.localeCompare(b.name))
|
|
|
|
.map((m) => ({
|
|
|
|
name: m.id,
|
|
|
|
label: `${m.name} - in:$${(m.pricing.prompt * 1_000_000).toFixed(
|
|
|
|
2,
|
|
|
|
)} out:$${(m.pricing.completion * 1_000_000).toFixed(2)} - context ${Math.floor(m.context_length / 1000)}k`,
|
|
|
|
provider: 'OpenRouter',
|
|
|
|
maxTokenAllowed: 8000,
|
|
|
|
}));
|
2024-10-23 15:36:12 +00:00
|
|
|
}
|
2024-10-28 03:16:07 +00:00
|
|
|
|
2024-12-11 08:32:21 +00:00
|
|
|
async function getLMStudioModels(_apiKeys?: Record<string, string>, settings?: IProviderSetting): Promise<ModelInfo[]> {
|
2024-10-28 03:16:07 +00:00
|
|
|
try {
|
2024-12-11 08:32:21 +00:00
|
|
|
const baseUrl = settings?.baseUrl || import.meta.env.LMSTUDIO_API_BASE_URL || 'http://localhost:1234';
|
2024-11-21 21:27:29 +00:00
|
|
|
const response = await fetch(`${baseUrl}/v1/models`);
|
2024-11-21 21:05:35 +00:00
|
|
|
const data = (await response.json()) as any;
|
|
|
|
|
2024-10-28 03:16:07 +00:00
|
|
|
return data.data.map((model: any) => ({
|
|
|
|
name: model.id,
|
|
|
|
label: model.id,
|
2024-11-21 21:05:35 +00:00
|
|
|
provider: 'LMStudio',
|
2024-10-28 03:16:07 +00:00
|
|
|
}));
|
2024-12-10 17:39:59 +00:00
|
|
|
} catch (e: any) {
|
2024-12-13 00:11:35 +00:00
|
|
|
logStore.logError('Failed to get LMStudio models', e, { baseUrl: settings?.baseUrl });
|
2024-12-10 17:39:59 +00:00
|
|
|
logger.warn('Failed to get LMStudio models: ', e.message || '');
|
2024-12-13 00:11:35 +00:00
|
|
|
|
2024-10-28 03:16:07 +00:00
|
|
|
return [];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-12-11 08:32:21 +00:00
|
|
|
async function initializeModelList(providerSettings?: Record<string, IProviderSetting>): Promise<ModelInfo[]> {
|
2024-12-02 20:43:33 +00:00
|
|
|
let apiKeys: Record<string, string> = {};
|
2024-12-06 11:28:04 +00:00
|
|
|
|
2024-12-02 20:43:33 +00:00
|
|
|
try {
|
|
|
|
const storedApiKeys = Cookies.get('apiKeys');
|
|
|
|
|
|
|
|
if (storedApiKeys) {
|
|
|
|
const parsedKeys = JSON.parse(storedApiKeys);
|
|
|
|
|
|
|
|
if (typeof parsedKeys === 'object' && parsedKeys !== null) {
|
|
|
|
apiKeys = parsedKeys;
|
|
|
|
}
|
|
|
|
}
|
2024-12-06 11:28:04 +00:00
|
|
|
} catch (error: any) {
|
2024-12-13 00:11:35 +00:00
|
|
|
logStore.logError('Failed to fetch API keys from cookies', error);
|
2024-12-10 17:39:59 +00:00
|
|
|
logger.warn(`Failed to fetch apikeys from cookies: ${error?.message}`);
|
2024-12-02 20:43:33 +00:00
|
|
|
}
|
2024-11-21 21:05:35 +00:00
|
|
|
MODEL_LIST = [
|
|
|
|
...(
|
|
|
|
await Promise.all(
|
|
|
|
PROVIDER_LIST.filter(
|
|
|
|
(p): p is ProviderInfo & { getDynamicModels: () => Promise<ModelInfo[]> } => !!p.getDynamicModels,
|
2024-12-11 08:32:21 +00:00
|
|
|
).map((p) => p.getDynamicModels(apiKeys, providerSettings?.[p.name])),
|
2024-11-21 21:05:35 +00:00
|
|
|
)
|
|
|
|
).flat(),
|
|
|
|
...staticModels,
|
|
|
|
];
|
2024-12-06 11:28:04 +00:00
|
|
|
|
2024-11-13 20:21:50 +00:00
|
|
|
return MODEL_LIST;
|
2024-10-18 11:34:08 +00:00
|
|
|
}
|
2024-11-11 21:47:12 +00:00
|
|
|
|
2024-11-21 21:05:35 +00:00
|
|
|
export {
|
|
|
|
getOllamaModels,
|
|
|
|
getOpenAILikeModels,
|
|
|
|
getLMStudioModels,
|
|
|
|
initializeModelList,
|
|
|
|
getOpenRouterModels,
|
|
|
|
PROVIDER_LIST,
|
|
|
|
};
|