Skip to content

Commit

Permalink
added production deployment section on README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
dantelmomsft committed May 2, 2024
1 parent e263577 commit 99cd148
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 0 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,10 @@ Below you can find the list of available implementations.
| Chat | [JavaSemanticKernelChainsApproach](https://github.com/Azure-Samples/azure-search-openai-demo-java/blob/main/app/backend/src/main/java/com/microsoft/openai/samples/rag/chat/approaches/semantickernel/JavaSemanticKernelChainsChatApproach.java) | Use Java Semantic Kernel framework with semantic and native functions chaining. It uses an imperative style for AI orchestration through semantic kernel functions chaining. [InformationFinder.SearchFromConversation](https://github.com/Azure-Samples/azure-search-openai-demo-java/blob/main/app/backend/src/main/java/com/microsoft/openai/samples/rag/retrieval/semantickernel/CognitiveSearchPlugin.java) native function and [RAG.AnswerConversation](https://github.com/Azure-Samples/azure-search-openai-demo-java/blob/main/app/backend/src/main/resources/semantickernel/Plugins/RAG/AnswerConversation/config.json) semantic function are called sequentially. Several search retrieval options are available: Text, Vector, Hybrid. | :x: | :white_check_mark: |


## Production Deployment on Azure Applciation Landing Zones

This sample is designed to get you started quickly and let you experiment with Java intelligent Apps RAG architectures on Azure.For production deployment, you can use the [Azure Application Landing Zones (LZA)](https://learn.microsoft.com/en-us/azure/cloud-adoption-framework/scenarios/app-platform/ready) to deploy the solution maintaining best practices for security, monitoring, networking and operational excellence.

Check the [chat-with-your-data-lza-app-accelerator](https://github.com/dantelmomsft/chat-with-your-data-java-lza-app-accelerator) to see how you can deploy this solution on App Service LZA or Azure Container Apps LZA.

![Azure Container Apps LZA deployment](docs/aca/aca-internal-java-ai.png)
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public ChatCompletions getChatCompletions(ChatCompletionsOptions chatCompletions
e.getResponse().getStatusCode(),
"Error calling OpenAI API:" + e.getMessage(),
e);
// ((Map)((Map)e.getValue()).get("error")).get("message")
}
return chatCompletions;
}
Expand Down
51 changes: 51 additions & 0 deletions deploy/aca/compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
services:
frontend:
image: ai-chat-reference-java/frontend
build: ./frontend
environment:
REACT_APP_API_BASE_URL: "http://backend:8080"
ports:
- "80:80"
backend:
image: ai-chat-reference-java/backend
build: ./backend
environment:
- AZURE_STORAGE_ACCOUNT=${AZURE_STORAGE_ACCOUNT}
- AZURE_STORAGE_CONTAINER=${AZURE_STORAGE_CONTAINER}
- AZURE_SEARCH_INDEX=${AZURE_SEARCH_INDEX}
- AZURE_SEARCH_SERVICE=${AZURE_SEARCH_SERVICE}
- AZURE_SEARCH_QUERY_LANGUAGE=${AZURE_SEARCH_QUERY_LANGUAGE}
- AZURE_SEARCH_QUERY_SPELLER=${AZURE_SEARCH_QUERY_SPELLER}
- AZURE_OPENAI_EMB_MODEL_NAME=${AZURE_OPENAI_EMB_MODEL_NAME}
- AZURE_OPENAI_EMB_DEPLOYMENT=${AZURE_OPENAI_EMB_DEPLOYMENT}
- AZURE_OPENAI_CHATGPT_MODEL=${AZURE_OPENAI_CHATGPT_MODEL}
- AZURE_OPENAI_SERVICE=${AZURE_OPENAI_SERVICE}
- AZURE_OPENAI_CHATGPT_DEPLOYMENT=${AZURE_OPENAI_CHATGPT_DEPLOYMENT}
- spring_profiles_active=docker
- AZURE_CLIENT_ID=${servicePrincipal}
- AZURE_CLIENT_SECRET=${servicePrincipalPassword}
- AZURE_TENANT_ID=${servicePrincipalTenant}
ports:
- "8080:8080"
indexer:
image: ai-chat-reference-java/indexer
build:
context: ./indexer
dockerfile: microservice/Dockerfile
environment:
- AZURE_STORAGE_ACCOUNT=${AZURE_STORAGE_ACCOUNT}
- AZURE_STORAGE_CONTAINER=${AZURE_STORAGE_CONTAINER}
- AZURE_SEARCH_INDEX=${AZURE_SEARCH_INDEX}
- AZURE_SEARCH_SERVICE=${AZURE_SEARCH_SERVICE}
- AZURE_FORMRECOGNIZER_SERVICE=${AZURE_FORMRECOGNIZER_SERVICE}
- AZURE_SEARCH_QUERY_SPELLER=${AZURE_SEARCH_QUERY_SPELLER}
- AZURE_OPENAI_EMB_MODEL_NAME=${AZURE_OPENAI_EMB_MODEL_NAME}
- AZURE_OPENAI_EMB_DEPLOYMENT=${AZURE_OPENAI_EMB_DEPLOYMENT}
- AZURE_OPENAI_SERVICE=${AZURE_OPENAI_SERVICE}
- AZURE_SERVICEBUS_NAMESPACE=${AZURE_SERVICEBUS_NAMESPACE}
- spring_profiles_active=docker
- SPRING_CONFIG_LOCATION=classpath:/local-dev.properties
- AZURE_CLIENT_ID=${servicePrincipal}
- AZURE_CLIENT_SECRET=${servicePrincipalPassword}
- AZURE_TENANT_ID=${servicePrincipalTenant}

63 changes: 63 additions & 0 deletions deploy/aca/start-compose.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
echo ""
echo "Loading azd .env file from current environment"
echo ""

while IFS='=' read -r key value; do
value=$(echo "$value" | sed 's/^"//' | sed 's/"$//')
export "$key=$value"
echo "export $key=$value"
done <<EOF
$(azd env get-values)
EOF

if [ $? -ne 0 ]; then
echo "Failed to load environment variables from azd environment"
exit $?
fi

echo ""
echo "Checking Service Principal and get password"
echo ""

roles=(
"5e0bd9bd-7b93-4f28-af87-19fc36ad61bd"
"a97b65f3-24c7-4388-baec-2e87135dc908"
"2a2b9908-6ea1-4ae2-8e65-a410df84e7d1"
"ba92f5b4-2d11-453d-a403-e96b0029c9fe"
"1407120a-92aa-4202-b7e9-c0e197c71c8f"
"8ebe5a00-799e-43f5-93ac-243d3dce84a7"
"7ca78c08-252a-4471-8644-bb5ff32d4ba0"
"4f6d3b9b-027b-4f4c-9142-0e5a2a2247e0"
)

#Check if service principal exists
export servicePrincipal=$(az ad sp list --display-name "azure-ai-chat-java-spi" --query [].appId --output tsv)

if [ -z "$servicePrincipal" ]; then
echo "Service principal not found. Creating service principal"
export servicePrincipal=$(az ad sp create-for-rbac --name "azure-ai-chat-java-spi" --role reader --scopes /subscriptions/"$AZURE_SUBSCRIPTION_ID"/resourceGroups/"$AZURE_RESOURCE_GROUP" --query appId --output tsv)
if [ $? -ne 0 ]; then
echo "Failed to create service principal"
exit $?
fi
export servicePrincipalObjectId=$(az ad sp show --id "$servicePrincipal" --query id --output tsv)
echo "Assigning Roles to service principal azure-ai-chat-java-spi with principal id:$servicePrincipal and object id[$servicePrincipalObjectId]"
for role in "${roles[@]}"; do

echo "Assigning Role[$role] to principal id[$servicePrincipal] for resource[/subscriptions/"$AZURE_SUBSCRIPTION_ID"/resourceGroups/"$AZURE_RESOURCE_GROUP"] "
az role assignment create \
--role "$role" \
--assignee-object-id "$servicePrincipalObjectId" \
--scope /subscriptions/"$AZURE_SUBSCRIPTION_ID"/resourceGroups/"$AZURE_RESOURCE_GROUP" \
--assignee-principal-type ServicePrincipal
done
fi

export servicePrincipalPassword=$(az ad sp credential reset --id "$servicePrincipal" --query password --output tsv)
export servicePrincipalTenant=$(az ad sp show --id "$servicePrincipal" --query appOwnerOrganizationId --output tsv)

echo ""
echo "Starting solution locally using docker compose. "
echo ""

docker compose -f ./compose.yaml up
Binary file added docs/aca/aca-internal-java-ai.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 99cd148

Please sign in to comment.