Skip to content

Commit

Permalink
Set Azure OpenAI API version in global configuration (#1399)
Browse files Browse the repository at this point in the history
* Set Azure OpenAI API version in global configuration

* Add Variable to CI Configurations

* Set the latest API version as the default value for the variable.

* Update app/backend/app.py

* Add output for Azure OpenAI API version.

* Update app/backend/app.py

---------

Co-authored-by: Pamela Fox <[email protected]>
Co-authored-by: Pamela Fox <[email protected]>
  • Loading branch information
3 people authored Mar 12, 2024
1 parent 648d438 commit 89503ad
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions .azdo/pipelines/azure-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ steps:
AZURE_LOCATION: $(AZURE_LOCATION)
AZD_INITIAL_ENVIRONMENT_CONFIG: $(AZD_INITIAL_ENVIRONMENT_CONFIG)
AZURE_OPENAI_SERVICE: $(AZURE_OPENAI_SERVICE)
AZURE_OPENAI_API_VERSION: $(AZURE_OPENAI_API_VERSION)
AZURE_OPENAI_RESOURCE_GROUP: $(AZURE_OPENAI_RESOURCE_GROUP)
AZURE_FORMRECOGNIZER_SERVICE: $(AZURE_FORMRECOGNIZER_SERVICE)
AZURE_FORMRECOGNIZER_RESOURCE_GROUP: $(AZURE_FORMRECOGNIZER_RESOURCE_GROUP)
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/azure-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ jobs:
AZURE_LOCATION: ${{ vars.AZURE_LOCATION }}
# project specific
AZURE_OPENAI_SERVICE: ${{ vars.AZURE_OPENAI_SERVICE }}
AZURE_OPENAI_API_VERSION: ${{ vars.AZURE_OPENAI_API_VERSION }}
AZURE_OPENAI_RESOURCE_GROUP: ${{ vars.AZURE_OPENAI_RESOURCE_GROUP }}
AZURE_FORMRECOGNIZER_SERVICE: ${{ vars.AZURE_FORMRECOGNIZER_SERVICE }}
AZURE_FORMRECOGNIZER_RESOURCE_GROUP: ${{ vars.AZURE_FORMRECOGNIZER_RESOURCE_GROUP }}
Expand Down
5 changes: 3 additions & 2 deletions app/backend/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,9 +308,10 @@ async def setup_clients():
else:
endpoint = f"https://{AZURE_OPENAI_SERVICE}.openai.azure.com"

# Store on app.config for later use inside requests
api_version = os.getenv("AZURE_OPENAI_API_VERSION") or "2024-03-01-preview"

openai_client = AsyncAzureOpenAI(
api_version="2023-07-01-preview",
api_version=api_version,
azure_endpoint=endpoint,
azure_ad_token_provider=token_provider,
)
Expand Down
1 change: 1 addition & 0 deletions azure.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ services:
pipeline:
variables:
- AZURE_OPENAI_SERVICE
- AZURE_OPENAI_API_VERSION
- AZURE_OPENAI_RESOURCE_GROUP
- AZURE_FORMRECOGNIZER_SERVICE
- AZURE_FORMRECOGNIZER_RESOURCE_GROUP
Expand Down
3 changes: 3 additions & 0 deletions infra/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ param appServiceSkuName string // Set in main.parameters.json
param openAiHost string // Set in main.parameters.json
param isAzureOpenAiHost bool = startsWith(openAiHost, 'azure')
param azureOpenAiCustomUrl string = ''
param azureOpenAiApiVersion string = ''

param openAiServiceName string = ''
param openAiResourceGroupName string = ''
Expand Down Expand Up @@ -244,6 +245,7 @@ module backend 'core/host/appservice.bicep' = {
// Shared by all OpenAI deployments
OPENAI_HOST: openAiHost
AZURE_OPENAI_CUSTOM_URL: azureOpenAiCustomUrl
AZURE_OPENAI_API_VERSION: azureOpenAiApiVersion
AZURE_OPENAI_EMB_MODEL_NAME: embeddingModelName
AZURE_OPENAI_CHATGPT_MODEL: chatGptModelName
AZURE_OPENAI_GPT4V_MODEL: gpt4vModelName
Expand Down Expand Up @@ -598,6 +600,7 @@ output AZURE_OPENAI_GPT4V_MODEL string = gpt4vModelName

// Specific to Azure OpenAI
output AZURE_OPENAI_SERVICE string = isAzureOpenAiHost ? openAi.outputs.name : ''
output AZURE_OPENAI_API_VERSION string = isAzureOpenAiHost ? azureOpenAiApiVersion : ''
output AZURE_OPENAI_RESOURCE_GROUP string = isAzureOpenAiHost ? openAiResourceGroup.name : ''
output AZURE_OPENAI_CHATGPT_DEPLOYMENT string = isAzureOpenAiHost ? chatGptDeploymentName : ''
output AZURE_OPENAI_EMB_DEPLOYMENT string = isAzureOpenAiHost ? embeddingDeploymentName : ''
Expand Down
3 changes: 3 additions & 0 deletions infra/main.parameters.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@
"azureOpenAiCustomUrl":{
"value": "${AZURE_OPENAI_CUSTOM_URL}"
},
"azureOpenAiApiVersion":{
"value": "${AZURE_OPENAI_API_VERSION}"
},
"openAiApiKey": {
"value": "${OPENAI_API_KEY}"
},
Expand Down

0 comments on commit 89503ad

Please sign in to comment.