From 8d1fff0e26bde62bf2bef02c36cc39d07c5e8ef9 Mon Sep 17 00:00:00 2001 From: Zhijie Huang Date: Wed, 9 Oct 2024 10:26:37 +0000 Subject: [PATCH 1/5] configure global standard deployment as default ofr gpt 4 --- infra/main.bicep | 13 +++++++++---- infra/main.parameters.json | 20 +++++++++++++++++++- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/infra/main.bicep b/infra/main.bicep index bc019f9c49..b3c22cddf9 100644 --- a/infra/main.bicep +++ b/infra/main.bicep @@ -57,7 +57,7 @@ param speechServiceResourceGroupName string = '' param speechServiceLocation string = '' param speechServiceName string = '' param speechServiceSkuName string // Set in main.parameters.json -param useGPT4V bool = false +param useGPT4V bool = true @description('Location for the OpenAI resource group') @allowed([ @@ -110,6 +110,7 @@ param chatGptModelName string = '' param chatGptDeploymentName string = '' param chatGptDeploymentVersion string = '' param chatGptDeploymentCapacity int = 0 +param chatGptDeploymentSkuName string = '' var chatGpt = { modelName: !empty(chatGptModelName) ? chatGptModelName @@ -117,6 +118,7 @@ var chatGpt = { deploymentName: !empty(chatGptDeploymentName) ? chatGptDeploymentName : 'chat' deploymentVersion: !empty(chatGptDeploymentVersion) ? chatGptDeploymentVersion : '0613' deploymentCapacity: chatGptDeploymentCapacity != 0 ? chatGptDeploymentCapacity : 30 + deploymentSkuName: !empty(chatGptDeploymentSkuName) ? chatGptDeploymentSkuName : 'Standard' } param embeddingModelName string = '' @@ -124,11 +126,13 @@ param embeddingDeploymentName string = '' param embeddingDeploymentVersion string = '' param embeddingDeploymentCapacity int = 0 param embeddingDimensions int = 0 +param embeddingDeploymentSkuName string = '' var embedding = { modelName: !empty(embeddingModelName) ? embeddingModelName : 'text-embedding-ada-002' deploymentName: !empty(embeddingDeploymentName) ? embeddingDeploymentName : 'embedding' deploymentVersion: !empty(embeddingDeploymentVersion) ? embeddingDeploymentVersion : '2' deploymentCapacity: embeddingDeploymentCapacity != 0 ? embeddingDeploymentCapacity : 30 + deploymentSkuName: !empty(embeddingDeploymentSkuName) ? embeddingDeploymentSkuName : 'Standard' dimensions: embeddingDimensions != 0 ? embeddingDimensions : 1536 } @@ -136,6 +140,7 @@ param gpt4vModelName string = 'gpt-4o' param gpt4vDeploymentName string = 'gpt-4o' param gpt4vModelVersion string = '2024-05-13' param gpt4vDeploymentCapacity int = 10 +param gpt4vDeploymentSkuName string = 'GlobalStandard' param tenantId string = tenant().tenantId param authTenantId string = '' @@ -453,7 +458,7 @@ var defaultOpenAiDeployments = [ version: chatGpt.deploymentVersion } sku: { - name: 'Standard' + name: chatGpt.deploymentSkuName capacity: chatGpt.deploymentCapacity } } @@ -465,7 +470,7 @@ var defaultOpenAiDeployments = [ version: embedding.deploymentVersion } sku: { - name: 'Standard' + name: embedding.deploymentSkuName capacity: embedding.deploymentCapacity } } @@ -483,7 +488,7 @@ var openAiDeployments = concat( version: gpt4vModelVersion } sku: { - name: 'Standard' + name: gpt4vDeploymentSkuName capacity: gpt4vDeploymentCapacity } } diff --git a/infra/main.parameters.json b/infra/main.parameters.json index 44a3a244fd..8001634f41 100644 --- a/infra/main.parameters.json +++ b/infra/main.parameters.json @@ -101,6 +101,9 @@ "chatGptDeploymentCapacity":{ "value": "${AZURE_OPENAI_CHATGPT_DEPLOYMENT_CAPACITY}" }, + "chatGptDeploymentSkuName":{ + "value": "${AZURE_OPENAI_CHATGPT_DEPLOYMENT_SKU=Standard}" + }, "embeddingModelName":{ "value": "${AZURE_OPENAI_EMB_MODEL_NAME}" }, @@ -113,12 +116,27 @@ "embeddingDeploymentCapacity":{ "value": "${AZURE_OPENAI_EMB_DEPLOYMENT_CAPACITY}" }, + "embeddingDeploymentSkuName":{ + "value": "${AZURE_OPENAI_EMB_DEPLOYMENT_SKU=Standard}" + }, "embeddingDimensions": { "value": "${AZURE_OPENAI_EMB_DIMENSIONS}" }, + "gpt4vModelName": { + "value": "${AZURE_OPENAI_GPT4V_MODEL_NAME=gpt-4o}" + }, + "gpt4vDeploymentName": { + "value": "${AZURE_OPENAI_GPT4V_DEPLOYMENT=gpt-4o}" + }, + "gpt4vDeploymentVersion":{ + "value": "${AZURE_OPENAI_GPT4V_DEPLOYMENT_VERSION=2024-05-13}" + }, "gpt4vDeploymentCapacity":{ "value": "${AZURE_OPENAI_GPT4V_DEPLOYMENT_CAPACITY=10}" }, + "gpt4vDeploymentSkuName":{ + "value": "${AZURE_OPENAI_GPT4V_DEPLOYMENT_SKU=GlobalStandard}" + }, "openAiHost": { "value": "${OPENAI_HOST=azure}" }, @@ -153,7 +171,7 @@ "value": "${USE_VECTORS=true}" }, "useGPT4V": { - "value": "${USE_GPT4V=false}" + "value": "${USE_GPT4V=true}" }, "enableLanguagePicker": { "value": "${ENABLE_LANGUAGE_PICKER=false}" From 48742e44ab6766b7746b5753d99c8664b918e833 Mon Sep 17 00:00:00 2001 From: Zhijie Huang Date: Wed, 9 Oct 2024 10:27:14 +0000 Subject: [PATCH 2/5] add pre-down hooks to unblock azd down --- .devcontainer/devcontainer.json | 2 +- azure.yaml | 9 +++++++++ requirements-dev.txt | 1 + scripts/pre-down.ps1 | 10 ++++++++++ scripts/pre-down.py | 32 ++++++++++++++++++++++++++++++++ scripts/pre-down.sh | 12 ++++++++++++ 6 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 scripts/pre-down.ps1 create mode 100644 scripts/pre-down.py create mode 100755 scripts/pre-down.sh diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index c025b04874..de4c7bdd81 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -23,7 +23,7 @@ "forwardPorts": [ 50505 ], - "postCreateCommand": "", + "postCreateCommand": "python3 -m pip install -r requirements-dev.txt", "remoteUser": "vscode", "hostRequirements": { "memory": "8gb" diff --git a/azure.yaml b/azure.yaml index b689b42a2e..00fde6f81f 100644 --- a/azure.yaml +++ b/azure.yaml @@ -132,3 +132,12 @@ hooks: run: ./scripts/auth_update.sh;./scripts/prepdocs.sh interactive: true continueOnError: false + predown: + windows: + shell: pwsh + run: ./scripts/pre-down.ps1 + continueOnError: true + posix: + shell: sh + run: ./scripts/pre-down.sh + continueOnError: true diff --git a/requirements-dev.txt b/requirements-dev.txt index d115c1000a..49c21f5380 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,4 +1,5 @@ -r app/backend/requirements.txt +azure-mgmt-cognitiveservices ruff black pytest diff --git a/scripts/pre-down.ps1 b/scripts/pre-down.ps1 new file mode 100644 index 0000000000..7951e9a0c7 --- /dev/null +++ b/scripts/pre-down.ps1 @@ -0,0 +1,10 @@ +# Get the directory of the current script +$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Definition + +# Load environment variables from azd env +$subscriptionId = azd env get-value AZURE_SUBSCRIPTION_ID +$resourceName = azd env get-value AZURE_OPENAI_SERVICE +$resourceGroup = azd env get-value AZURE_OPENAI_RESOURCE_GROUP + +# Run the Python script with the retrieved values +python "$scriptDir/pre-down.py" --subscription-id $subscriptionId --resource-name $resourceName --resource-group $resourceGroup diff --git a/scripts/pre-down.py b/scripts/pre-down.py new file mode 100644 index 0000000000..abbd504d73 --- /dev/null +++ b/scripts/pre-down.py @@ -0,0 +1,32 @@ +import argparse + +from azure.identity import DefaultAzureCredential +from azure.mgmt.cognitiveservices import CognitiveServicesManagementClient + +# Set up argument parsing +parser = argparse.ArgumentParser(description="Delete an Azure OpenAI deployment.") +parser.add_argument("--resource-name", required=True, help="The name of the Azure OpenAI resource.") +parser.add_argument("--resource-group", required=True, help="The name of the Azure resource group.") +parser.add_argument("--subscription-id", required=True, help="The Azure subscription ID.") + +args = parser.parse_args() + +# Authenticate using DefaultAzureCredential +credential = DefaultAzureCredential() + +# Initialize the Cognitive Services client +client = CognitiveServicesManagementClient(credential, subscription_id=args.subscription_id) + +# List all deployments +deployments = client.deployments.list( + resource_group_name=args.resource_group, account_name=args.resource_name +) + +# Delete each deployment and wait for the operation to complete +for deployment in deployments: + deployment_name = deployment.name + poller = client.deployments.begin_delete( + resource_group_name=args.resource_group, account_name=args.resource_name, deployment_name=deployment_name + ) + poller.result() + print(f"Deployment {deployment_name} deleted successfully.") diff --git a/scripts/pre-down.sh b/scripts/pre-down.sh new file mode 100755 index 0000000000..a0a16b25aa --- /dev/null +++ b/scripts/pre-down.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +# Get the directory of the current script +script_dir=$(dirname "$0") + +# Load environment variables from azd env +subscription_id=$(azd env get-value AZURE_SUBSCRIPTION_ID) +resource_name=$(azd env get-value AZURE_OPENAI_SERVICE) +resource_group=$(azd env get-value AZURE_OPENAI_RESOURCE_GROUP) + +# Run the Python script with the retrieved values +python "$script_dir/pre-down.py" --subscription-id $subscription_id --resource-name $resource_name --resource-group $resource_group From 9853755d5d332f8299e1a2e57eb3d5ccbc1e5abb Mon Sep 17 00:00:00 2001 From: Zhijie Huang Date: Wed, 9 Oct 2024 10:28:14 +0000 Subject: [PATCH 3/5] revert useGPT4V to false --- infra/main.bicep | 2 +- infra/main.parameters.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/infra/main.bicep b/infra/main.bicep index b3c22cddf9..f9bafe3642 100644 --- a/infra/main.bicep +++ b/infra/main.bicep @@ -57,7 +57,7 @@ param speechServiceResourceGroupName string = '' param speechServiceLocation string = '' param speechServiceName string = '' param speechServiceSkuName string // Set in main.parameters.json -param useGPT4V bool = true +param useGPT4V bool = false @description('Location for the OpenAI resource group') @allowed([ diff --git a/infra/main.parameters.json b/infra/main.parameters.json index 8001634f41..1b54af49e4 100644 --- a/infra/main.parameters.json +++ b/infra/main.parameters.json @@ -171,7 +171,7 @@ "value": "${USE_VECTORS=true}" }, "useGPT4V": { - "value": "${USE_GPT4V=true}" + "value": "${USE_GPT4V=false}" }, "enableLanguagePicker": { "value": "${ENABLE_LANGUAGE_PICKER=false}" From 7819991de0060cdf239daab9730e6dd6c7736f81 Mon Sep 17 00:00:00 2001 From: Zhijie Huang Date: Wed, 9 Oct 2024 10:57:03 +0000 Subject: [PATCH 4/5] fix mypy error --- scripts/pre-down.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/pre-down.py b/scripts/pre-down.py index abbd504d73..25d1a4d16d 100644 --- a/scripts/pre-down.py +++ b/scripts/pre-down.py @@ -25,6 +25,8 @@ # Delete each deployment and wait for the operation to complete for deployment in deployments: deployment_name = deployment.name + if not deployment_name: + continue poller = client.deployments.begin_delete( resource_group_name=args.resource_group, account_name=args.resource_name, deployment_name=deployment_name ) From ae5bfd47c4f3c70ff903f43f98e0a968d76d725f Mon Sep 17 00:00:00 2001 From: Zhijie Huang Date: Wed, 9 Oct 2024 11:00:31 +0000 Subject: [PATCH 5/5] format with black --- scripts/pre-down.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/scripts/pre-down.py b/scripts/pre-down.py index 25d1a4d16d..17fe8e5bd2 100644 --- a/scripts/pre-down.py +++ b/scripts/pre-down.py @@ -18,9 +18,7 @@ client = CognitiveServicesManagementClient(credential, subscription_id=args.subscription_id) # List all deployments -deployments = client.deployments.list( - resource_group_name=args.resource_group, account_name=args.resource_name -) +deployments = client.deployments.list(resource_group_name=args.resource_group, account_name=args.resource_name) # Delete each deployment and wait for the operation to complete for deployment in deployments: