Skip to content

Commit

Permalink
Merge pull request #376 from jasonpnnl/375-allow-override-of-service-…
Browse files Browse the repository at this point in the history
…endpoint-domains

Allow override of endpoint suffixes with env vars
  • Loading branch information
davidxw authored Sep 11, 2024
2 parents c848a44 + e58eb11 commit 47f4aa9
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 8 deletions.
8 changes: 7 additions & 1 deletion src/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,10 @@ AZURE_STORAGE_ACCOUNT_NAME=azurechat
AZURE_STORAGE_ACCOUNT_KEY=123456

# Azure Key Vault to store secrets
AZURE_KEY_VAULT_NAME=
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=
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion src/features/common/services/ai-search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion src/features/common/services/azure-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion src/features/common/services/key-vault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
9 changes: 6 additions & 3 deletions src/features/common/services/openai.ts
Original file line number Diff line number Diff line change
@@ -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 },
});
Expand All @@ -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 },
});
Expand All @@ -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",
Expand Down

0 comments on commit 47f4aa9

Please sign in to comment.