Skip to content

Commit

Permalink
Refactor environment variables and provider configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
miurla committed Oct 26, 2024
1 parent 4db6c33 commit 144e312
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .env.local.example
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ SEARXNG_SAFESEARCH=0 # Safe search setting: 0 (off), 1 (moderate), 2 (strict)
# Groq API key retrieved here: https://console.groq.com/keys
# GROQ_API_KEY=[YOUR_GROQ_API_KEY]

# Ollama Base URL
# OLLAMA_BASE_URL=http://localhost:11434

# Azure OpenAI API key retrieved here: https://oai.azure.com/resource/deployments/
# AZURE_API_KEY=
# The resource name is used in the assembled URL: https://{resourceName}.openai.azure.com/openai/deployments/{modelId}{path}.
Expand Down
2 changes: 1 addition & 1 deletion app/actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ async function submit(
// Check if provider is enabled
if (!isProviderEnabled(providerId)) {
throw new Error(
`Provider ${providerId} is not available (API key not configured)`
`Provider ${providerId} is not available (API key not configured or base URL not set)`
)
}

Expand Down
8 changes: 5 additions & 3 deletions lib/utils/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { openai, createOpenAI } from '@ai-sdk/openai'
import { anthropic } from '@ai-sdk/anthropic'
import { google } from '@ai-sdk/google'
import { createAzure } from '@ai-sdk/azure'
import { ollama } from 'ollama-ai-provider'
import { createOllama } from 'ollama-ai-provider'

export const registry = createProviderRegistry({
openai,
Expand All @@ -13,7 +13,9 @@ export const registry = createProviderRegistry({
apiKey: process.env.GROQ_API_KEY,
baseURL: 'https://api.groq.com/openai/v1'
}),
ollama,
ollama: createOllama({
baseURL: `${process.env.OLLAMA_BASE_URL}/api`
}),
azure: createAzure({
apiKey: process.env.AZURE_API_KEY,
resourceName: process.env.AZURE_RESOURCE_NAME
Expand All @@ -35,7 +37,7 @@ export function isProviderEnabled(providerId: string): boolean {
case 'groq':
return !!process.env.GROQ_API_KEY
case 'ollama':
return true
return !!process.env.OLLAMA_BASE_URL
case 'azure':
return !!process.env.AZURE_API_KEY && !!process.env.AZURE_RESOURCE_NAME
default:
Expand Down

0 comments on commit 144e312

Please sign in to comment.