extensions icon indicating copy to clipboard operation
extensions copied to clipboard

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

Open NiceWaffel opened this issue 1 year ago • 0 comments

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

NiceWaffel avatar Mar 26 '25 11:03 NiceWaffel