Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow override of endpoint suffixes with env vars #376

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ AZURE_OPENAI_API_INSTANCE_NAME=azurechat
AZURE_OPENAI_API_DEPLOYMENT_NAME=gpt-4
AZURE_OPENAI_API_VERSION=2023-12-01-preview
AZURE_OPENAI_API_EMBEDDINGS_DEPLOYMENT_NAME=embedding
AZURE_OPENAI_API_ENDPOINT_SUFFIX=

# DALL-E image creation endpoint config
AZURE_OPENAI_DALLE_API_KEY=222222
Expand Down Expand Up @@ -53,6 +54,7 @@ AZURE_COSMOSDB_CONFIG_CONTAINER_NAME=config
AZURE_SEARCH_API_KEY=
AZURE_SEARCH_NAME=
AZURE_SEARCH_INDEX_NAME=
AZURE_SEARCH_ENDPOINT_SUFFIX=

# Azure AI Document Intelligence to extract content from your data
AZURE_DOCUMENT_INTELLIGENCE_ENDPOINT=https://NAME.api.cognitive.microsoft.com/
Expand All @@ -68,6 +70,8 @@ AZURE_SPEECH_KEY=
# Azure Storage account to store files
AZURE_STORAGE_ACCOUNT_NAME=azurechat
AZURE_STORAGE_ACCOUNT_KEY=123456
AZURE_STORAGE_ENDPOINT_SUFFIX=

# Azure Key Vault to store secrets
AZURE_KEY_VAULT_NAME=
AZURE_KEY_VAULT_NAME=
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);
};
12 changes: 8 additions & 4 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 All @@ -67,10 +70,11 @@ export const OpenAIVisionInstance = () => {
"Azure OpenAI Vision environment 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_VISION_API_KEY,
baseURL: `https://${process.env.AZURE_OPENAI_VISION_API_INSTANCE_NAME}.openai.azure.com/openai/deployments/${process.env.AZURE_OPENAI_VISION_API_DEPLOYMENT_NAME}`,
baseURL: `https://${process.env.AZURE_OPENAI_VISION_API_INSTANCE_NAME}.${endpointSuffix}/openai/deployments/${process.env.AZURE_OPENAI_VISION_API_DEPLOYMENT_NAME}`,
defaultQuery: {
"api-version": process.env.AZURE_OPENAI_VISION_API_VERSION,
},
Expand Down