-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #194 from ms-johnalex/refactor-config-openai1
Refactored chat.py to use ChainedTokenCredential
- Loading branch information
Showing
17 changed files
with
303 additions
and
201 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
AZURE_OPENAI_API_VERSION="2024-02-15-preview" | ||
AZURE_OPENAI_ENDPOINT="https://YOUR-ENDPOINT-HERE.openai.azure.com/" | ||
# Name of the Azure OpenAI GPT deployment (different from the model name) | ||
AZURE_OPENAI_CHATGPT_DEPLOYMENT=chatgpt | ||
AZURE_OPENAI_CHAT_DEPLOYMENT=gpt4o-mini |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
-r src/requirements.txt | ||
azure-mgmt-cognitiveservices | ||
black | ||
ruff | ||
pre-commit | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# 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_RESOURCE_NAME | ||
$resourceGroup = azd env get-value AZURE_OPENAI_RESOURCE_GROUP | ||
$deploymentName = azd env get-value AZURE_OPENAI_CHAT_DEPLOYMENT | ||
|
||
# Run the Python script with the retrieved values | ||
python "$scriptDir/pre-down.py" --subscription-id $subscriptionId --resource-name $resourceName --resource-group $resourceGroup --deployment-name $deploymentName |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import argparse | ||
|
||
import azure.core.exceptions | ||
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("--deployment-name", required=True, help="The name of the deployment to delete.") | ||
parser.add_argument("--subscription-id", required=True, help="The Azure subscription ID.") | ||
|
||
print("Pre-down OpenAI script starting.") | ||
|
||
args = parser.parse_args() | ||
|
||
# Authenticate using DefaultAzureCredential | ||
credential = DefaultAzureCredential() | ||
|
||
# Initialize the Cognitive Services client | ||
client = CognitiveServicesManagementClient(credential, subscription_id=args.subscription_id) | ||
try: | ||
# Begin delete the deployment | ||
poller = client.deployments.begin_delete( | ||
resource_group_name=args.resource_group, account_name=args.resource_name, deployment_name=args.deployment_name | ||
) | ||
except azure.core.exceptions.ResourceNotFoundError: | ||
print(f"Deployment {args.deployment_name} not found.") | ||
exit(0) | ||
|
||
# Wait for the delete operation to complete | ||
poller.result() | ||
|
||
print(f"Deployment {args.deployment_name} deleted successfully.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/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_RESOURCE_NAME) | ||
resource_group=$(azd env get-value AZURE_OPENAI_RESOURCE_GROUP) | ||
deployment_name=$(azd env get-value AZURE_OPENAI_CHAT_DEPLOYMENT) | ||
|
||
# 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 --deployment-name $deployment_name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.