Define IProvider interface and implement concrete providers for Mistral (with custom DTOs for chat completion API) and Ollama (via OllamaSharp). Includes DI registration extensions using Microsoft.Extensions.AI.
28 lines
830 B
C#
28 lines
830 B
C#
using Luna.Configuration;
|
|
using Luna.Providers.Abstractions;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Options;
|
|
|
|
namespace Luna.Providers.Extensions;
|
|
|
|
public static class ServiceProviderExtensions
|
|
{
|
|
extension(IServiceProvider provider)
|
|
{
|
|
public TProvider GetProvider<TProvider>(string? name = null)
|
|
where TProvider : IProvider
|
|
{
|
|
name ??= TProvider.Name;
|
|
return provider.GetRequiredKeyedService<TProvider>(name);
|
|
}
|
|
|
|
public ProviderOptions GetProviderOptions<TProvider>(string? name = null)
|
|
where TProvider : IProvider
|
|
{
|
|
name ??= TProvider.Name;
|
|
return provider
|
|
.GetRequiredService<IOptionsMonitor<ProviderOptions>>()
|
|
.Get(name);
|
|
}
|
|
}
|
|
} |