diff --git a/.env.example b/.env.example index 46a21e89..00a0fd94 100644 --- a/.env.example +++ b/.env.example @@ -5,6 +5,12 @@ # You only need this environment variable set if you want to use Groq models GROQ_API_KEY= +# Get your HuggingFace API Key here - +# https://huggingface.co/settings/tokens +# You only need this environment variable set if you want to use HuggingFace models +HuggingFace_API_KEY= + + # Get your Open AI API Key by following these instructions - # https://help.openai.com/en/articles/4936850-where-do-i-find-my-openai-api-key # You only need this environment variable set if you want to use GPT models @@ -55,4 +61,4 @@ LMSTUDIO_API_BASE_URL= XAI_API_KEY= # Include this environment variable if you want more logging for debugging locally -VITE_LOG_LEVEL=debug +VITE_LOG_LEVEL=debug \ No newline at end of file diff --git a/.husky/commit-msg b/.husky/commit-msg deleted file mode 100644 index d821bbc5..00000000 --- a/.husky/commit-msg +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env sh - -. "$(dirname "$0")/_/husky.sh" - -npx commitlint --edit $1 - -exit 0 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 1bf3bfb7..5bb82b8f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -72,6 +72,7 @@ pnpm install - Add your LLM API keys (only set the ones you plan to use): ```bash GROQ_API_KEY=XXX +HuggingFace_API_KEY=XXX OPENAI_API_KEY=XXX ANTHROPIC_API_KEY=XXX ... diff --git a/Dockerfile b/Dockerfile index 3b5a74cd..82c07da0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -19,6 +19,7 @@ FROM base AS bolt-ai-production # Define environment variables with default values or let them be overridden ARG GROQ_API_KEY +ARG HuggingFace_API_KEY ARG OPENAI_API_KEY ARG ANTHROPIC_API_KEY ARG OPEN_ROUTER_API_KEY @@ -28,6 +29,7 @@ ARG VITE_LOG_LEVEL=debug ENV WRANGLER_SEND_METRICS=false \ GROQ_API_KEY=${GROQ_API_KEY} \ + HuggingFace_KEY=${HuggingFace_API_KEY} \ OPENAI_API_KEY=${OPENAI_API_KEY} \ ANTHROPIC_API_KEY=${ANTHROPIC_API_KEY} \ OPEN_ROUTER_API_KEY=${OPEN_ROUTER_API_KEY} \ @@ -48,6 +50,7 @@ FROM base AS bolt-ai-development # Define the same environment variables for development ARG GROQ_API_KEY +ARG HuggingFace ARG OPENAI_API_KEY ARG ANTHROPIC_API_KEY ARG OPEN_ROUTER_API_KEY @@ -56,6 +59,7 @@ ARG OLLAMA_API_BASE_URL ARG VITE_LOG_LEVEL=debug ENV GROQ_API_KEY=${GROQ_API_KEY} \ + HuggingFace_API_KEY=${HuggingFace_API_KEY} \ OPENAI_API_KEY=${OPENAI_API_KEY} \ ANTHROPIC_API_KEY=${ANTHROPIC_API_KEY} \ OPEN_ROUTER_API_KEY=${OPEN_ROUTER_API_KEY} \ diff --git a/app/lib/.server/llm/api-key.ts b/app/lib/.server/llm/api-key.ts index 464e334d..f282aa80 100644 --- a/app/lib/.server/llm/api-key.ts +++ b/app/lib/.server/llm/api-key.ts @@ -23,6 +23,8 @@ export function getAPIKey(cloudflareEnv: Env, provider: string, userApiKeys?: Re return env.GOOGLE_GENERATIVE_AI_API_KEY || cloudflareEnv.GOOGLE_GENERATIVE_AI_API_KEY; case 'Groq': return env.GROQ_API_KEY || cloudflareEnv.GROQ_API_KEY; + case 'HuggingFace': + return env.HuggingFace_API_KEY || cloudflareEnv.HuggingFace_API_KEY; case 'OpenRouter': return env.OPEN_ROUTER_API_KEY || cloudflareEnv.OPEN_ROUTER_API_KEY; case 'Deepseek': diff --git a/app/lib/.server/llm/model.ts b/app/lib/.server/llm/model.ts index 6be9d117..e07f2bbc 100644 --- a/app/lib/.server/llm/model.ts +++ b/app/lib/.server/llm/model.ts @@ -56,6 +56,15 @@ export function getGroqModel(apiKey: string, model: string) { return openai(model); } +export function getHuggingFaceModel(apiKey: string, model: string) { + const openai = createOpenAI({ + baseURL: 'https://api-inference.huggingface.co/v1/', + apiKey, + }); + + return openai(model); +} + export function getOllamaModel(baseURL: string, model: string) { let Ollama = ollama(model, { numCtx: 32768, @@ -110,6 +119,8 @@ export function getModel(provider: string, model: string, env: Env, apiKeys?: Re return getOpenAIModel(apiKey, model); case 'Groq': return getGroqModel(apiKey, model); + case 'HuggingFace': + return getHuggingFaceModel(apiKey, model); case 'OpenRouter': return getOpenRouterModel(apiKey, model); case 'Google': diff --git a/app/utils/constants.ts b/app/utils/constants.ts index fbcf226e..308832b9 100644 --- a/app/utils/constants.ts +++ b/app/utils/constants.ts @@ -71,7 +71,19 @@ const PROVIDER_LIST: ProviderInfo[] = [ { name: 'llama-3.2-1b-preview', label: 'Llama 3.2 1b (Groq)', provider: 'Groq' } ], getApiKeyLink: 'https://console.groq.com/keys' - }, { + }, + { + name: 'HuggingFace', + staticModels: [ + { name: 'Qwen/Qwen2.5-Coder-32B-Instruct', label: 'Qwen2.5-Coder-32B-Instruct (HuggingFace)', provider: 'HuggingFace' }, + { name: '01-ai/Yi-1.5-34B-Chat', label: 'Yi-1.5-34B-Chat (HuggingFace)', provider: 'HuggingFace' }, + { name: 'codellama/CodeLlama-34b-Instruct-hf', label: 'CodeLlama-34b-Instruct (HuggingFace)', provider: 'HuggingFace' }, + { name: 'NousResearch/Hermes-3-Llama-3.1-8B', label: 'Hermes-3-Llama-3.1-8B (HuggingFace)', provider: 'HuggingFace' } + ], + getApiKeyLink: 'https://huggingface.co/settings/tokens' + }, + + { name: 'OpenAI', staticModels: [ { name: 'gpt-4o-mini', label: 'GPT-4o Mini', provider: 'OpenAI' }, diff --git a/docker-compose.yaml b/docker-compose.yaml index c391dd73..7c03531d 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -14,6 +14,7 @@ services: # No strictly neded but serving as hints for Coolify - PORT=5173 - GROQ_API_KEY=${GROQ_API_KEY} + - HuggingFace_API_KEY=${HuggingFace_API_KEY} - OPENAI_API_KEY=${OPENAI_API_KEY} - ANTHROPIC_API_KEY=${ANTHROPIC_API_KEY} - OPEN_ROUTER_API_KEY=${OPEN_ROUTER_API_KEY} @@ -40,6 +41,7 @@ services: - WATCHPACK_POLLING=true - PORT=5173 - GROQ_API_KEY=${GROQ_API_KEY} + - HuggingFace_API_KEY=${HuggingFace_API_KEY} - OPENAI_API_KEY=${OPENAI_API_KEY} - ANTHROPIC_API_KEY=${ANTHROPIC_API_KEY} - OPEN_ROUTER_API_KEY=${OPEN_ROUTER_API_KEY} diff --git a/worker-configuration.d.ts b/worker-configuration.d.ts index 6db1aa60..1d8993bc 100644 --- a/worker-configuration.d.ts +++ b/worker-configuration.d.ts @@ -2,6 +2,7 @@ interface Env { ANTHROPIC_API_KEY: string; OPENAI_API_KEY: string; GROQ_API_KEY: string; + HuggingFace_API_KEY: string; OPEN_ROUTER_API_KEY: string; OLLAMA_API_BASE_URL: string; OPENAI_LIKE_API_KEY: string;