I want to create a differeny OpenAIService per key. Here's what I tried:
-
I can use static OpenAIService.CreateService and provide options. This works but generally ServiceProvider should be disposed. Therefore I'm left with hanging undisposed instance of a container. This is an issue on it's own.
-
I can use AddForgeOpenAIAsTransient in 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
OpenAIProviderEndpointService is 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 leaves IApiHttpService out of the box.
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:This function gives me the impression that I can really provide OpenAIOptions but in reality each service resolves on it's own
IApiHttpServicethat ends up with defaultIProviderEndpointServicewith default options inside.Specifically this code is copypasted in many services:
But it's actually wrong because provided
providerEndpointServiceis not passed to_apiHttpServiceOpenAIProviderEndpointServiceis 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.