Skip to content

CawaMS/OutputCacheOpenAI

Repository files navigation

.NET 8 Web Application with Redis Output Caching and Azure Open AI

Overview

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

To experiment with the demo:

  1. 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.
  2. call the /cached/ endpoint with your command prompt. Refresh the browser. Observe that the output picture does not change and refresh finishes instantly.
  3. 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

Output Cache: a purple robot in the cloud

Figure 2: /semanticcache/ endpoint for "a french garden in monet style"

semantic cache: 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.

semantic cache: a monet style french garden

Run the application in Azure

Prerequisites:

  1. Open a command prompt
  2. Change directory to the project folder where azure.yaml file is located
  3. Make sure docker is running
  4. Run:
    azd up
    
  5. Follow command prompt to enter environment name and select subscription
  6. 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
  1. To clean up the environment, run
    azd down
    

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published