Repository navigation
Description
Describe the bug
I have been using the SK Ollama connector with the .NET Aspire community toolkit Ollama client integration, expecting an easy, configuration-free, plug-and-play experience. Unfortunately, a dependency registration error happens at runtime.
The SK connector requires an OllamaApiClient to be registered when called without any parameter, but the .NET Aspire client integration registers its interface, IOllamaApiClient.
To Reproduce
Register both the SK Ollama connector and the .NET Aspire's community toolkit Ollama client integration in a generic host-powered app:
builder.AddOllamaApiClient("embedding-model");
builder.Services.AddOllamaTextEmbeddingGeneration();In the .NET Aspire app host, register an Ollama model and reference it in your app:
var embeddingModel = builder.AddOllama("ollama")
.AddModel("embedding-model", "bge-m3");
builder.AddProject<Projects.HelloSK02_ApiService>("apiservice")
.WithReference(embeddingModel)
.WaitFor(embeddingModel);When requesting an ITextEmbeddingGenerationService in the app, you'll get the following exception:
No service for type 'OllamaSharp.OllamaApiClient' has been registered.
Expected behavior
I would have expected these two components to play nicely, for instance, the SK connector to fallback and look for IOllamaApiClient or the community Aspire component to register the concrete class. I'm not sure who's responsibility it is, but given that the SK connector is still alpha, I thought I would give it a try here.
Workaround
So far I've been doing this to bypass the registration problem:
builder.Services.AddSingleton(sp => (OllamaApiClient)sp.GetRequiredService<IOllamaApiClient>());Platform
- Language: C#
- Sources:
- Microsoft.SemanticKernel.Connectors.Ollama: 1.37.0-alpha
- CommunityToolkit.Aspire.OllamaSharp: 9.1.0
- AI model: bge-m3
- IDE: Rider
- OS: Windows
Additional context
It may be related to #10321, but the fix doesn't seem to cover this particular path.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsSprint: Done
Activity
Caldas commentedon Feb 21, 2025
I´m also facing this bug.
Thanks for the workaround Anthony Simmon (@asimmon)
Caldas commentedon Feb 21, 2025
Mark Wallace (@markwallace-microsoft) you just need to add this 3 methods at OllamaServiceCollectionExtensions class to solve this issue:
And you can also improve OllamaKernelBuilderExtensions class too:
.Net: Add missing Ollama Connector Aspire Friendly Extensions (#10775)
.Net: Add missing Ollama Connector Aspire Friendly Extensions (micros…
.Net: Add missing Ollama Connector Aspire Friendly Extensions (micros…
.Net: Add missing Ollama Connector Aspire Friendly Extensions (micros…