semantic-kernel icon indicating copy to clipboard operation
semantic-kernel copied to clipboard

Bug: ExtensionData parameters not included in HTTP JSON request when using OpenAIPromptExecutionSettings

Open tianbiai opened this issue 1 year ago • 10 comments

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 avatar Jul 01 '25 02:07 tianbiai

@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 avatar Jul 02 '25 10:07 markwallace-microsoft

@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

nels-ai-source avatar Jul 03 '25 04:07 nels-ai-source

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

nels-ai-source avatar Jul 03 '25 04:07 nels-ai-source

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 } });

tianbiai avatar Jul 03 '25 04:07 tianbiai

ExtensionData parameters not included in HTTP JSON request when using OpenAIPromptExecutionSettings,You can refer to Connectors.AzureOpenAI and rewrite a Connector.Ailiyun

syp10000 avatar Jul 15 '25 05:07 syp10000

Image

syp10000 avatar Jul 18 '25 03:07 syp10000

Image

why not a PR

jzhouw avatar Jul 18 '25 03:07 jzhouw

It has been a month and a half, but this issue still persists

checkmateTowindn avatar Aug 22 '25 10:08 checkmateTowindn

This issue is stale because it has been open for 90 days with no activity.

github-actions[bot] avatar Apr 06 '26 02:04 github-actions[bot]

This issue was closed because it has been inactive for 14 days since being marked as stale.

github-actions[bot] avatar Apr 20 '26 02:04 github-actions[bot]