Junaid Aslam
Unable to configure values in DI using the extension method
@TeBeCo a small improvement:
public static IServiceCollection AddGemini(this IServiceCollection services,Func<HttpClientHandler>? proxyHandler=null)
{
return RegisterCoreServices<GeminiClient>(services, proxyHandler);
}
public static IServiceCollection AddGemini<TGeminiClient>(this IServiceCollection services,Func<HttpClientHandler>? proxyHandler=null) where TGeminiClient : class, IGeminiClient
{
return RegisterCoreServices<TGeminiClient>(services, proxyHandler);
}
private static IServiceCollection RegisterCoreServices<TGeminiClient>(IServiceCollection services, Func<HttpClientHandler>? proxyHandler) where TGeminiClient : class, IGeminiClient
{
services.AddTransient<GeminiAuthHandler<GeminiHttpClientOptions>>();
var httpClientBuilder = services.AddHttpClient<IGeminiClient, TGeminiClient>((IServiceProvider serviceProvider, HttpClient client) =>
{
var options = serviceProvider.GetRequiredService<IOptions<GeminiHttpClientOptions>>().Value;
client.BaseAddress = options.Url;
});
if (proxyHandler is not null)
{
httpClientBuilder.ConfigurePrimaryHttpMessageHandler(proxyHandler);
}
httpClientBuilder.AddHttpMessageHandler<GeminiAuthHandler<GeminiHttpClientOptions>>();
services.AddTransient<ITextService, TextService>();
services.AddTransient<IVisionService, VisionService>();
services.AddTransient<IChatService, ChatService>();
services.AddTransient<IEmbeddingService, EmbeddingService>();
services.AddTransient<IModelInfoService, ModelInfoService>();
return services;
}
288 replies