Skip to content

Commit 1c650e1

Browse files
Bump the dotnet group in /docs/core/extensions/snippets/ai/ConsoleAI.DependencyInjection with 4 updates (#45220)
* Bump the dotnet group Bumps the dotnet group in /docs/core/extensions/snippets/ai/ConsoleAI.DependencyInjection with 4 updates: [Microsoft.Extensions.AI](https://github.com/dotnet/extensions), [System.Threading.RateLimiting](https://github.com/dotnet/runtime), [Microsoft.Extensions.Caching.Memory](https://github.com/dotnet/runtime) and [Microsoft.Extensions.Hosting](https://github.com/dotnet/runtime). Updates `Microsoft.Extensions.AI` from 9.3.0-preview.1.25114.11 to 9.3.0-preview.1.25161.3 - [Release notes](https://github.com/dotnet/extensions/releases) - [Commits](https://github.com/dotnet/extensions/commits) Updates `System.Threading.RateLimiting` from 9.0.2 to 9.0.3 - [Release notes](https://github.com/dotnet/runtime/releases) - [Commits](dotnet/runtime@v9.0.2...v9.0.3) Updates `Microsoft.Extensions.Caching.Memory` from 9.0.2 to 9.0.3 - [Release notes](https://github.com/dotnet/runtime/releases) - [Commits](dotnet/runtime@v9.0.2...v9.0.3) Updates `Microsoft.Extensions.Hosting` from 9.0.2 to 9.0.3 - [Release notes](https://github.com/dotnet/runtime/releases) - [Commits](dotnet/runtime@v9.0.2...v9.0.3) --- updated-dependencies: - dependency-name: Microsoft.Extensions.AI dependency-type: direct:production update-type: version-update:semver-patch dependency-group: dotnet - dependency-name: System.Threading.RateLimiting dependency-type: direct:production update-type: version-update:semver-patch dependency-group: dotnet - dependency-name: Microsoft.Extensions.Caching.Memory dependency-type: direct:production update-type: version-update:semver-patch dependency-group: dotnet - dependency-name: Microsoft.Extensions.Hosting dependency-type: direct:production update-type: version-update:semver-patch dependency-group: dotnet ... Signed-off-by: dependabot[bot] <[email protected]> * update packages and fix code in core/extensions/snippets/ai * remove overload list since it's hard to maintain --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Genevieve Warren <[email protected]>
1 parent 30ea82d commit 1c650e1

File tree

23 files changed

+39
-92
lines changed

23 files changed

+39
-92
lines changed

docs/core/extensions/artificial-intelligence.md

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -187,20 +187,13 @@ The consumer can then easily use this in their pipeline, for example:
187187

188188
This example demonstrates [hosted scenario](generic-host.md), where the consumer relies on [dependency injection](dependency-injection.md) to provide the `RateLimiter` instance. The preceding extension methods demonstrate using a `Use` method on <xref:Microsoft.Extensions.AI.ChatClientBuilder>. The `ChatClientBuilder` also provides <xref:Microsoft.Extensions.AI.ChatClientBuilder.Use*> overloads that make it easier to write such delegating handlers.
189189

190-
- <xref:Microsoft.Extensions.AI.ChatClientBuilder.Use(Microsoft.Extensions.AI.AnonymousDelegatingChatClient.GetResponseSharedFunc)>
191-
- <xref:Microsoft.Extensions.AI.ChatClientBuilder.Use(System.Func{Microsoft.Extensions.AI.IChatClient,Microsoft.Extensions.AI.IChatClient})>
192-
- <xref:Microsoft.Extensions.AI.ChatClientBuilder.Use(System.Func{Microsoft.Extensions.AI.IChatClient,System.IServiceProvider,Microsoft.Extensions.AI.IChatClient})>
193-
- <xref:Microsoft.Extensions.AI.ChatClientBuilder.Use(System.Func{System.Collections.Generic.IList{Microsoft.Extensions.AI.ChatMessage},Microsoft.Extensions.AI.ChatOptions,Microsoft.Extensions.AI.IChatClient,System.Threading.CancellationToken,System.Threading.Tasks.Task{Microsoft.Extensions.AI.ChatResponse}},System.Func{System.Collections.Generic.IList{Microsoft.Extensions.AI.ChatMessage},Microsoft.Extensions.AI.ChatOptions,Microsoft.Extensions.AI.IChatClient,System.Threading.CancellationToken,System.Collections.Generic.IAsyncEnumerable{Microsoft.Extensions.AI.ChatResponseUpdate}})>
194-
195190
For example, in the earlier `RateLimitingChatClient` example, the overrides of `GetResponseAsync` and `GetStreamingResponseAsync` only need to do work before and after delegating to the next client in the pipeline. To achieve the same thing without writing a custom class, you can use an overload of `Use` that accepts a delegate that's used for both `GetResponseAsync` and `GetStreamingResponseAsync`, reducing the boilerplate required:
196191

197192
:::code language="csharp" source="snippets/ai/ConsoleAI.UseExample/Program.cs":::
198193

199-
The preceding overload internally uses an `AnonymousDelegatingChatClient`, which enables more complicated patterns with only a little additional code. For example, to achieve the same result but with the <xref:System.Threading.RateLimiting.RateLimiter> retrieved from DI:
200-
201-
:::code language="csharp" source="snippets/ai/ConsoleAI.UseExampleAlt/Program.cs":::
194+
The preceding overload internally uses an `AnonymousDelegatingChatClient`, which enables more complicated patterns with only a little additional code.
202195

203-
For scenarios where the developer would like to specify delegating implementations of `GetResponseAsync` and `GetStreamingResponseAsync` inline, and where it's important to be able to write a different implementation for each in order to handle their unique return types specially, another overload of `Use` exists that accepts a delegate for each.
196+
For scenarios where you'd like to specify delegating implementations of `GetResponseAsync` and `GetStreamingResponseAsync` inline, and where it's important to be able to write a different implementation for each in order to handle their unique return types specially, you can use the <xref:Microsoft.Extensions.AI.ChatClientBuilder.Use(System.Func{System.Collections.Generic.IEnumerable{Microsoft.Extensions.AI.ChatMessage},Microsoft.Extensions.AI.ChatOptions,Microsoft.Extensions.AI.IChatClient,System.Threading.CancellationToken,System.Threading.Tasks.Task{Microsoft.Extensions.AI.ChatResponse}},System.Func{System.Collections.Generic.IEnumerable{Microsoft.Extensions.AI.ChatMessage},Microsoft.Extensions.AI.ChatOptions,Microsoft.Extensions.AI.IChatClient,System.Threading.CancellationToken,System.Collections.Generic.IAsyncEnumerable{Microsoft.Extensions.AI.ChatResponseUpdate}})> overload that accepts a delegate for each.
204197

205198
### Dependency injection
206199

docs/core/extensions/snippets/ai/AI.Shared/AI.Shared.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<PackageReference Include="Microsoft.Extensions.AI" Version="9.3.0-preview.1.25114.11" />
11-
<PackageReference Include="System.Threading.RateLimiting" Version="9.0.2" />
10+
<PackageReference Include="Microsoft.Extensions.AI" Version="9.3.0-preview.1.25161.3" />
11+
<PackageReference Include="System.Threading.RateLimiting" Version="10.0.0-preview.1.25080.5" />
1212
</ItemGroup>
1313

1414
</Project>

docs/core/extensions/snippets/ai/AI.Shared/RateLimitingChatClient.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public sealed class RateLimitingChatClient(
77
: DelegatingChatClient(innerClient)
88
{
99
public override async Task<ChatResponse> GetResponseAsync(
10-
IList<ChatMessage> chatMessages,
10+
IEnumerable<ChatMessage> chatMessages,
1111
ChatOptions? options = null,
1212
CancellationToken cancellationToken = default)
1313
{
@@ -24,7 +24,7 @@ public override async Task<ChatResponse> GetResponseAsync(
2424
}
2525

2626
public override async IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync(
27-
IList<ChatMessage> chatMessages,
27+
IEnumerable<ChatMessage> chatMessages,
2828
ChatOptions? options = null,
2929
[EnumeratorCancellation] CancellationToken cancellationToken = default)
3030
{

docs/core/extensions/snippets/ai/AI.Shared/SampleChatClient.cs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ public sealed class SampleChatClient(Uri endpoint, string modelId) : IChatClient
66
public ChatClientMetadata Metadata { get; } = new(nameof(SampleChatClient), endpoint, modelId);
77

88
public async Task<ChatResponse> GetResponseAsync(
9-
IList<ChatMessage> chatMessages,
9+
IEnumerable<ChatMessage> chatMessages,
1010
ChatOptions? options = null,
1111
CancellationToken cancellationToken = default)
1212
{
@@ -21,15 +21,14 @@ public async Task<ChatResponse> GetResponseAsync(
2121
"This is yet another response message."
2222
];
2323

24-
return new([new ChatMessage()
25-
{
26-
Role = ChatRole.Assistant,
27-
Text = responses[Random.Shared.Next(responses.Length)],
28-
}]);
24+
return new(new ChatMessage(
25+
ChatRole.Assistant,
26+
responses[Random.Shared.Next(responses.Length)]
27+
));
2928
}
3029

3130
public async IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync(
32-
IList<ChatMessage> chatMessages,
31+
IEnumerable<ChatMessage> chatMessages,
3332
ChatOptions? options = null,
3433
[EnumeratorCancellation] CancellationToken cancellationToken = default)
3534
{
@@ -41,11 +40,7 @@ public async IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync(
4140
await Task.Delay(100, cancellationToken);
4241

4342
// Yield the next message in the response.
44-
yield return new ChatResponseUpdate
45-
{
46-
Role = ChatRole.Assistant,
47-
Text = word,
48-
};
43+
yield return new ChatResponseUpdate(ChatRole.Assistant, word);
4944
}
5045
}
5146

docs/core/extensions/snippets/ai/ConsoleAI.CacheResponses/ConsoleAI.CacheResponses.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="9.0.2" />
11+
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="10.0.0-preview.1.25080.5" />
1212
</ItemGroup>
1313

1414
<ItemGroup>

docs/core/extensions/snippets/ai/ConsoleAI.ConsumeClientMiddleware/ConsoleAI.ConsumeClientMiddleware.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.2" />
11+
<PackageReference Include="Microsoft.Extensions.Hosting" Version="10.0.0-preview.1.25080.5" />
1212
<ProjectReference Include="..\AI.Shared\AI.Shared.csproj" />
1313
</ItemGroup>
1414

docs/core/extensions/snippets/ai/ConsoleAI.CustomClientMiddle/ConsoleAI.CustomClientMiddle.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="System.Threading.RateLimiting" Version="9.0.2" />
11+
<PackageReference Include="System.Threading.RateLimiting" Version="10.0.0-preview.1.25080.5" />
1212
</ItemGroup>
1313

1414
<ItemGroup>

docs/core/extensions/snippets/ai/ConsoleAI.CustomEmbeddingsMiddle/ConsoleAI.CustomEmbeddingsMiddle.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="9.0.2" />
11+
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="10.0.0-preview.1.25080.5" />
1212
<PackageReference Include="OpenTelemetry.Exporter.Console" Version="1.11.2" />
1313
<ProjectReference Include="..\AI.Shared\AI.Shared.csproj" />
1414
</ItemGroup>

docs/core/extensions/snippets/ai/ConsoleAI.CustomEmbeddingsMiddle/Program.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,23 @@
55
using OpenTelemetry.Trace;
66

77
// Configure OpenTelemetry exporter
8-
var sourceName = Guid.NewGuid().ToString();
9-
var tracerProvider = OpenTelemetry.Sdk.CreateTracerProviderBuilder()
8+
string sourceName = Guid.NewGuid().ToString();
9+
TracerProvider tracerProvider = OpenTelemetry.Sdk.CreateTracerProviderBuilder()
1010
.AddSource(sourceName)
1111
.AddConsoleExporter()
1212
.Build();
1313

1414
// Explore changing the order of the intermediate "Use" calls to see that impact
1515
// that has on what gets cached, traced, etc.
16-
var generator = new EmbeddingGeneratorBuilder<string, Embedding<float>>(
16+
IEmbeddingGenerator<string, Embedding<float>> generator = new EmbeddingGeneratorBuilder<string, Embedding<float>>(
1717
new SampleEmbeddingGenerator(new Uri("http://coolsite.ai"), "target-ai-model"))
1818
.UseDistributedCache(
1919
new MemoryDistributedCache(
2020
Options.Create(new MemoryDistributedCacheOptions())))
2121
.UseOpenTelemetry(sourceName: sourceName)
2222
.Build();
2323

24-
var embeddings = await generator.GenerateAsync(
24+
GeneratedEmbeddings<Embedding<float>> embeddings = await generator.GenerateAsync(
2525
[
2626
"What is AI?",
2727
"What is .NET?",

docs/core/extensions/snippets/ai/ConsoleAI.DependencyInjection/ConsoleAI.DependencyInjection.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.2" />
12-
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="9.0.2" />
11+
<PackageReference Include="Microsoft.Extensions.Hosting" Version="10.0.0-preview.1.25080.5" />
12+
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="10.0.0-preview.1.25080.5" />
1313
<ProjectReference Include="..\AI.Shared\AI.Shared.csproj" />
1414
</ItemGroup>
1515

0 commit comments

Comments
 (0)