Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MEAI] Custom ChatOptions.AdditionalProperties ignored on deserialization. #6180

Open
arthuridea opened this issue Mar 23, 2025 · 4 comments
Labels
area-ai Microsoft.Extensions.AI libraries bug This issue describes a behavior which is not expected - a bug.

Comments

@arthuridea
Copy link

arthuridea commented Mar 23, 2025

Description

Custom additional properties is ignored when mapping to OpenAI.Chat.ChatCompletionOptions models.
The static method ToOpenAIOptions in OpenAIModelMapper.ChatCompletion.cs leaves custom properties unhandled.
It works fine in OpenAI .NET library using IJsonModel and JsonElement for serialization.

Reproduction Steps

// passing "web_search" for some LLMs...
var optionJson = """
    {
        "model": "some LLM model id",
        "stream": true,
        "web_search": {
            "enabled": true,
            "enable_trace": true,
            "enable_citation": false
        },
        "stream_options": {
            "include_usage": true
        },
        "messages": [
            {
                "role": "user",
                "content": "some user prompts...."
            }
        ]
    }
"""u8.ToArray();
///////////// case OpenAI serialization senario:
ChatCompletionOptions openAIChatCompletionOptions = new();
var binaryData = BinaryData.FromBytes(optionJson);
openAIChatCompletionOptions = ((IJsonModel<ChatCompletionOptions>)openAIChatCompletionOptions).Create(binaryData, ModelReaderWriterOptions.Json);
// We can find additional serialized data successfully deserialized

///////////// case MEAI serialization senario:
using MemoryStream optionStream = new(optionJson);
var chatRequest = await OpenAISerializationHelpers.DeserializeChatCompletionRequestAsync(optionStream);
var options = chatRequest.Options;
// Properties missing after deserialization.

Expected behavior

Custom properties will also be deserialzed.

Actual behavior

Custom properties unhandled.

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

@arthuridea arthuridea added bug This issue describes a behavior which is not expected - a bug. untriaged labels Mar 23, 2025
@github-actions github-actions bot added the area-ai Microsoft.Extensions.AI libraries label Mar 23, 2025
@arthuridea arthuridea changed the title [MEAI] Custom ChatOptions.AdditionalProperty ignored on deserialization. [MEAI] Custom ChatOptions.AdditionalProperties ignored on deserialization. Mar 23, 2025
@stephentoub
Copy link
Member

stephentoub commented Mar 23, 2025

This support is being removed as part of #6094 / #6138. It's relying on private reflection into the OpenAI library and is not something we can actually make stable. The missing properties here are a good example of how it's deficient, since the OpenAI library it wraps doesn't expose the ability to achieve this.

@arthuridea
Copy link
Author

This support is being removed as part of #6094 / #6138. It's relying on private reflection into the OpenAI library and is not something we can actually make stable. The missing properties here are a good example of how it's deficient, since the OpenAI library it wraps doesn't expose the ability to achieve this.

Will the whole ChatClient(or other clients) implementation or only mapping extension methods be removed?
Should I open an issue in OpenAI.NET repo,rquesting if any public methods will be provided, or in some day,we can use a rquest & response mapping delegations here?............which will make codes ugly :( @stephentoub

@stephentoub
Copy link
Member

The IChatClient implementation (and IEmbeddingGenerator impl) is planned to move into the OpenAI library itself.

@jeffhandley
Copy link
Member

Noting this issue will need to be reviewed during that effort.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-ai Microsoft.Extensions.AI libraries bug This issue describes a behavior which is not expected - a bug.
Projects
None yet
Development

No branches or pull requests

3 participants