This repository contains sample code for an AI image generation web application. It calls into Azure Open AI DallE to generate images based on user prompt. There are two features the sample highlights:
- It allows responses from the /cached/ endpoint to be saved in Azure Cache for Redis through the IOutputCache() abstraction.
- It uses semantic caching to cache responses from similar prompts using the Redis OM for .NET
Prerequisites:
- Azure subscription. Start free
- .NET 9. Download
- Docker. Get docker
- Azure Developer CLI. Install
NOTE: deploy this demo in the East US region to ensure both zonal support and Dall-E model available. DALL-E model for picture generation is only supported among East US, Australia East, or Sweden Central. Azure Cache for Redis needs a region with zonal support to work.
- Open a command prompt
- Change directory to the project folder where azure.yaml file is located
- Make sure docker is running
- Run:
azd up
- Follow command prompt to enter environment name and select subscription
- This will create all the resources needed to run the sample:
- Azure Container App instance and environment
- Azure Container Registry
- Azure Open AI service
- Azure Cache for Redis Enterprise
- Azure Key Vault
To experiment with the demo:
- call the /nocache/ endpoint with your command prompt. Refresh the browser. Observe that refresh takes a noticeable delay and a new picture will be generated.
- call the /cached/ endpoint with your command prompt. Refresh the browser. Observe that the output picture does not change and refresh finishes instantly.
- call the /semanticcache/ endpoint with your command prompt. Enter two similar prompts such as "a french garden in monet style" and "a monet style french garden". Observe that the outputs are cached.
Here are an example outputs:
Figure 1: /cached/ endpoint caches web response rendered output
Figure 2: /semanticcache/ endpoint for "a french garden in monet style"
Figure 3: /semanticcache/ endpoiont for "a monet style french garden". Observe with semantic caching, the output is the same as Figure 2 above.
- To clean up the environment, run
azd down