Quickstart: Integrate Azure OpenAI

Note

Azure Spring Apps is the new name for the Azure Spring Cloud service. Although the service has a new name, you'll see the old name in some places for a while as we work to update assets such as screenshots, videos, and diagrams.

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

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:

  1. 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>   
    
  2. Use the following commands to create the model deployments for text-embedding-ada-002 and gpt-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.

  1. 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
    
  2. 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
    
  3. 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)
    
  4. 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)
    
  5. 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
    
  6. Now, test the Fitness Store application in the browser. Select ASK TO FITASSIST to converse with the Assist Service application.

    Screenshot that shows the ASK TO FITASSIST button.

  7. In FitAssist, enter I need a bike for a commute to work and observe the output that was generated by the Assist Service application:

    Screenshot that shows the 'I need a bike for a commute to work' query and the response from the Fitness Store assistant.

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: