From 9a2fc9220d252d20f046074e70abc47976e67216 Mon Sep 17 00:00:00 2001 From: Anon Date: Thu, 7 Nov 2024 01:03:37 +0100 Subject: [PATCH 1/2] Added support for xAI Grok Beta --- app/lib/.server/llm/api-key.ts | 2 ++ app/lib/.server/llm/model.ts | 11 +++++++++++ app/utils/constants.ts | 2 ++ 3 files changed, 15 insertions(+) diff --git a/app/lib/.server/llm/api-key.ts b/app/lib/.server/llm/api-key.ts index 327cfb334..9293a5694 100644 --- a/app/lib/.server/llm/api-key.ts +++ b/app/lib/.server/llm/api-key.ts @@ -25,6 +25,8 @@ export function getAPIKey(cloudflareEnv: Env, provider: string) { return env.MISTRAL_API_KEY || cloudflareEnv.MISTRAL_API_KEY; case "OpenAILike": return env.OPENAI_LIKE_API_KEY || cloudflareEnv.OPENAI_LIKE_API_KEY; + case "xAI": + return env.XAI_API_KEY || cloudflareEnv.XAI_API_KEY; default: return ""; } diff --git a/app/lib/.server/llm/model.ts b/app/lib/.server/llm/model.ts index 390d57aeb..6d48171a2 100644 --- a/app/lib/.server/llm/model.ts +++ b/app/lib/.server/llm/model.ts @@ -80,6 +80,15 @@ export function getOpenRouterModel(apiKey: string, model: string) { return openRouter.chat(model); } +export function getXAIModel(apiKey: string, model: string) { + const openai = createOpenAI({ + baseURL: 'https://api.x.ai/v1', + apiKey, + }); + + return openai(model); +} + export function getModel(provider: string, model: string, env: Env) { const apiKey = getAPIKey(env, provider); const baseURL = getBaseURL(env, provider); @@ -101,6 +110,8 @@ export function getModel(provider: string, model: string, env: Env) { return getDeepseekModel(apiKey, model) case 'Mistral': return getMistralModel(apiKey, model); + case 'xAI': + return getXAIModel(apiKey, model); default: return getOllamaModel(baseURL, model); } diff --git a/app/utils/constants.ts b/app/utils/constants.ts index d003df496..b3120f91d 100644 --- a/app/utils/constants.ts +++ b/app/utils/constants.ts @@ -15,6 +15,7 @@ const staticModels: ModelInfo[] = [ { 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: 'x-ai/grok-beta', label: "xAI Grok Beta (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' }, @@ -32,6 +33,7 @@ const staticModels: ModelInfo[] = [ { 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' }, + { name: 'grok-beta', label: "xAI Grok Beta", provider: 'xAI' }, { name: 'deepseek-coder', label: 'Deepseek-Coder', provider: 'Deepseek'}, { name: 'deepseek-chat', label: 'Deepseek-Chat', provider: 'Deepseek'}, { name: 'open-mistral-7b', label: 'Mistral 7B', provider: 'Mistral' }, From 8d7f108dfa3700d8a7444962a2286380bb44dd7a Mon Sep 17 00:00:00 2001 From: Anon Date: Thu, 7 Nov 2024 01:14:27 +0100 Subject: [PATCH 2/2] Added the XAI_API_KEY variable to the .env.example --- .env.example | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.env.example b/.env.example index ec825e8ee..83f29aedc 100644 --- a/.env.example +++ b/.env.example @@ -43,5 +43,10 @@ OPENAI_LIKE_API_KEY= # You only need this environment variable set if you want to use Mistral models MISTRAL_API_KEY= +# Get your xAI API key +# https://x.ai/api +# You only need this environment variable set if you want to use xAI models +XAI_API_KEY= + # Include this environment variable if you want more logging for debugging locally VITE_LOG_LEVEL=debug