Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Add sample IChatClient and IEmbeddingGenerator implementations #46482

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jun 23, 2025

Conversation

gewarren
Copy link
Contributor

@gewarren gewarren commented May 29, 2025

@gewarren gewarren requested review from alexwolfmsft and a team as code owners May 29, 2025 17:21
@dotnetrepoman dotnetrepoman bot added this to the May 2025 milestone May 29, 2025
docs/ai/advanced/sample-implementations.md Outdated Show resolved Hide resolved
Co-authored-by: Rageking8 <106309953+Rageking8@users.noreply.github.com>
@gewarren gewarren requested review from jeffhandley and Copilot May 30, 2025 23:36
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds real-world OllamaApiClient examples and dedicated sample implementations for IChatClient and IEmbeddingGenerator.

  • Swapped out SampleChatClient and SampleEmbeddingGenerator in most snippets for OllamaApiClient and added the OllamaSharp package reference.
  • Introduced a new sample-implementations.md article with concrete IChatClient and IEmbeddingGenerator examples under docs/ai/advanced.
  • Updated the main Microsoft.Extensions.AI docs to link to the new advanced sample implementations.

Reviewed Changes

Copilot reviewed 24 out of 24 changed files in this pull request and generated no comments.

Show a summary per file
File Description
docs/ai/snippets/microsoft-extensions-ai/ConsoleAI.UseTelemetry/ConsoleAI.UseTelemetry.csproj Added OllamaSharp package reference
docs/ai/snippets/microsoft-extensions-ai/ConsoleAI.GetStreamingResponseAsync/Program.cs Replaced SampleChatClient with OllamaApiClient; added using OllamaSharp
docs/ai/snippets/microsoft-extensions-ai/ConsoleAI.GetStreamingResponseAsync/ConsoleAI.GetStreamingResponseAsync.csproj Added OllamaSharp package reference
docs/ai/snippets/microsoft-extensions-ai/ConsoleAI.GetResponseAsyncArgs/Program.cs Replaced SampleChatClient with OllamaApiClient; added using OllamaSharp
docs/ai/snippets/microsoft-extensions-ai/ConsoleAI.GetResponseAsyncArgs/ConsoleAI.GetResponseAsyncArgs.csproj Added OllamaSharp package reference
docs/ai/snippets/microsoft-extensions-ai/ConsoleAI.CustomEmbeddingsMiddle/Program.cs Replaced SampleEmbeddingGenerator with OllamaApiClient; added using OllamaSharp
docs/ai/snippets/microsoft-extensions-ai/ConsoleAI.CustomEmbeddingsMiddle/ConsoleAI.CustomEmbeddingsMiddle.csproj Added OllamaSharp package reference
docs/ai/snippets/microsoft-extensions-ai/ConsoleAI.CreateEmbeddings/Program.cs Replaced SampleEmbeddingGenerator with OllamaApiClient; added using OllamaSharp
docs/ai/snippets/microsoft-extensions-ai/ConsoleAI.CreateEmbeddings/ConsoleAI.CreateEmbeddings.csproj Added OllamaSharp package reference
docs/ai/snippets/microsoft-extensions-ai/ConsoleAI.ConsumeRateLimitingEmbedding/Program.cs Replaced SampleEmbeddingGenerator with OllamaApiClient; added using OllamaSharp
docs/ai/snippets/microsoft-extensions-ai/ConsoleAI.ConsumeRateLimitingEmbedding/ConsoleAI.ConsumeRateLimitingEmbedding.csproj Added OllamaSharp package reference
docs/ai/snippets/microsoft-extensions-ai/ConsoleAI.ConsumeClientMiddleware/Program.cs Replaced builder sample with OllamaApiClient; added using OllamaSharp
docs/ai/snippets/microsoft-extensions-ai/ConsoleAI.ConsumeClientMiddleware/ConsoleAI.ConsumeClientMiddleware.csproj Added OllamaSharp package reference
docs/ai/snippets/microsoft-extensions-ai/ConsoleAI.AddMessages/Program.cs Replaced SampleChatClient with OllamaApiClient; added using OllamaSharp
docs/ai/snippets/microsoft-extensions-ai/ConsoleAI.AddMessages/ConsoleAI.AddMessages.csproj Added OllamaSharp package reference
docs/ai/microsoft-extensions-ai.md Updated links to point at the new advanced sample-implementations article
docs/ai/advanced/snippets/sample-implementations/SampleEmbeddingGenerator.cs Modified return expression to use C# collection syntax
docs/ai/advanced/snippets/sample-implementations/SampleChatClient.cs Reformatted constructor signature and property initializer
docs/ai/advanced/snippets/sample-implementations/Implementations.csproj Added new project file for sample implementations
docs/ai/advanced/sample-implementations.md Added new article with sample IChatClient and IEmbeddingGenerator code
Comments suppressed due to low confidence (2)

docs/ai/snippets/microsoft-extensions-ai/ConsoleAI.AddMessages/Program.cs:8

  • Assigning an empty array literal [] to a List will not compile. Initialize the list explicitly using new List<ChatMessage>() or use a collection expression that returns a List, e.g.: var history = new List<ChatMessage>();
List<ChatMessage> history = [];

docs/ai/advanced/snippets/sample-implementations/SampleEmbeddingGenerator.cs:19

  • The return statement uses a C# collection expression instead of instantiating the GeneratedEmbeddings<Embedding> object. This will not compile since the method signature expects a GeneratedEmbeddings<Embedding>. You should wrap the array in the constructor, e.g.: return new GeneratedEmbeddings<Embedding<float>>(values.Select(v => new Embedding<float>(Enumerable.Range(0,384).Select(_ => Random.Shared.NextSingle()).ToArray())));
return [.. from value in values

Copy link
Member

@BillWagner BillWagner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This LGTM @gewarren

You can :shipit: once you and the product team are happy.

@gewarren gewarren enabled auto-merge (squash) June 21, 2025 06:29
@gewarren gewarren merged commit b12bc08 into dotnet:main Jun 23, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.