From 331ddb5bb5e69e812cd37164b4f9cbf25b3068cf Mon Sep 17 00:00:00 2001 From: Stephen Toub Date: Tue, 8 Oct 2024 16:55:12 -0400 Subject: [PATCH] Improve registration of IDistributedCache in READMEs (#5480) --- .../Microsoft.Extensions.AI.Abstractions/README.md | 7 +------ .../Microsoft.Extensions.AI.AzureAIInference/README.md | 5 +---- src/Libraries/Microsoft.Extensions.AI.Ollama/README.md | 5 +---- src/Libraries/Microsoft.Extensions.AI.OpenAI/README.md | 5 +---- 4 files changed, 4 insertions(+), 18 deletions(-) diff --git a/src/Libraries/Microsoft.Extensions.AI.Abstractions/README.md b/src/Libraries/Microsoft.Extensions.AI.Abstractions/README.md index eb9d3a28c6f..4cacbda0a4f 100644 --- a/src/Libraries/Microsoft.Extensions.AI.Abstractions/README.md +++ b/src/Libraries/Microsoft.Extensions.AI.Abstractions/README.md @@ -317,17 +317,12 @@ await client.CompleteAsync("Hello, world!"); ```csharp using Microsoft.Extensions.AI; -using Microsoft.Extensions.Caching.Distributed; -using Microsoft.Extensions.Caching.Memory; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; -using Microsoft.Extensions.Options; -using System.Runtime.CompilerServices; // App Setup var builder = Host.CreateApplicationBuilder(); -builder.Services.AddSingleton( - new MemoryDistributedCache(Options.Create(new MemoryDistributedCacheOptions()))); +builder.Services.AddDistributedMemoryCache(); builder.Services.AddChatClient(b => b .UseDistributedCache() .Use(new SampleChatClient(new Uri("http://coolsite.ai"), "my-custom-model"))); diff --git a/src/Libraries/Microsoft.Extensions.AI.AzureAIInference/README.md b/src/Libraries/Microsoft.Extensions.AI.AzureAIInference/README.md index 3fd34c7897b..f34e89a08fb 100644 --- a/src/Libraries/Microsoft.Extensions.AI.AzureAIInference/README.md +++ b/src/Libraries/Microsoft.Extensions.AI.AzureAIInference/README.md @@ -223,12 +223,9 @@ static int GetPersonAge(string personName) => using Azure; using Azure.AI.Inference; using Microsoft.Extensions.AI; -using Microsoft.Extensions.Caching.Distributed; -using Microsoft.Extensions.Caching.Memory; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Options; // App Setup var builder = Host.CreateApplicationBuilder(); @@ -236,7 +233,7 @@ builder.Services.AddSingleton( new ChatCompletionsClient( new("https://models.inference.ai.azure.com"), new AzureKeyCredential(Environment.GetEnvironmentVariable("GH_TOKEN")!))); -builder.Services.AddSingleton(new MemoryDistributedCache(Options.Create(new MemoryDistributedCacheOptions()))); +builder.Services.AddDistributedMemoryCache(); builder.Services.AddLogging(b => b.AddConsole().SetMinimumLevel(LogLevel.Trace)); builder.Services.AddChatClient(b => b diff --git a/src/Libraries/Microsoft.Extensions.AI.Ollama/README.md b/src/Libraries/Microsoft.Extensions.AI.Ollama/README.md index ef8c60ff7b2..3d2eddcafc1 100644 --- a/src/Libraries/Microsoft.Extensions.AI.Ollama/README.md +++ b/src/Libraries/Microsoft.Extensions.AI.Ollama/README.md @@ -226,16 +226,13 @@ foreach (var prompt in new[] { "What is AI?", "What is .NET?", "What is AI?" }) ```csharp using Microsoft.Extensions.AI; -using Microsoft.Extensions.Caching.Distributed; -using Microsoft.Extensions.Caching.Memory; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Options; // App Setup var builder = Host.CreateApplicationBuilder(); -builder.Services.AddSingleton(new MemoryDistributedCache(Options.Create(new MemoryDistributedCacheOptions()))); +builder.Services.AddDistributedMemoryCache(); builder.Services.AddLogging(b => b.AddConsole().SetMinimumLevel(LogLevel.Trace)); builder.Services.AddChatClient(b => b diff --git a/src/Libraries/Microsoft.Extensions.AI.OpenAI/README.md b/src/Libraries/Microsoft.Extensions.AI.OpenAI/README.md index f7af212f4d7..696cc0c01bf 100644 --- a/src/Libraries/Microsoft.Extensions.AI.OpenAI/README.md +++ b/src/Libraries/Microsoft.Extensions.AI.OpenAI/README.md @@ -249,18 +249,15 @@ foreach (var prompt in new[] { "What is AI?", "What is .NET?", "What is AI?" }) ```csharp using Microsoft.Extensions.AI; -using Microsoft.Extensions.Caching.Distributed; -using Microsoft.Extensions.Caching.Memory; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Options; using OpenAI; // App Setup var builder = Host.CreateApplicationBuilder(); builder.Services.AddSingleton(new OpenAIClient(Environment.GetEnvironmentVariable("OPENAI_API_KEY"))); -builder.Services.AddSingleton(new MemoryDistributedCache(Options.Create(new MemoryDistributedCacheOptions()))); +builder.Services.AddDistributedMemoryCache(); builder.Services.AddLogging(b => b.AddConsole().SetMinimumLevel(LogLevel.Trace)); builder.Services.AddChatClient(b => b