diff --git a/src/.env.example b/src/.env.example index 2ebc01512..646879352 100644 --- a/src/.env.example +++ b/src/.env.example @@ -64,4 +64,10 @@ AZURE_STORAGE_ACCOUNT_NAME=azurechat AZURE_STORAGE_ACCOUNT_KEY=123456 # Azure Key Vault to store secrets -AZURE_KEY_VAULT_NAME= \ No newline at end of file +AZURE_KEY_VAULT_NAME= + +# optional - endpoint suffix overrides - typically used for Azure Government Clouds, China Clouds, etc. Only use if required. +# AZURE_OPENAI_API_ENDPOINT_SUFFIX= +# AZURE_SEARCH_ENDPOINT_SUFFIX= +# AZURE_STORAGE_ENDPOINT_SUFFIX= +# AZURE_KEY_VAULT_ENDPOINT_SUFFIX= \ No newline at end of file diff --git a/src/features/chat-page/chat-services/azure-ai-search/azure-ai-search.ts b/src/features/chat-page/chat-services/azure-ai-search/azure-ai-search.ts index d2b3c6398..b6d26679f 100644 --- a/src/features/chat-page/chat-services/azure-ai-search/azure-ai-search.ts +++ b/src/features/chat-page/chat-services/azure-ai-search/azure-ai-search.ts @@ -129,8 +129,9 @@ export const ExtensionSimilaritySearch = async (props: { input: searchText, model: "", }); + const endpointSuffix = process.env.AZURE_SEARCH_ENDPOINT_SUFFIX || "search.windows.net"; - const endpoint = `https://${searchName}.search.windows.net`; + const endpoint = `https://${searchName}.${endpointSuffix}`; const searchClient = new SearchClient( endpoint, diff --git a/src/features/common/services/ai-search.ts b/src/features/common/services/ai-search.ts index 187cac299..86b669e04 100644 --- a/src/features/common/services/ai-search.ts +++ b/src/features/common/services/ai-search.ts @@ -15,8 +15,9 @@ export const AzureAISearchCredentials = () => { "One or more Azure AI Search environment variables are not set" ); } + const endpointSuffix = process.env.AZURE_SEARCH_ENDPOINT_SUFFIX || "search.windows.net"; - const endpoint = `https://${searchName}.search.windows.net`; + const endpoint = `https://${searchName}.${endpointSuffix}`; return { apiKey, endpoint, diff --git a/src/features/common/services/azure-storage.ts b/src/features/common/services/azure-storage.ts index 0cc026426..42e0eaffe 100644 --- a/src/features/common/services/azure-storage.ts +++ b/src/features/common/services/azure-storage.ts @@ -10,8 +10,9 @@ const InitBlobServiceClient = () => { throw new Error( "Azure Storage Account not configured correctly, check environment variables." ); + const endpointSuffix = process.env.AZURE_STORAGE_ENDPOINT_SUFFIX || "core.windows.net"; - const connectionString = `DefaultEndpointsProtocol=https;AccountName=${acc};AccountKey=${key};EndpointSuffix=core.windows.net`; + const connectionString = `DefaultEndpointsProtocol=https;AccountName=${acc};AccountKey=${key};EndpointSuffix=${endpointSuffix}`; const blobServiceClient = BlobServiceClient.fromConnectionString(connectionString); diff --git a/src/features/common/services/key-vault.ts b/src/features/common/services/key-vault.ts index 0a0b09580..7f821b642 100644 --- a/src/features/common/services/key-vault.ts +++ b/src/features/common/services/key-vault.ts @@ -10,7 +10,8 @@ export const AzureKeyVaultInstance = () => { "Azure Key vault is not configured correctly, check environment variables." ); } - const url = `https://${keyVaultName}.vault.azure.net`; + const endpointSuffix = process.env.AZURE_KEY_VAULT_ENDPOINT_SUFFIX || "vault.azure.net"; + const url = `https://${keyVaultName}.${endpointSuffix}`; return new SecretClient(url, credential); }; diff --git a/src/features/common/services/openai.ts b/src/features/common/services/openai.ts index c7437184d..0e44a4523 100644 --- a/src/features/common/services/openai.ts +++ b/src/features/common/services/openai.ts @@ -1,9 +1,10 @@ import { OpenAI } from "openai"; export const OpenAIInstance = () => { + const endpointSuffix = process.env.AZURE_OPENAI_API_ENDPOINT_SUFFIX || "openai.azure.com"; const openai = new OpenAI({ apiKey: process.env.AZURE_OPENAI_API_KEY, - baseURL: `https://${process.env.AZURE_OPENAI_API_INSTANCE_NAME}.openai.azure.com/openai/deployments/${process.env.AZURE_OPENAI_API_DEPLOYMENT_NAME}`, + baseURL: `https://${process.env.AZURE_OPENAI_API_INSTANCE_NAME}.${endpointSuffix}/openai/deployments/${process.env.AZURE_OPENAI_API_DEPLOYMENT_NAME}`, defaultQuery: { "api-version": process.env.AZURE_OPENAI_API_VERSION }, defaultHeaders: { "api-key": process.env.AZURE_OPENAI_API_KEY }, }); @@ -20,10 +21,11 @@ export const OpenAIEmbeddingInstance = () => { "Azure OpenAI Embeddings endpoint config is not set, check environment variables." ); } + const endpointSuffix = process.env.AZURE_OPENAI_API_ENDPOINT_SUFFIX || "openai.azure.com"; const openai = new OpenAI({ apiKey: process.env.AZURE_OPENAI_API_KEY, - baseURL: `https://${process.env.AZURE_OPENAI_API_INSTANCE_NAME}.openai.azure.com/openai/deployments/${process.env.AZURE_OPENAI_API_EMBEDDINGS_DEPLOYMENT_NAME}`, + baseURL: `https://${process.env.AZURE_OPENAI_API_INSTANCE_NAME}.${endpointSuffix}/openai/deployments/${process.env.AZURE_OPENAI_API_EMBEDDINGS_DEPLOYMENT_NAME}`, defaultQuery: { "api-version": process.env.AZURE_OPENAI_API_VERSION }, defaultHeaders: { "api-key": process.env.AZURE_OPENAI_API_KEY }, }); @@ -41,10 +43,11 @@ export const OpenAIDALLEInstance = () => { "Azure OpenAI DALLE endpoint config is not set, check environment variables." ); } + const endpointSuffix = process.env.AZURE_OPENAI_API_ENDPOINT_SUFFIX || "openai.azure.com"; const openai = new OpenAI({ apiKey: process.env.AZURE_OPENAI_DALLE_API_KEY, - baseURL: `https://${process.env.AZURE_OPENAI_DALLE_API_INSTANCE_NAME}.openai.azure.com/openai/deployments/${process.env.AZURE_OPENAI_DALLE_API_DEPLOYMENT_NAME}`, + baseURL: `https://${process.env.AZURE_OPENAI_DALLE_API_INSTANCE_NAME}.${endpointSuffix}/openai/deployments/${process.env.AZURE_OPENAI_DALLE_API_DEPLOYMENT_NAME}`, defaultQuery: { "api-version": process.env.AZURE_OPENAI_DALLE_API_VERSION || "2023-12-01-preview",