Bug: ExtensionData parameters not included in HTTP JSON request when using OpenAIPromptExecutionSettings
I'm trying to set a custom parameter enable_thinking through ExtensionData in OpenAIPromptExecutionSettings, but it's not being included in the HTTP JSON request payload. Here's my code:
var setting = new OpenAIPromptExecutionSettings { MaxTokens = 8192, Temperature = 0.7f, TopP = 0.7f, ExtensionData = new Dictionary<string, object> { { "enable_thinking", false } } }; var kernel = builder.Build(); var result = await kernel.InvokePromptAsync("xxxxx", new KernelArguments(setting) { });
The generated JSON request doesn't include the enable_thinking field. How can I properly configure this to include custom parameters in the HTTP request JSON?
@tianbiai Consider using Microsoft.Extensions.AI as this allows additional parameters to be passed. Take a look here: https://devblogs.microsoft.com/semantic-kernel/semantic-kernel-and-microsoft-extensions-ai-better-together-part-2/
@markwallace-microsoft Additional Note: Same Issue Encountered When Using Agent
The same extensibility issue was encountered when using Agent functionality. Investigation revealed that the CreateChatCompletionOptions method uses hardcoded property assignment to create ChatCompletionOptions objects.
Specific Code Location and Issue:
Location: dotnet\src\Connectors\Connectors.OpenAI\Core\ClientCore.ChatCompletion.cs lines 456-479
protected virtual ChatCompletionOptions CreateChatCompletionOptions(
OpenAIPromptExecutionSettings executionSettings,
ChatHistory chatHistory,
ToolCallingConfig toolCallingConfig,
Kernel? kernel)
{
var options = new ChatCompletionOptions
{
WebSearchOptions = GetWebSearchOptions(executionSettings),
MaxOutputTokenCount = executionSettings.MaxTokens,
Temperature = (float?)executionSettings.Temperature,
TopP = (float?)executionSettings.TopP,
FrequencyPenalty = (float?)executionSettings.FrequencyPenalty,
PresencePenalty = (float?)executionSettings.PresencePenalty,
Seed = executionSettings.Seed,
EndUserId = executionSettings.User,
TopLogProbabilityCount = executionSettings.TopLogprobs,
IncludeLogProbabilities = executionSettings.Logprobs,
StoredOutputEnabled = executionSettings.Store,
ReasoningEffortLevel = GetEffortLevel(executionSettings),
};
Impact: When other model providers use the OpenAI connector and want to pass different custom parameters, they face limitations. Common scenarios include:
- Provider-specific parameters cannot be passed
The ChatCompletionOptions class implements a complete JSON deserialization mechanism in ChatCompletionOptions.Serialization.cs , including:
- JsonModelCreateCore method supports creating objects from JSON
- _additionalBinaryDataProperties field automatically handles unrecognized properties
- DeserializeChatCompletionOptions static method provides deserialization entry point
I'm using Microsoft.Extensions.AI's IChatClient. I made a request with the following code, but the enable_thinking field wasn't included in the JSON. How should I configure this to make it work?
var client = new OpenAIClient(new ApiKeyCredential(OPENAI_API_KEY), new OpenAIClientOptions { Endpoint = new Uri("xxx"), }).GetChatClient("xxx").AsIChatClient();
var response = await client.GetResponseAsync( new List<Microsoft.Extensions.AI.ChatMessage> { new Microsoft.Extensions.AI.ChatMessage(ChatRole.User, list) }, new ChatOptions { AdditionalProperties = new AdditionalPropertiesDictionary { ["enable_thinking"] = true } });
ExtensionData parameters not included in HTTP JSON request when using OpenAIPromptExecutionSettings,You can refer to Connectors.AzureOpenAI and rewrite a Connector.Ailiyun
why not a PR
It has been a month and a half, but this issue still persists
This issue is stale because it has been open for 90 days with no activity.
This issue was closed because it has been inactive for 14 days since being marked as stale.