Skip to content

Commit 47f4aa9

Browse files
authored
Merge pull request #376 from jasonpnnl/375-allow-override-of-service-endpoint-domains
Allow override of endpoint suffixes with env vars
2 parents c848a44 + e58eb11 commit 47f4aa9

File tree

6 files changed

+21
-8
lines changed

6 files changed

+21
-8
lines changed

src/.env.example

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,10 @@ AZURE_STORAGE_ACCOUNT_NAME=azurechat
6464
AZURE_STORAGE_ACCOUNT_KEY=123456
6565

6666
# Azure Key Vault to store secrets
67-
AZURE_KEY_VAULT_NAME=
67+
AZURE_KEY_VAULT_NAME=
68+
69+
# optional - endpoint suffix overrides - typically used for Azure Government Clouds, China Clouds, etc. Only use if required.
70+
# AZURE_OPENAI_API_ENDPOINT_SUFFIX=
71+
# AZURE_SEARCH_ENDPOINT_SUFFIX=
72+
# AZURE_STORAGE_ENDPOINT_SUFFIX=
73+
# AZURE_KEY_VAULT_ENDPOINT_SUFFIX=

src/features/chat-page/chat-services/azure-ai-search/azure-ai-search.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,9 @@ export const ExtensionSimilaritySearch = async (props: {
129129
input: searchText,
130130
model: "",
131131
});
132+
const endpointSuffix = process.env.AZURE_SEARCH_ENDPOINT_SUFFIX || "search.windows.net";
132133

133-
const endpoint = `https://${searchName}.search.windows.net`;
134+
const endpoint = `https://${searchName}.${endpointSuffix}`;
134135

135136
const searchClient = new SearchClient(
136137
endpoint,

src/features/common/services/ai-search.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ export const AzureAISearchCredentials = () => {
1515
"One or more Azure AI Search environment variables are not set"
1616
);
1717
}
18+
const endpointSuffix = process.env.AZURE_SEARCH_ENDPOINT_SUFFIX || "search.windows.net";
1819

19-
const endpoint = `https://${searchName}.search.windows.net`;
20+
const endpoint = `https://${searchName}.${endpointSuffix}`;
2021
return {
2122
apiKey,
2223
endpoint,

src/features/common/services/azure-storage.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ const InitBlobServiceClient = () => {
1010
throw new Error(
1111
"Azure Storage Account not configured correctly, check environment variables."
1212
);
13+
const endpointSuffix = process.env.AZURE_STORAGE_ENDPOINT_SUFFIX || "core.windows.net";
1314

14-
const connectionString = `DefaultEndpointsProtocol=https;AccountName=${acc};AccountKey=${key};EndpointSuffix=core.windows.net`;
15+
const connectionString = `DefaultEndpointsProtocol=https;AccountName=${acc};AccountKey=${key};EndpointSuffix=${endpointSuffix}`;
1516

1617
const blobServiceClient =
1718
BlobServiceClient.fromConnectionString(connectionString);

src/features/common/services/key-vault.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ export const AzureKeyVaultInstance = () => {
1010
"Azure Key vault is not configured correctly, check environment variables."
1111
);
1212
}
13-
const url = `https://${keyVaultName}.vault.azure.net`;
13+
const endpointSuffix = process.env.AZURE_KEY_VAULT_ENDPOINT_SUFFIX || "vault.azure.net";
14+
const url = `https://${keyVaultName}.${endpointSuffix}`;
1415

1516
return new SecretClient(url, credential);
1617
};

src/features/common/services/openai.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { OpenAI } from "openai";
22

33
export const OpenAIInstance = () => {
4+
const endpointSuffix = process.env.AZURE_OPENAI_API_ENDPOINT_SUFFIX || "openai.azure.com";
45
const openai = new OpenAI({
56
apiKey: process.env.AZURE_OPENAI_API_KEY,
6-
baseURL: `https://${process.env.AZURE_OPENAI_API_INSTANCE_NAME}.openai.azure.com/openai/deployments/${process.env.AZURE_OPENAI_API_DEPLOYMENT_NAME}`,
7+
baseURL: `https://${process.env.AZURE_OPENAI_API_INSTANCE_NAME}.${endpointSuffix}/openai/deployments/${process.env.AZURE_OPENAI_API_DEPLOYMENT_NAME}`,
78
defaultQuery: { "api-version": process.env.AZURE_OPENAI_API_VERSION },
89
defaultHeaders: { "api-key": process.env.AZURE_OPENAI_API_KEY },
910
});
@@ -20,10 +21,11 @@ export const OpenAIEmbeddingInstance = () => {
2021
"Azure OpenAI Embeddings endpoint config is not set, check environment variables."
2122
);
2223
}
24+
const endpointSuffix = process.env.AZURE_OPENAI_API_ENDPOINT_SUFFIX || "openai.azure.com";
2325

2426
const openai = new OpenAI({
2527
apiKey: process.env.AZURE_OPENAI_API_KEY,
26-
baseURL: `https://${process.env.AZURE_OPENAI_API_INSTANCE_NAME}.openai.azure.com/openai/deployments/${process.env.AZURE_OPENAI_API_EMBEDDINGS_DEPLOYMENT_NAME}`,
28+
baseURL: `https://${process.env.AZURE_OPENAI_API_INSTANCE_NAME}.${endpointSuffix}/openai/deployments/${process.env.AZURE_OPENAI_API_EMBEDDINGS_DEPLOYMENT_NAME}`,
2729
defaultQuery: { "api-version": process.env.AZURE_OPENAI_API_VERSION },
2830
defaultHeaders: { "api-key": process.env.AZURE_OPENAI_API_KEY },
2931
});
@@ -41,10 +43,11 @@ export const OpenAIDALLEInstance = () => {
4143
"Azure OpenAI DALLE endpoint config is not set, check environment variables."
4244
);
4345
}
46+
const endpointSuffix = process.env.AZURE_OPENAI_API_ENDPOINT_SUFFIX || "openai.azure.com";
4447

4548
const openai = new OpenAI({
4649
apiKey: process.env.AZURE_OPENAI_DALLE_API_KEY,
47-
baseURL: `https://${process.env.AZURE_OPENAI_DALLE_API_INSTANCE_NAME}.openai.azure.com/openai/deployments/${process.env.AZURE_OPENAI_DALLE_API_DEPLOYMENT_NAME}`,
50+
baseURL: `https://${process.env.AZURE_OPENAI_DALLE_API_INSTANCE_NAME}.${endpointSuffix}/openai/deployments/${process.env.AZURE_OPENAI_DALLE_API_DEPLOYMENT_NAME}`,
4851
defaultQuery: {
4952
"api-version":
5053
process.env.AZURE_OPENAI_DALLE_API_VERSION || "2023-12-01-preview",

0 commit comments

Comments
 (0)