-
Notifications
You must be signed in to change notification settings - Fork 839
Closed
Labels
Description
The IServiceCollection
extensions provided with the MEAI package are hardcoding singleton lifetimes for registered services:
Lines 28 to 38 in fab3675
public static ChatClientBuilder AddChatClient( | |
this IServiceCollection serviceCollection, | |
Func<IServiceProvider, IChatClient> innerClientFactory) | |
{ | |
_ = Throw.IfNull(serviceCollection); | |
_ = Throw.IfNull(innerClientFactory); | |
var builder = new ChatClientBuilder(innerClientFactory); | |
_ = serviceCollection.AddSingleton(builder.Build); | |
return builder; | |
} |
This doesn't work well in the context of Github Copilot agents that forward to the Github completions API since the clients need to be scoped to the specific Github token used in the request. We should consider extending the helpers so that all lifetimes are supported -- most likely this is going to be a breaking change since we'd need to rename the methods to adhere to naming conventions used DI elsewhere: AddSingletonChatClient
, AddScopedChatClient
, AddTransientChatClient
, etc.