-
Notifications
You must be signed in to change notification settings - Fork 15
Open
Description
I want to create a differeny OpenAIService per key. Here's what I tried:
-
I can use static
OpenAIService.CreateServiceand provide options. This works but generallyServiceProvidershould be disposed. Therefore I'm left with hanging undisposed instance of a container. This is an issue on it's own. -
I can use
AddForgeOpenAIAsTransientin my root container and after call:IOpenAIService CreateService(OpenAIOptions options, IServiceProvider serviceProvider, IProviderEndpointService providerEndpointService)
This function gives me the impression that I can really provide OpenAIOptions but in reality each service resolves on it's own IApiHttpService that ends up with default IProviderEndpointService with default options inside.
Specifically this code is copypasted in many services:
_apiHttpService = serviceProvider.GetRequiredService<IApiHttpService>();
_providerEndpointService = providerEndpointService;
But it's actually wrong because provided providerEndpointService is not passed to _apiHttpService
- It doesn't matter what function I call to register services
OpenAIProviderEndpointServiceis registered as singleton. Therefore it is shared and you can't really have different options in one app. Ok you can call a function from step 2. creating this service with options as constructor parameter but that still leavesIApiHttpServiceout of the box.
Metadata
Metadata
Assignees
Labels
No labels