Quickstart: Integrate Azure OpenAI
Note
The Basic, Standard, and Enterprise plans will be deprecated starting from mid-March, 2025, with a 3 year retirement period. We recommend transitioning to Azure Container Apps. For more information, see the Azure Spring Apps retirement announcement.
The Standard consumption and dedicated plan will be deprecated starting September 30, 2024, with a complete shutdown after six months. We recommend transitioning to Azure Container Apps. For more information, see Migrate Azure Spring Apps Standard consumption and dedicated plan to Azure Container Apps.
This article applies to: ❌ Basic/Standard ✔️ Enterprise
This quickstart shows you how to integrate Azure OpenAI with applications deployed on the Azure Spring Apps Enterprise plan.
Azure OpenAI enables your applications to take advantage of large-scale, generative AI models with deep understandings of language and code to enable new reasoning and comprehension capabilities.
The following video shows how Azure Spring Apps uses Azure OpenAI to build intelligent applications:
Prerequisites
- An Azure account with an active subscription. Create an account for free.
- Access granted to Azure OpenAI. For more information, see Request Access to Azure OpenAI Service.
- Understand and fulfill the Requirements section of Enterprise plan in Azure Marketplace.
- The Azure CLI version 2.45.0 or higher.
- Git.
- jq
-
The Azure Spring Apps Enterprise plan extension. Use the following command to remove previous versions and install the latest Enterprise plan extension. If you previously installed the
spring-cloud
extension, uninstall it to avoid configuration and version mismatches.az extension add --upgrade --name spring az extension remove --name spring-cloud
- Complete the steps in Build and deploy apps to Azure Spring Apps using the Enterprise plan.
Provision Azure OpenAI
To add AI to the application, create an Azure OpenAI account and deploy language models. The following steps describe how to provision an Azure OpenAI account and deploy language models using the Azure CLI:
Use the following command to create an Azure OpenAI account:
az cognitiveservices account create \ --resource-group <resource-group-name> \ --name <open-ai-service-name> \ --location <region> \ --kind OpenAI \ --sku s0 \ --custom-domain <open-ai-service-name>
Use the following commands to create the model deployments for
text-embedding-ada-002
andgpt-35-turbo-16k
in your Azure OpenAI service instance:az cognitiveservices account deployment create \ --resource-group <resource-group-name> \ --name <open-ai-service-name> \ --deployment-name text-embedding-ada-002 \ --model-name text-embedding-ada-002 \ --model-version "2" \ --model-format OpenAI \ --sku-name "Standard" \ --sku-capacity 1 az cognitiveservices account deployment create \ --resource-group <resource-group-name> \ --name <open-ai-service-name> \ --deployment-name gpt-35-turbo-16k \ --model-name gpt-35-turbo-16k \ --model-version "0613" \ --model-format OpenAI \ --sku-name "Standard" \ --sku-capacity 1
Deploy Assist Service to Azure Spring Apps
Use the following steps to create, configure, and deploy the Assist Service application to Azure Spring Apps.
Use the following command to create the new AI service,
assist-service
:az spring app create \ --resource-group <resource-group-name> \ --name assist-service \ --service <Azure-Spring-Apps-service-instance-name> \ --instance-count 1 \ --memory 1Gi
Use the following command to configure Spring Cloud Gateway with the Assist Service route:
az spring gateway route-config create \ --resource-group <resource-group-name> \ --service <Azure-Spring-Apps-service-instance-name> \ --name assist-routes \ --app-name assist-service \ --routes-file azure-spring-apps-enterprise/resources/json/routes/assist-service.json
Use the following command to retrieve the REST API endpoint base URL for the Azure OpenAI service:
export SPRING_AI_AZURE_OPENAI_ENDPOINT=$(az cognitiveservices account show \ --name <open-ai-service-name> \ --resource-group <resource-group-name> \ | jq -r .properties.endpoint)
Use the following command to retrieve the primary API key:
export SPRING_AI_AZURE_OPENAI_APIKEY=$(az cognitiveservices account keys list \ --name <open-ai-service-name> \ --resource-group <resource-group-name> \ | jq -r .key1)
Use the following command to deploy the Assist Service application:
az spring app deploy --resource-group <resource-group-name> \ --name assist-service \ --service <Azure-Spring-Apps-service-instance-name> \ --source-path apps/acme-assist \ --build-env BP_JVM_VERSION=17 \ --env \ SPRING_AI_AZURE_OPENAI_ENDPOINT=${SPRING_AI_AZURE_OPENAI_ENDPOINT} \ SPRING_AI_AZURE_OPENAI_APIKEY=${SPRING_AI_AZURE_OPENAI_APIKEY} \ SPRING_AI_AZURE_OPENAI_MODEL=gpt-35-turbo-16k \ SPRING_AI_AZURE_OPENAI_EMBEDDINGMODEL=text-embedding-ada-002
Now, test the Fitness Store application in the browser. Select ASK TO FITASSIST to converse with the Assist Service application.
In FitAssist, enter I need a bike for a commute to work and observe the output that was generated by the Assist Service application:
Clean up resources
If you plan to continue working with subsequent quickstarts and tutorials, you might want to leave these resources in place. When no longer needed, delete the resource group, which deletes the resources in the resource group. To delete the resource group by using Azure CLI, use the following commands:
echo "Enter the Resource Group name:" &&
read resourceGroupName &&
az group delete --name $resourceGroupName &&
echo "Press [ENTER] to continue ..."
Next steps
Continue on to any of the following optional quickstarts: