Closed cisionmarkwalls closed 2 months ago
Hi @cisionmarkwalls thanks for creating this issue and the offer to create a contribution. The requirement makes sense to me, I'll discuss with the team today.
Hi @cisionmarkwalls Thanks for reaching out, currently as this is a very specific requirement and our APIs currently allow you to do that with a simple Extension method implemented by the customer. We would appreciate as a contribution for that to be a helper on our Concepts or Demonstration projects.
Following some of the code below you might be able to achieve the requirement.
DependencyInjection - NamedHttpClient Registration
public static class OpenAIExtension
{
public static IServiceCollection AddOpenAIChatCompletionService(this IServiceCollection services, string serviceId)
{
services.AddTransient<IChatCompletionService>((sp) => {
var clientFactory = sp.GetRequiredService<IHttpClientFactory>();
return new OpenAIChatCompletionService("model-id", "api-key", httpClient: clientFactory.CreateClient(serviceId));
});
return services;
}
}
It would be really useful to be able to define a named HttpClient based on the serviceId of the IChatCompletionService (like the httpclient parameter for the kernel). That way I could have specialized http clients for different types of completion services. If I have one type of request that takes 30 seconds on average then I don't want to up the timeout on all http client's, just the one that would be pulled in by that service.
I'd be happy to write the code for this, it would be fairly minor and left as an optional parameter, but I'm curious if that matches design goals before I try to build it.