Skip to content

[FEATURE REQ] Add more Create overloads to BinaryContent #50920

Closed
@KrzysztofCwalina

Description

@KrzysztofCwalina

Library name

System.ClientModel

Please describe the feature.

BinaryContent is used all protocol method scenarios. A typical usage today looks like the following

BinaryContent content = BinaryContent.Create(BinaryData.FromObjectAsJson(
    new {
        model = "gpt-4.1",
        prompt = new {
            id = "pmpt_abc123",
            version = "2",
            variables = new {
                customer_name = "Jane Doe",
                product = "40oz juice box"
            }
        }
    }

It would be nice to simplify it to:

BinaryContent content = BinaryContent.CreateJson(
    new {
        model = "gpt-4.1",
        prompt = new {
            id = "pmpt_abc123",
            version = "2",
            variables = new {
                customer_name = "Jane Doe",
                product = "40oz juice box"
            }
        }
    }

Similarly with other scenarios that consume BinaryData. And so we should the following members to BinaryContent

public string? MediaType { get; }
public static BinaryContent CreateJson<T>(T jsonSerializable, System.Text.Json.JsonSerializerOptions? options = default);System.Text.Json.Serialization.Metadata.JsonTypeInfo<T> jsonTypeInfo
public static BinaryContent CreateJson<T>(T jsonSerializable, System.Text.Json.Serialization.Metadata.JsonTypeInfo<T> jsonTypeInfo);

Metadata

Metadata

Labels

ClientThis issue is related to a non-management packageSystem.ClientModelBase Core library

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions