Open gaeaehrlich opened 3 months ago
It's possible to create your own OpenAIClient
and pass it in when creating the IChatCompletionService
, see https://github.com/microsoft/semantic-kernel/blob/main/dotnet/src/Connectors/Connectors.OpenAI/OpenAIServiceCollectionExtensions.cs#L1036
Is this approach sufficient to meet your need?
@crickman as the UserAgent ask is only for Agents can we add a new method that allows the OpenAIClient to be injected into the Agent?
This is the approach we use for AI Services i.e. a developer can provide the OpenAIClient and configure it whatever way they want.
@markwallace-microsoft - Your proposal makes sense but would only be critical for OpenAIAssistantAgent
for ChatCompletionAgent
the entry point might still be the implementation of IChatCompletionService
The agent framework doesn't directly handle the OpenAIClient
for ChatCompletionAgent
.
@markwallace-microsoft - In our case we can't use it because we don't have control over the creation of AzureOpenAIChatCompletionService, our user creates AzureOpenAIChatCompletionService and we get it through DI. Another thing I noticed is that when you create AzureOpenAIChatCompletionService with your own OpenAIClient, this c'tor will be called: https://github.com/microsoft/semantic-kernel/blob/ce79de5ce14f2fa610c2efbb2788101d14387627/dotnet/src/Connectors/Connectors.OpenAI/AzureSdk/AzureOpenAIClientCore.cs#L89 this c'tor don't call to GetOpenAIClientOptions() like the c'tor without the OpenAIClient, so if someone will create AzureOpenAIChatCompletionService with OpenAIClient the UserAgent header won't have the Semantic-Kernel prefix and Semantic-Kernel-Version header.
Yes, if someone creates their own OpenAIClient
then we lose the ability to set the Semantic-Kernel prefix and Semantic-Kernel-Version header. This is working as designed. We don't want to override or modify what a developer may have set.
As an SDK, the user creates the Kernel and can create their own OpenAIClient
, so we can't override what they use.
In our case, it would be better to append our header to the client.
The Azure SDK enables to append a string to the UserAgent header, it is being done by the OpenAIClientOptions.Diagnostics.ApplicationId. We need from SK to expose the same capability, perhaps by adding a new property to the ChatCompletionAgent Execution Settings.
In our implementation we don't have access to the user provided HTTP client, but even if we find a way to get the HTTP client it won't help, because SK and azure SDK add user agent header on the request and it will override the client default header.