An AI-powered search engine with a generative UI
TypeScript generative-aigenerative-uinextjsollamareactsearxngshadcn-uitailwindcsstavilytypescriptupstashvercel-ai-sdk
chore: Fix environment variable handling for Ollama, OpenAI, and Google
Yoshiki Miura97bbb828ce74
diff --git a/.env.local.example b/.env.local.exampleindex 25d12d91..98012886 100644--- a/.env.local.example+++ b/.env.local.example@@ -27,7 +27,7 @@ UPSTASH_REDIS_REST_TOKEN=[YOUR_UPSTASH_REDIS_REST_TOKEN]# Google Generative AI API key retrieved here: https://aistudio.google.com/app/apikey# GOOGLE_GENERATIVE_AI_API_KEY=[YOUR_GOOGLE_GENERATIVE_AI_API_KEY]-# If you want to use Ollama, enable the following variables.+# [Unstable] If you want to use Ollama, enable the following variables.# OLLAMA_MODEL=[YOUR_OLLAMA_MODEL] # The main model to use. Recommended: mistral or openherms# OLLAMA_SUB_MODEL=[YOUR_OLLAMA_SUB_MODEL] # The sub model to use. Recommended: phi3 or llama3# OLLAMA_BASE_URL=[YOUR_OLLAMA_URL] # The base URL to use. e.g. http://localhost:11434diff --git a/lib/utils/index.ts b/lib/utils/index.tsindex 58747b71..958e88de 100644--- a/lib/utils/index.ts+++ b/lib/utils/index.ts@@ -16,13 +16,14 @@ export function getModel(useSubModel = false) {const openaiApiBase = process.env.OPENAI_API_BASEconst openaiApiKey = process.env.OPENAI_API_KEYlet openaiApiModel = process.env.OPENAI_API_MODEL || 'gpt-4o'+ const googleApiKey = process.env.GOOGLE_GENERATIVE_AI_API_KEY- if (!(ollamaBaseUrl && ollamaModel) && !(openaiApiBase && openaiApiKey)) {- throw new Error('Missing environment variables for Ollama and OpenAI')+ if (!(ollamaBaseUrl && ollamaModel) && !openaiApiKey && !googleApiKey) {+ throw new Error(+ 'Missing environment variables for Ollama, OpenAI, or Google'+ )}-// Ollama-if (ollamaBaseUrl && ollamaModel) {const ollama = createOllama({ baseURL: ollamaBaseUrl })@@ -40,8 +41,8 @@ export function getModel(useSubModel = false) {// Fallback to OpenAI insteadconst openai = createOpenAI({- baseUrl: process.env.OPENAI_API_BASE, // optional base URL for proxies etc.- apiKey: process.env.OPENAI_API_KEY, // optional API key, default to env property OPENAI_API_KEY+ baseUrl: openaiApiBase, // optional base URL for proxies etc.+ apiKey: openaiApiKey, // optional API key, default to env property OPENAI_API_KEYorganization: '' // optional organization})