Skip to content

[API Proposal]: [MEAI] Add possibility to set image detail level for OpenAI. #6198

@NiceWaffel

Description

@NiceWaffel

Background and motivation

The OpenAI API allows for specifying the detail level for images, by setting the parameter detail to either low, high or auto.

I imagine this is similar to issue #5524, which was closed due to ImageContent being removed.

API Proposal

Setting the image detail level is provider specific. As such, allowing the property to be set using the AdditionalProperties of the DataContent makes the most sense to me.

API Usage

var content = new DataContent("https://uri.to/image.png", "image/png");
content.AdditionalProperties = new AdditionalPropertiesDictionary { ["detail"] = "high" };
var message = new ChatMessage(ChatRole.User, [content]);

Alternative Designs

Optionally, extension methods could be added to set the detail level, such that the dictionary doesn't need to be created manually. I.e.:

public static class DataContentImageDetailExtensions
{
    public static void SetHighImageDetail(this DataContent content)
    {
        content.AdditionalProperties ??= new AdditionalPropertiesDictionary();
        content.AdditionalProperties["detail"] = "high";
    }

    public static void SetLowImageDetail(this DataContent content)
    {
        content.AdditionalProperties ??= new AdditionalPropertiesDictionary();
        content.AdditionalProperties["detail"] = "low";
    }
}

Risks

No response

Metadata

Metadata

Assignees

Labels

area-aiMicrosoft.Extensions.AI libraries

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions