Azure-Samples / acme-fitness-store

Sample - how to deploy Spring Boot apps to Azure?
https://docs.microsoft.com/en-us/azure/spring-cloud/overview
MIT License
84 stars 157 forks source link

Enable incremental product embedding #207

Closed dingmeng-xue closed 4 months ago

dingmeng-xue commented 4 months ago

The command to deploy the job is like:

az spring job deploy --name assist-job \
    --source-path apps/acme-assist \
    --build-env BP_JVM_VERSION=17 \
    --build-env BP_MAVEN_ACTIVE_PROFILES=job \
    --env \
        SPRING_AI_AZURE_OPENAI_ENDPOINT=${SPRING_AI_AZURE_OPENAI_ENDPOINT} \
        SPRING_AI_AZURE_OPENAI_API_KEY=${SPRING_AI_AZURE_OPENAI_API_KEY}

Steps to go through this change:

  1. Update the Spring Cloud Gateway routing rules for catalog service, assist service.

  2. Add a new product, you can enrich the short description and description

    curl --location 'https://xiada-fitness-store-gateway-fa329.svc.azuremicroservices.io/products' \
    --header 'Content-Type: application/json' \
    --data '{
       "imageUrl1": "url1",
       "imageUrl2": "url2",
       "imageUrl3": "url3",
       "name": "xiada",
       "shortDescription": "short desc",
       "description": "desc",
       "price": 299.99,
       "tags": [
           "a",
           "b",
           "c"
       ]
    }'
  3. Update the product, this is optional

    curl --location 'https://xiada-fitness-store-gateway-fa329.svc.azuremicroservices.io/products/07e5785e-c844-41ca-b4cb-d1dfa0a1d383' \
    --header 'Content-Type: application/json' \
    --data '{
       "imageUrl1": "https://www.shutterstock.com/shutterstock/photos/2272933579/display_1500/stock-vector-captain-america-logo-art-design-template-white-background-isolated-2272933579.jpg",
       "imageUrl2": "https://www.shutterstock.com/shutterstock/photos/2272933579/display_1500/stock-vector-captain-america-logo-art-design-template-white-background-isolated-2272933579.jpg",
       "imageUrl3": "https://www.shutterstock.com/shutterstock/photos/2272933579/display_1500/stock-vector-captain-america-logo-art-design-template-white-background-isolated-2272933579.jpg",
       "shortDescription": "this is the short description for the product xiada, and it'\''s the best for hiking",
       "description": "xiada likes hiking, and it can be used in different places"
    }'
  4. Deploy the assist-service, call the list product ids to index. You can see the newly added product is in the returned values.

    curl --location 'https://xiada-fitness-store-gateway-fa329.svc.azuremicroservices.io/ai/admin/products-to-index'
  5. Create and deploy the job, make sure setting the BP_MAVEN_ACTIVE_PROFILES env

    az spring job deploy --name assist-job \
       --source-path apps/acme-assist \
       --build-env BP_JVM_VERSION=17 \
       --build-env BP_MAVEN_ACTIVE_PROFILES=job \
       --env \
           SPRING_AI_AZURE_OPENAI_ENDPOINT=${SPRING_AI_AZURE_OPENAI_ENDPOINT} \
           SPRING_AI_AZURE_OPENAI_API_KEY=${SPRING_AI_AZURE_OPENAI_API_KEY}

Additional change is to unify parameter name SPRING_AI_AZURE_OPENAI_API_KEY and SPRING_AI_AZURE_OPENAI_APIKEY. Use SPRING_AI_AZURE_OPENAI_API_KEY as it is used by Spring AI doc.