This application utilizes the following Azure resources:
- Azure Spring Apps to host the application
- Azure OpenAI for ChatGPT
- Azure Redis to save the conversation history for each user.
Here's a high level architecture diagram that illustrates these components. Notice that these are all contained within a single resource group, that will be created for you when you create the resources.
You can run this sample app using the Azure CLI by following these steps.
- JDK 17
- Maven
- Azure CLI
- An Azure subscription with access granted to Azure OpenAI (see more here)
-
Use the following commands to define variables for this quickstart with the names of your resources and desired settings:
LOCATION="eastus" RESOURCE_GROUP="<resource-group-name>" MANAGED_ENVIRONMENT="<Azure-Container-Apps-environment-name>" SERVICE_NAME="<Azure-Spring-Apps-instance-name>" APP_NAME="<Spring-app-name>" AZURE_OPENAI_RESOURCE_NAME="<Azure-OpenAI-resource-name>" CACHE="<Azure-Redis-Cache-Name>"
-
Use the following command to create a resource group:
az group create \ --resource-group ${RESOURCE_GROUP} \ --location ${LOCATION}
-
An Azure Container Apps environment creates a secure boundary around a group of applications. Apps deployed to the same environment are deployed in the same virtual network and write logs to the same log analytics workspace. For more information, see Log Analytics workspace overview. Use the following command to create the environment:
az containerapp env create \ --resource-group ${RESOURCE_GROUP} \ --name ${MANAGED_ENVIRONMENT} \ --location ${LOCATION} \ --enable-workload-profiles
-
Use the following command to create a variable to store the environment resource ID:
MANAGED_ENV_RESOURCE_ID=$(az containerapp env show \ --resource-group ${RESOURCE_GROUP} \ --name ${MANAGED_ENVIRONMENT} \ --query id \ --output tsv)
-
Use the following command to create an Azure Spring Apps service instance. An instance of the Azure Spring Apps Standard consumption and dedicated plan is built on top of the Azure Container Apps environment. Create your Azure Spring Apps instance by specifying the resource ID of the environment you created.
az spring create \ --resource-group ${RESOURCE_GROUP} \ --name ${SERVICE_NAME} \ --managed-environment ${MANAGED_ENV_RESOURCE_ID} \ --sku standardGen2 \ --location ${LOCATION}
-
Run the following command to create an Azure OpenAI resource in the the resource group.
az cognitiveservices account create \ -n ${AZURE_OPENAI_RESOURCE_NAME} \ -g ${RESOURCE_GROUP} \ -l ${LOCATION} \ --kind OpenAI \ --sku s0 \ --custom-domain ${AZURE_OPENAI_RESOURCE_NAME}
-
Create the model deployments for
text-embedding-ada-002
andgpt-35-turbo
in your Azure OpenAI service.az cognitiveservices account deployment create \ -g ${RESOURCE_GROUP} \ -n ${AZURE_OPENAI_RESOURCE_NAME} \ --deployment-name text-embedding-ada-002 \ --model-name text-embedding-ada-002 \ --model-version "2" \ --model-format OpenAI az cognitiveservices account deployment create \ -g ${RESOURCE_GROUP} \ -n ${AZURE_OPENAI_RESOURCE_NAME} \ --deployment-name gpt-35-turbo \ --model-name gpt-35-turbo \ --model-version "0301" \ --model-format OpenAI
-
Run the following command to create an Azure Cache for Redis in the resource group.
az redis create \ -g ${RESOURCE_GROUP} \ -n ${CACHE} \ -l ${LOCATION} \ --sku "basic" \ --vm-size "c0"
- Run
git clone https://github.com/rohanmukesh/spring-ai-azure-movee.git
- Run
cd spring-ai-azure-movee
. - Build with
./mvnw clean package -PProduction
.
Before running the web app, you need to preprocess the movies and load them into the vector store:
source env.sh
java -jar spring-ai-azure-movee/target/spring-ai-azure-movee-0.0.1-SNAPSHOT.jar --from=/<path>/<to>/<your>/<documents>
Or dowload the pre-built vector store of the public documents of the Azure Spring Apps.
To run the demo in the local machine, please follow these steps:
-
Launch the web app
./mvnw clean package source env.sh java -jar spring-ai-azure-movee/target/spring-ai-azure-movee-0.0.1-SNAPSHOT.jar
-
Open
http://localhost:8080
in your browser.
-
Use the following command to specify the app name on Azure Spring Apps and to allocate required resources:
az spring app create \ --resource-group ${RESOURCE_GROUP} \ --service ${SERVICE_NAME} \ --name ${APP_NAME} \ --cpu 2 \ --memory 4Gi \ --min-replicas 1 \ --max-replicas 1 \ --assign-endpoint true
-
Use the following command to deploy the .jar file for the app:
az spring app deploy \ --resource-group ${RESOURCE_GROUP} \ --service ${SERVICE_NAME} \ --name ${APP_NAME} \ --artifact-path target/spring-ai-azure-movee-0.0.1-SNAPSHOT.jar \ --runtime-version Java_17 --env AZURE_OPENAI_ENDPOINT=<your_azure_openai_endpoint> AZURE_OPENAI_APIKEY=<your_api_key> AZURE_OPENAI_CHATDEPLOYMENTID=gpt-35-turbo AZURE_OPENAI_EMBEDDINGDEPLOYMENTID=text-embedding-ada-002 \