An AI-powered search engine with a generative UI
TypeScript generative-aigenerative-uinextjsollamareactsearxngshadcn-uitailwindcsstavilytypescriptupstashvercel-ai-sdk
Support Azure OpenAI provider
Peter Szilvasi253073762265
diff --git a/.env.local.example b/.env.local.exampleindex 34088f40..f168272c 100644--- a/.env.local.example+++ b/.env.local.example@@ -40,6 +40,16 @@ SEARXNG_SAFESEARCH=0 # Safe search setting: 0 (off), 1 (moderate), 2 (strict)# If not set, the default is gpt-4o.# OPENAI_API_MODEL=gpt-4o-mini+# 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}.+# AZURE_RESOURCE_NAME=++# Used to set the deployment name for Azure OpenAI API requests.+# If not set, the default is gpt-4o.+# AZURE_DEPLOYMENT_NAME=+# If you want to use Google Generative AI instead of OpenAI, enable the following settings.# Google Generative AI API key retrieved here: https://aistudio.google.com/app/apikey# GOOGLE_GENERATIVE_AI_API_KEY=[YOUR_GOOGLE_GENERATIVE_AI_API_KEY]diff --git a/README.md b/README.mdindex cf15a490..4d23aada 100644--- a/README.md+++ b/README.md@@ -27,6 +27,7 @@ An AI-powered search engine with a generative UI.- Use as a search engine [※](#-search-engine)- Support for providers other than OpenAI- Google Generative AI Provider+ - Azure OpenAI Provider [※](https://github.com/miurla/morphic/issues/13)- Anthropic Provider [※](https://github.com/miurla/morphic/pull/239)- Ollama Provider ([Unstable](https://github.com/miurla/morphic/issues/215))- Specify the model to generate answersdiff --git a/bun.lockb b/bun.lockbindex 4cc856e3..bded68fa 100755Binary files a/bun.lockb and b/bun.lockb differdiff --git a/lib/utils/index.ts b/lib/utils/index.tsindex 08535a18..4ab9023d 100644--- a/lib/utils/index.ts+++ b/lib/utils/index.ts@@ -2,6 +2,7 @@ import { type ClassValue, clsx } from 'clsx'import { twMerge } from 'tailwind-merge'import { createOllama } from 'ollama-ai-provider'import { createOpenAI } from '@ai-sdk/openai'+import { createAzure } from '@ai-sdk/azure';import { google } from '@ai-sdk/google'import { anthropic } from '@ai-sdk/anthropic'import { CoreMessage } from 'ai'@@ -17,6 +18,9 @@ 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 azureResourceName = process.env.AZURE_RESOURCE_NAME+ const azureApiKey = process.env.AZURE_API_KEY+ let azureDeploymentName = process.env.AZURE_DEPLOYMENT_NAME || 'gpt-4o'const googleApiKey = process.env.GOOGLE_GENERATIVE_AI_API_KEYconst anthropicApiKey = process.env.ANTHROPIC_API_KEY@@ -27,7 +31,7 @@ export function getModel(useSubModel = false) {!anthropicApiKey) {throw new Error(- 'Missing environment variables for Ollama, OpenAI, Google or Anthropic'+ 'Missing environment variables for Ollama, OpenAI, Azure OpenAI, Google or Anthropic')}// Ollama@@ -49,8 +53,16 @@ export function getModel(useSubModel = false) {return anthropic('claude-3-5-sonnet-20240620')}- // Fallback to OpenAI instead+ if (azureApiKey && azureResourceName) {+ const azure = createAzure({+ apiKey: azureApiKey,+ resourceName: azureResourceName+ })++ return azure.chat(azureDeploymentName)+ }+ // Fallback to OpenAI insteadconst openai = createOpenAI({baseURL: openaiApiBase, // optional base URL for proxies etc.apiKey: openaiApiKey, // optional API key, default to env property OPENAI_API_KEYdiff --git a/package.json b/package.jsonindex aa02039e..1d96fda6 100644--- a/package.json+++ b/package.json@@ -11,6 +11,7 @@},"dependencies": {"@ai-sdk/anthropic": "^0.0.21",+ "@ai-sdk/azure": "^0.0.32","@ai-sdk/google": "^0.0.22","@ai-sdk/openai": "^0.0.31","@radix-ui/react-alert-dialog": "^1.0.5",