-
Notifications
You must be signed in to change notification settings - Fork 6k
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
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: Rageking8 <[email protected]>
There was a problem hiding this 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
andSampleEmbeddingGenerator
in most snippets forOllamaApiClient
and added theOllamaSharp
package reference. - Introduced a new
sample-implementations.md
article with concrete IChatClient and IEmbeddingGenerator examples underdocs/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 usingnew 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
Contributes to #46047.
Internal previews