diff --git a/.env.example b/.env.example index 22bdcc18..8c312611 100644 --- a/.env.example +++ b/.env.example @@ -20,5 +20,9 @@ ANTHROPIC_API_KEY= # You only need this environment variable set if you want to use OpenRouter models OPEN_ROUTER_API_KEY= +# You only need this environment variable set if you want to use oLLAMA models +#EXAMPLE http://localhost:11434 +OLLAMA_API_BASE_URL= + # Include this environment variable if you want more logging for debugging locally -VITE_LOG_LEVEL=debug \ No newline at end of file +VITE_LOG_LEVEL=debug diff --git a/app/entry.server.tsx b/app/entry.server.tsx index 4baf0700..be2b42bf 100644 --- a/app/entry.server.tsx +++ b/app/entry.server.tsx @@ -5,6 +5,7 @@ import { renderToReadableStream } from 'react-dom/server'; import { renderHeadToString } from 'remix-island'; import { Head } from './root'; import { themeStore } from '~/lib/stores/theme'; +import { initializeModelList } from '~/utils/constants'; export default async function handleRequest( request: Request, @@ -13,6 +14,8 @@ export default async function handleRequest( remixContext: EntryContext, _loadContext: AppLoadContext, ) { + await initializeModelList(); + const readable = await renderToReadableStream(, { signal: request.signal, onError(error: unknown) { diff --git a/app/routes/api.models.ts b/app/routes/api.models.ts new file mode 100644 index 00000000..ace4ef00 --- /dev/null +++ b/app/routes/api.models.ts @@ -0,0 +1,6 @@ +import { json } from '@remix-run/cloudflare'; +import { MODEL_LIST } from '~/utils/constants'; + +export async function loader() { + return json(MODEL_LIST); +} diff --git a/app/utils/constants.ts b/app/utils/constants.ts index 4ff6a46f..db9d5bc8 100644 --- a/app/utils/constants.ts +++ b/app/utils/constants.ts @@ -1,38 +1,55 @@ +import type { ModelInfo } from './types'; + export const WORK_DIR_NAME = 'project'; export const WORK_DIR = `/home/${WORK_DIR_NAME}`; export const MODIFICATIONS_TAG_NAME = 'bolt_file_modifications'; export const MODEL_REGEX = /^\[Model: (.*?)\]\n\n/; -export const DEFAULT_MODEL = "claude-3-5-sonnet-20240620"; -export const DEFAULT_PROVIDER = "Anthropic"; -export const MODEL_LIST = [ - { name: 'claude-3-5-sonnet-20240620', label: 'Claude 3.5 Sonnet', provider: 'Anthropic' }, - { name: 'gpt-4o', label: 'GPT-4o', provider: 'OpenAI' }, - { name: 'qwen2.5-coder:7b', label: 'Qwen 2.5 Coder 7b', provider: 'Ollama' }, - { name: 'qwen2.5-coder:1.5b', label: 'Qwen 2.5 Coder 1.5b', provider: 'Ollama' }, - { name: 'deepseek-coder-v2:236b', label: 'DeepSeek-Coder-V2 236b', provider: 'Ollama' }, - { name: 'deepseek-coder-v2:16b', label: 'DeepSeek-Coder-V2 16b', provider: 'Ollama' }, - { name: 'codebooga', label: 'Codebooga 34b', provider: 'Ollama' }, - { name: 'phind-codellama', label: 'Phind CodeLlama 34b', provider: 'Ollama' }, - { name: 'codellama:70b', label: 'Code Llama 70b', provider: 'Ollama' }, - { name: 'codellama:34b', label: 'Code Llama 34b', provider: 'Ollama' }, - { name: 'codellama:13b', label: 'Code Llama 13b', provider: 'Ollama' }, - { name: 'codellama:7b', label: 'Code Llama 7b', provider: 'Ollama' }, - { name: 'deepseek/deepseek-coder', label: 'Deepseek-Coder V2 236B (OpenRouter)', provider: 'OpenRouter' }, - { name: 'google/gemini-flash-1.5', label: 'Google Gemini Flash 1.5 (OpenRouter)', provider: 'OpenRouter' }, - { name: 'google/gemini-pro-1.5', label: 'Google Gemini Pro 1.5 (OpenRouter)', provider: 'OpenRouter' }, - { name: 'mistralai/mistral-nemo', label: 'OpenRouter Mistral Nemo (OpenRouter)', provider: 'OpenRouter' }, - { name: 'qwen/qwen-110b-chat', label: 'OpenRouter Qwen 110b Chat (OpenRouter)', provider: 'OpenRouter' }, - { name: 'cohere/command', label: 'Cohere Command (OpenRouter)', provider: 'OpenRouter' }, - { name: 'llama-3.1-70b-versatile', label: 'Llama 3.1 70b (Groq)', provider: 'Groq' }, - { name: 'llama-3.1-8b-instant', label: 'Llama 3.1 8b (Groq)', provider: 'Groq' }, - { name: 'llama-3.2-11b-vision-preview', label: 'Llama 3.2 11b (Groq)', provider: 'Groq' }, - { name: 'llama-3.2-3b-preview', label: 'Llama 3.2 3b (Groq)', provider: 'Groq' }, - { name: 'llama-3.2-1b-preview', label: 'Llama 3.2 1b (Groq)', provider: 'Groq' }, - { name: 'claude-3-opus-20240229', label: 'Claude 3 Opus', provider: 'Anthropic' }, - { name: 'claude-3-sonnet-20240229', label: 'Claude 3 Sonnet', provider: 'Anthropic' }, - { name: 'claude-3-haiku-20240307', label: 'Claude 3 Haiku', provider: 'Anthropic' }, - { name: 'gpt-4o-mini', label: 'GPT-4o Mini', provider: 'OpenAI' }, - { name: 'gpt-4-turbo', label: 'GPT-4 Turbo', provider: 'OpenAI' }, - { name: 'gpt-4', label: 'GPT-4', provider: 'OpenAI' }, - { name: 'gpt-3.5-turbo', label: 'GPT-3.5 Turbo', provider: 'OpenAI' }, -]; \ No newline at end of file +export const DEFAULT_MODEL = 'claude-3-5-sonnet-20240620'; +export const DEFAULT_PROVIDER = 'Anthropic'; + +const staticModels: ModelInfo[] = [ + { name: 'claude-3-5-sonnet-20240620', label: 'Claude 3.5 Sonnet', provider: 'Anthropic' }, + { name: 'gpt-4o', label: 'GPT-4o', provider: 'OpenAI' }, + { name: 'deepseek/deepseek-coder', label: 'Deepseek-Coder V2 236B (OpenRouter)', provider: 'OpenRouter' }, + { name: 'google/gemini-flash-1.5', label: 'Google Gemini Flash 1.5 (OpenRouter)', provider: 'OpenRouter' }, + { name: 'google/gemini-pro-1.5', label: 'Google Gemini Pro 1.5 (OpenRouter)', provider: 'OpenRouter' }, + { name: 'mistralai/mistral-nemo', label: 'OpenRouter Mistral Nemo (OpenRouter)', provider: 'OpenRouter' }, + { name: 'qwen/qwen-110b-chat', label: 'OpenRouter Qwen 110b Chat (OpenRouter)', provider: 'OpenRouter' }, + { name: 'cohere/command', label: 'Cohere Command (OpenRouter)', provider: 'OpenRouter' }, + { name: 'llama-3.1-70b-versatile', label: 'Llama 3.1 70b (Groq)', provider: 'Groq' }, + { name: 'llama-3.1-8b-instant', label: 'Llama 3.1 8b (Groq)', provider: 'Groq' }, + { name: 'llama-3.2-11b-vision-preview', label: 'Llama 3.2 11b (Groq)', provider: 'Groq' }, + { name: 'llama-3.2-3b-preview', label: 'Llama 3.2 3b (Groq)', provider: 'Groq' }, + { name: 'llama-3.2-1b-preview', label: 'Llama 3.2 1b (Groq)', provider: 'Groq' }, + { name: 'claude-3-opus-20240229', label: 'Claude 3 Opus', provider: 'Anthropic' }, + { name: 'claude-3-sonnet-20240229', label: 'Claude 3 Sonnet', provider: 'Anthropic' }, + { name: 'claude-3-haiku-20240307', label: 'Claude 3 Haiku', provider: 'Anthropic' }, + { name: 'gpt-4o-mini', label: 'GPT-4o Mini', provider: 'OpenAI' }, + { name: 'gpt-4-turbo', label: 'GPT-4 Turbo', provider: 'OpenAI' }, + { name: 'gpt-4', label: 'GPT-4', provider: 'OpenAI' }, + { name: 'gpt-3.5-turbo', label: 'GPT-3.5 Turbo', provider: 'OpenAI' }, +]; + +export let MODEL_LIST: ModelInfo[] = [...staticModels]; + +async function getOllamaModels(): Promise { + try { + const response = await fetch(`http://localhost:11434/api/tags`); + const data = await response.json(); + + return data.models.map((model: any) => ({ + name: model.name, + label: `${model.name} (${model.details.parameter_size})`, + provider: 'Ollama', + })); + } catch (e) { + return []; + } +} + +async function initializeModelList(): Promise { + const ollamaModels = await getOllamaModels(); + MODEL_LIST = [...ollamaModels, ...staticModels]; +} +initializeModelList().then(); +export { getOllamaModels, initializeModelList }; diff --git a/app/utils/types.ts b/app/utils/types.ts new file mode 100644 index 00000000..7ace4e64 --- /dev/null +++ b/app/utils/types.ts @@ -0,0 +1,28 @@ + +interface OllamaModelDetails { + parent_model: string; + format: string; + family: string; + families: string[]; + parameter_size: string; + quantization_level: string; +} + +interface OllamaModel { + name: string; + model: string; + modified_at: string; + size: number; + digest: string; + details: OllamaModelDetails; +} + +export interface OllamaApiResponse { + models: OllamaModel[]; +} + +export interface ModelInfo { + name: string; + label: string; + provider: string; +} diff --git a/worker-configuration.d.ts b/worker-configuration.d.ts index 41af2144..f3259893 100644 --- a/worker-configuration.d.ts +++ b/worker-configuration.d.ts @@ -3,4 +3,5 @@ interface Env { OPENAI_API_KEY: string; GROQ_API_KEY: string; OPEN_ROUTER_API_KEY: string; + OLLAMA_API_BASE_URL: string; }