Skip to content

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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

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
@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

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.

2 participants