136 instantiations of DataContent
Microsoft.Extensions.AI.Abstractions (3)
ChatCompletion\ChatResponseExtensions.cs (1)
290return new DataContent(new ReadOnlyMemory<byte>(ms.GetBuffer(), 0, (int)ms.Length), first.MediaType) { Name = first.Name };
Contents\DataContent.cs (1)
195return new DataContent(new ReadOnlyMemory<byte>(memoryStream.GetBuffer(), 0, (int)memoryStream.Length), mediaType)
Image\ImageGeneratorExtensions.cs (1)
184var dataContent = new DataContent(originalImageData, mediaType) { Name = fileName };
Microsoft.Extensions.AI.Abstractions.Tests (80)
ChatCompletion\ChatMessageTests.cs (4)
146new DataContent("data:text/image;base64,aGVsbG8="), 147new DataContent("data:text/plain;base64,aGVsbG8="), 259new DataContent(new Uri("data:text/plain;base64,aGVsbG8="), "mime-type/2") 263new DataContent(new BinaryData(new[] { 1, 2, 3 }, options: TestJsonSerializerContext.Default.Options), "mime-type/3")
ChatCompletion\ChatResponseUpdateExtensionsTests.cs (8)
662updates.Add(new() { Contents = [new DataContent("data:image/png;base64,aGVsbG8=")] }); 923var image1 = new DataContent((byte[])[1, 2, 3, 4], "image/png") { Name = "image1.png" }; 924var image2 = new DataContent((byte[])[5, 6, 7, 8], "image/jpeg") { Name = "image2.jpg" }; 925var image3 = new DataContent((byte[])[9, 10, 11, 12], "image/png") { Name = "image3.png" }; 926var image4 = new DataContent((byte[])[13, 14, 15, 16], "image/gif") { Name = "image4.gif" }; 981var image1 = new DataContent((byte[])[1, 2, 3, 4], "image/png") { Name = "image1.png" }; 982var image2 = new DataContent((byte[])[5, 6, 7, 8], "image/jpeg") { Name = "image2.jpg" }; 983var image3 = new DataContent((byte[])[9, 10, 11, 12], "image/png") { Name = "image3.png" };
ChatCompletion\ChatResponseUpdateTests.cs (4)
92new DataContent("data:image/audio;base64,aGVsbG8="), 93new DataContent("data:image/image;base64,aGVsbG8="), 122new DataContent("data:image/png;base64,aGVsbG8="), 124new DataContent("data"u8.ToArray(), "text/plain"),
Contents\AIContentTests.cs (2)
65new DataContent(new byte[] { 1, 2, 3 }, "application/octet-stream"), 80new ImageGenerationToolResultContent { ImageId = "img456", Outputs = [new DataContent(new byte[] { 4, 5, 6 }, "image/png")] }
Contents\CodeInterpreterToolCallContentTests.cs (1)
57new DataContent(new byte[] { 1, 2, 3 }, "application/octet-stream")
Contents\CodeInterpreterToolResultContentTests.cs (1)
57new DataContent(new byte[] { 1, 2, 3 }, "application/octet-stream"),
Contents\DataContentTests.cs (37)
49Assert.Throws(exception, () => new DataContent(path)); 61Assert.Throws<ArgumentException>("mediaType", () => new DataContent("data:image/png;base64,aGVsbG8=", type)); 71var content = new DataContent("data:image/png;base64,aGVsbG8=", mediaType); 75content = new DataContent("data:,", mediaType); 79content = new DataContent("data:text/plain,", mediaType); 83content = new DataContent(new Uri("data:text/plain,"), mediaType); 87content = new DataContent(new byte[] { 0, 1, 2 }, mediaType); 91content = new DataContent(content.Uri); 101content = new DataContent("data:image/png;base64,aGVsbG8="); 106content = new DataContent(new Uri("data:image/png;base64,aGVsbG8=")); 127Validate(new DataContent(uri), expectedData); 128Validate(new DataContent(new Uri(uri)), expectedData); 137var content = new DataContent(uri, mediaType); 147new DataContent(uri: "data:application/octet-stream;base64,AQIDBA=="), 153new DataContent(new ReadOnlyMemory<byte>([0x01, 0x02, 0x03, 0x04]), "application/octet-stream"), 159new DataContent(new ReadOnlyMemory<byte>([0x01, 0x02, 0x03, 0x04]), "application/octet-stream") { Name = "test.bin" }, 248DataContent c = new("data:,", mediaType); 261var content = new DataContent("data:application/octet-stream;base64,AQIDBA==", mediaType); 274var content = new DataContent("data:application/octet-stream;base64,AQIDBA==", mediaType); 287var content = new DataContent(data, "application/octet-stream"); 297var content = new DataContent("data:text/plain,hello world"); 306DataContent content = new(new byte[] { 1, 2, 3 }, "application/octet-stream"); 457DataContent content = new(testData, "application/octet-stream"); 484DataContent content = new(testData, "application/json"); 511DataContent content = new(testData, "application/json") 543DataContent content = new(testData, "application/json"); 572DataContent content = new(testData, "application/json"); 598DataContent content = new(testData, "application/json"); 626DataContent content = new(testData, "image/png") { Name = "myimage.png" }; 655DataContent content = new(testData, "text/plain") { Name = $"testfile_{Guid.NewGuid()}.txt" }; 698DataContent content = new(new byte[] { 1 }, "application/octet-stream"); 735DataContent content = new(testData, "text/css"); 792DataContent content = new(new byte[] { 1, 2, 3 }, "application/octet-stream"); 832DataContent content = new(testData, "application/json") 863DataContent content = new(testData, "application/json"); 921DataContent content = new(testData, "application/octet-stream"); 954DataContent content = new(newContent, "application/octet-stream");
Contents\ImageGenerationToolResultContentTests.cs (5)
32IList<AIContent> outputs = [new DataContent(new byte[] { 1, 2, 3 }, "image/png")]; 55new DataContent(new byte[] { 1, 2, 3 }, "image/png"), 57new DataContent(new byte[] { 4, 5, 6 }, "image/gif") 76new DataContent(new byte[] { 1, 2, 3 }, "image/png"), 102new DataContent(new byte[] { 7, 8, 9 }, "image/png"),
Image\ImageGenerationResponseTests.cs (3)
74new DataContent(imageData, "image/jpeg") 100new DataContent((byte[])[1, 2, 3, 4], "image/jpeg") 138new DataContent((byte[])[255, 216, 255, 224], "image/jpeg"),
Image\ImageGeneratorExtensionsTests.cs (3)
64var dataContent = new DataContent(imageData, "image/png") { Name = "test.png" }; 92var dataContent = new DataContent(new byte[] { 1, 2, 3 }, "image/png"); 202var dataContent = new DataContent(imageData, "image/png");
Image\ImageGeneratorTests.cs (1)
139AIContent[] originalImages = [new DataContent((byte[])[1, 2, 3, 4], "image/png")];
SpeechToText\SpeechToTextClientExtensionsTests.cs (3)
28var content = new DataContent("data:audio/wav;base64,AQIDBA=="); 42var content = new DataContent("data:audio/wav;base64,AQIDBA=="); 73new DataContent("data:audio/wav;base64,AQIDBA=="),
SpeechToText\SpeechToTextClientTests.cs (2)
34new DataContent("data:audio/wav;base64,AQIDBA=="), 62new DataContent("data:audio/wav;base64,AQIDBA=="),
SpeechToText\SpeechToTextResponseTests.cs (1)
211new DataContent("data:image/png;base64,AQIDBA==", mediaType: "image/png"),
SpeechToText\SpeechToTextResponseUpdateExtensionsTests.cs (1)
117updates.Add(new() { Contents = [new DataContent("data:image/png;base64,aGVsbG8=")] });
SpeechToText\SpeechToTextResponseUpdateTests.cs (3)
62new DataContent("data:audio/wav;base64,AQIDBA==", "application/octet-stream"), 63new DataContent("data:image/wav;base64,AQIDBA==", "application/octet-stream"), 94new DataContent("data:audio/wav;base64,AQIDBA==", "application/octet-stream")
Tools\HostedCodeInterpreterToolTests.cs (1)
48new DataContent(new byte[] { 1, 2, 3 }, "application/octet-stream")
Microsoft.Extensions.AI.Evaluation.Integration.Tests (2)
SafetyEvaluatorTests.cs (2)
379new DataContent(ImageDataUri.GetImageDataUri())], 413new DataContent(ImageDataUri.GetImageDataUri())],
Microsoft.Extensions.AI.Integration.Tests (7)
ChatClientIntegrationTests.cs (2)
196new DataContent(ImageDataUri.GetImageDataUri(), "image/png"), 214new DataContent(ImageDataUri.GetPdfDataUri(), "application/pdf") { Name = "sample.pdf" },
ImageGeneratingChatClientIntegrationTests.cs (3)
159var originalImageData = new DataContent(testImageData, "image/png") { Name = "original.png" }; 375var originalImage = new DataContent(testImageData, "image/png") { Name = "test.png" }; 422var imageContent = new DataContent(imageData, TestImageMediaType)
ImageGeneratorIntegrationTests.cs (1)
96AIContent[] originalImages = [new DataContent(imageData, "image/png") { Name = "dotnet.png" }];
ToolReductionTests.cs (1)
311new DataContent(new byte[] { 1, 2, 3 }, "application/octet-stream"),
Microsoft.Extensions.AI.OpenAI (12)
OpenAIAssistantsChatClient.cs (1)
208Inputs = [new DataContent(Encoding.UTF8.GetBytes(details.CodeInterpreterInput), OpenAIClientExtensions.PythonMediaType)],
OpenAIChatClient.cs (4)
390responseUpdate.Contents.Add(new DataContent(audioUpdate.AudioBytesUpdate.ToMemory(), GetOutputAudioMimeType(options)) 517returnMessage.Contents.Add(new DataContent(audio.AudioBytes.ToMemory(), GetOutputAudioMimeType(chatCompletionOptions)) 770contentPart.ImageBytes is not null ? new DataContent(contentPart.ImageBytes.ToMemory(), contentPart.ImageBytesMediaType) : 784contentPart.FileBytes is not null ? new DataContent(contentPart.FileBytes.ToMemory(), contentPart.FileBytesMediaType) { Name = contentPart.Filename } :
OpenAIImageGenerator.cs (1)
134contents.Add(new DataContent(image.ImageBytes.ToMemory(), contentType));
OpenAIResponsesChatClient.cs (6)
233Inputs = !string.IsNullOrWhiteSpace(cicri.Code) ? [new DataContent(Encoding.UTF8.GetBytes(cicri.Code), OpenAIClientExtensions.PythonMediaType)] : null, 434Inputs = [new DataContent(Encoding.UTF8.GetBytes(codeInterpreterDeltaUpdate.Delta), OpenAIClientExtensions.PythonMediaType)], 1288content = new DataContent(part.InputFileBytes, part.InputFileBytesMediaType ?? "application/octet-stream") { Name = part.InputFilename }; 1294content = new DataContent(inputImageUrl); 1434Outputs = [new DataContent(outputItem.ImageResultBytes, $"image/{outputFormat}")] 1449new DataContent(update.PartialImageBytes, $"image/{outputType}")
Microsoft.Extensions.AI.OpenAI.Tests (10)
OpenAIChatClientTests.cs (1)
1589new DataContent(ImageDataUri.GetImageDataUri(), "image/png")
OpenAIConversionTests.cs (1)
992new DataContent(new byte[] { 1, 2, 3, 4 }, "application/octet-stream")
OpenAIResponseClientIntegrationTests.cs (3)
489Tools = [AIFunctionFactory.Create(() => new DataContent(ImageDataUri.GetImageDataUri(), "image/png"), "GetDotnetLogo", "Returns the .NET logo image")] 514Tools = [AIFunctionFactory.Create(() => new DataContent(ImageDataUri.GetPdfDataUri(), "application/pdf") { Name = "document.pdf" }, "GetDocument", "Returns a PDF document")] 540new DataContent(imageBytes, "image/png"),
OpenAIResponseClientTests.cs (5)
4311new FunctionResultContent("call_789", new DataContent(imageData, "image/png")) 4547new FunctionResultContent("call_pdf", new DataContent(pdfData, "application/pdf") { Name = "report.pdf" }) 4940new DataContent(imageData, "image/png"), 4941new DataContent(imageData, "image/png") { AdditionalProperties = new AdditionalPropertiesDictionary { ["detail"] = ResponseImageDetailLevel.Low }}, 4942new DataContent(pdfData, "application/pdf") { Name = "doc.pdf" },
Microsoft.Extensions.AI.Tests (20)
ChatCompletion\OpenTelemetryChatClientTests.cs (3)
410new DataContent(Convert.FromBase64String("aGVsbG8gd29ybGQ="), "image/png"), 426yield return new() { Contents = [new DataContent(Convert.FromBase64String("aGVsbG8gd29ybGQ="), "image/png")] }; 446new DataContent(Convert.FromBase64String("ZGF0YSBjb250ZW50"), "audio/mp3"),
Functions\AIFunctionFactoryTest.cs (15)
942AIFunctionFactory.Create(() => new DataContent(new byte[] { 1, 2, 3 }, "application/octet-stream")), 943AIFunctionFactory.Create(async () => new DataContent(new byte[] { 1, 2, 3 }, "application/octet-stream")), 944AIFunctionFactory.Create(async ValueTask<DataContent> () => new DataContent(new byte[] { 1, 2, 3 }, "application/octet-stream")), 949AIFunctionFactory.Create(() => (IEnumerable<AIContent>)[new TextContent("text"), new DataContent(new byte[] { 1, 2, 3 }, "application/octet-stream")]), 950AIFunctionFactory.Create(async () => (IEnumerable<AIContent>)[new TextContent("text"), new DataContent(new byte[] { 1, 2, 3 }, "application/octet-stream")]), 951AIFunctionFactory.Create(async ValueTask<IEnumerable<AIContent>> () => (IEnumerable<AIContent>)[new TextContent("text"), new DataContent(new byte[] { 1, 2, 3 }, "application/octet-stream")]), 956AIFunctionFactory.Create(() => (AIContent[])[new TextContent("text"), new DataContent(new byte[] { 1, 2, 3 }, "application/octet-stream")]), 957AIFunctionFactory.Create(async () => (AIContent[])[new TextContent("text"), new DataContent(new byte[] { 1, 2, 3 }, "application/octet-stream")]), 958AIFunctionFactory.Create(async ValueTask<AIContent[]> () => (AIContent[])[new TextContent("text"), new DataContent(new byte[] { 1, 2, 3 }, "application/octet-stream")]), 963AIFunctionFactory.Create(() => (List<AIContent>)[new TextContent("text"), new DataContent(new byte[] { 1, 2, 3 }, "application/octet-stream")]), 964AIFunctionFactory.Create(async () => (List<AIContent>)[new TextContent("text"), new DataContent(new byte[] { 1, 2, 3 }, "application/octet-stream")]), 965AIFunctionFactory.Create(async ValueTask<List<AIContent>> () => (List<AIContent>)[new TextContent("text"), new DataContent(new byte[] { 1, 2, 3 }, "application/octet-stream")]), 970AIFunctionFactory.Create(() => (IList<AIContent>)[new TextContent("text"), new DataContent(new byte[] { 1, 2, 3 }, "application/octet-stream")]), 971AIFunctionFactory.Create(async () => (IList<AIContent>)[new TextContent("text"), new DataContent(new byte[] { 1, 2, 3 }, "application/octet-stream")]), 972AIFunctionFactory.Create(async ValueTask<IList<AIContent>> () => (List<AIContent>)[new TextContent("text"), new DataContent(new byte[] { 1, 2, 3 }, "application/octet-stream")]),
Image\LoggingImageGeneratorTests.cs (1)
116AIContent[] originalImages = [new DataContent((byte[])[1, 2, 3, 4], "image/png")];
Image\OpenTelemetryImageGeneratorTests.cs (1)
46new DataContent(new byte[] { 1, 2, 3, 4 }, "image/png") { Name = "moreOutput.png" },
Microsoft.Extensions.DataIngestion (1)
Processors\ImageAlternativeTextEnricher.cs (1)
93contents.Add(new DataContent(image.Content!.Value, image.MediaType!));
Microsoft.Extensions.DataIngestion.Tests (1)
IngestionPipelineTests.cs (1)
182content: new(image.Content.GetValueOrDefault(), image.MediaType!),
213 references to DataContent
Microsoft.Extensions.AI (13)
ChatCompletion\ImageGeneratingChatClient.cs (10)
60/// <param name="dataContentHandling">Specifies how to handle <see cref="DataContent"/> instances when passing messages to the inner client. 175void ReplaceImage(string imageId, DataContent dataContent) 186if (content is DataContent dataContent && dataContent.HasTopLevelMediaType("image")) 201if (output is DataContent generatedDataContent && generatedDataContent.HasTopLevelMediaType("image")) 397if (content is DataContent imageContent && imageContent.MediaType.StartsWith("image/", StringComparison.OrdinalIgnoreCase)) 442var originalImage = RetrieveImageContent(imageId); 460if (content is DataContent imageContent && imageContent.MediaType.StartsWith("image/", StringComparison.OrdinalIgnoreCase)) 488private DataContent? RetrieveImageContent(string imageId) 492return imageContent as DataContent; 498private string StoreImage(DataContent imageContent, bool isGenerated = false)
ChatCompletion\OpenTelemetryChatClient.cs (2)
332case DataContent dc: 527if (input is DataContent dc && dc.HasTopLevelMediaType("text"))
Image\LoggingImageGenerator.cs (1)
81if (_logger.IsEnabled(LogLevel.Trace) && response.Contents.All(c => c is not DataContent))
Microsoft.Extensions.AI.Abstractions (31)
ChatCompletion\ChatResponseExtensions.cs (5)
265Coalesce<DataContent>( 276var current = (DataContent)contents[i]; 289var first = (DataContent)contents[start];
Contents\AIContent.cs (1)
11[JsonDerivedType(typeof(DataContent), typeDiscriminator: "data")]
Contents\CodeInterpreterToolCallContent.cs (2)
37/// <see cref="DataContent"/> for binary data, or other <see cref="AIContent"/> types as supported 38/// by the service. Typically <see cref="Inputs"/> includes a <see cref="DataContent"/> with a "text/x-python"
Contents\CodeInterpreterToolResultContent.cs (1)
33/// <see cref="DataContent"/> for binary data, <see cref="TextContent"/> for standard output text,
Contents\DataContent.cs (10)
57/// Initializes a new instance of the <see cref="DataContent"/> class. 74/// Initializes a new instance of the <see cref="DataContent"/> class. 117/// Initializes a new instance of the <see cref="DataContent"/> class. 132/// Loads a <see cref="DataContent"/> from a file path asynchronously. 142/// <returns>A <see cref="DataContent"/> containing the file data with the inferred or specified media type and name.</returns> 145public static async ValueTask<DataContent> LoadFromAsync(string path, string? mediaType = null, CancellationToken cancellationToken = default) 154/// Loads a <see cref="DataContent"/> from a stream asynchronously. 163/// <returns>A <see cref="DataContent"/> containing the stream data with the inferred or specified media type and name.</returns> 165public static async ValueTask<DataContent> LoadFromAsync(Stream stream, string? mediaType = null, CancellationToken cancellationToken = default) 266/// <summary>Gets the data URI for this <see cref="DataContent"/>.</summary>
Contents\HostedFileContent.cs (1)
14/// Unlike <see cref="DataContent"/> which contains the data for a file or blob, this class represents a file that is hosted
Contents\ImageGenerationToolResultContent.cs (1)
36/// Content is typically <see cref="DataContent"/> for images streamed from the tool, or <see cref="UriContent"/> for remotely hosted images, but
Contents\UriContent.cs (1)
16/// For data URIs, use <see cref="DataContent"/> instead.
Image\ImageGenerationResponse.cs (1)
41/// Content is typically <see cref="DataContent"/> for images streamed from the generator, or <see cref="UriContent"/> for remotely hosted images, but
Image\ImageGeneratorExtensions.cs (2)
144DataContent originalImage, 184var dataContent = new DataContent(originalImageData, mediaType) { Name = fileName };
SpeechToText\SpeechToTextClientExtensions.cs (4)
35/// <summary>Generates text from speech providing a single audio speech <see cref="DataContent"/>.</summary> 43DataContent audioSpeechContent, 57/// <summary>Generates text from speech providing a single audio speech <see cref="DataContent"/>.</summary> 65DataContent audioSpeechContent,
Tools\HostedCodeInterpreterTool.cs (1)
39/// represented via <see cref="HostedFileContent"/>. Some also support binary data, represented via <see cref="DataContent"/>.
Tools\HostedFileSearchTool.cs (1)
40/// others might support binary data uploaded as part of the request in <see cref="DataContent"/>, and others might support
Microsoft.Extensions.AI.Abstractions.Tests (92)
ChatCompletion\ChatMessageTests.cs (3)
303var dataContent = deserializedMessage.Contents[1] as DataContent; 311dataContent = deserializedMessage.Contents[2] as DataContent;
ChatCompletion\ChatResponseFormatTests.cs (2)
121ChatResponseFormat.ForJsonSchema<DataContent>() : 122ChatResponseFormat.ForJsonSchema(typeof(DataContent));
ChatCompletion\ChatResponseUpdateExtensionsTests.cs (7)
923var image1 = new DataContent((byte[])[1, 2, 3, 4], "image/png") { Name = "image1.png" }; 924var image2 = new DataContent((byte[])[5, 6, 7, 8], "image/jpeg") { Name = "image2.jpg" }; 925var image3 = new DataContent((byte[])[9, 10, 11, 12], "image/png") { Name = "image3.png" }; 926var image4 = new DataContent((byte[])[13, 14, 15, 16], "image/gif") { Name = "image4.gif" }; 981var image1 = new DataContent((byte[])[1, 2, 3, 4], "image/png") { Name = "image1.png" }; 982var image2 = new DataContent((byte[])[5, 6, 7, 8], "image/jpeg") { Name = "image2.jpg" }; 983var image3 = new DataContent((byte[])[9, 10, 11, 12], "image/png") { Name = "image3.png" };
ChatCompletion\ChatResponseUpdateTests.cs (4)
145Assert.IsType<DataContent>(result.Contents[1]); 146Assert.Equal("data:image/png;base64,aGVsbG8=", ((DataContent)result.Contents[1]).Uri); 151Assert.IsType<DataContent>(result.Contents[3]); 152Assert.Equal("data"u8.ToArray(), ((DataContent)result.Contents[3]).Data.ToArray());
Contents\CodeInterpreterToolCallContentTests.cs (1)
65Assert.IsType<DataContent>(c.Inputs[2]);
Contents\CodeInterpreterToolResultContentTests.cs (1)
66Assert.IsType<DataContent>(c.Outputs[2]);
Contents\DataContentTests.cs (53)
71var content = new DataContent("data:image/png;base64,aGVsbG8=", mediaType); 99DataContent content; 121static void Validate(DataContent content, string expectedData) 137var content = new DataContent(uri, mediaType); 168Assert.Throws<ArgumentNullException>("uri", () => JsonSerializer.Deserialize<DataContent>(json, TestJsonSerializerContext.Default.Options)!); 175var content = JsonSerializer.Deserialize<DataContent>("""{"uri":"data:application/octet-stream;base64,AQIDBA=="}""", TestJsonSerializerContext.Default.Options)!; 183content = JsonSerializer.Deserialize<DataContent>("""{"uri":"data:application/octet-stream;base64,AQIDBA=="}""", TestJsonSerializerContext.Default.Options)!; 189content = JsonSerializer.Deserialize<DataContent>(""" 216var content = JsonSerializer.Deserialize<DataContent>(serialized, TestJsonSerializerContext.Default.Options)!; 248DataContent c = new("data:,", mediaType); 261var content = new DataContent("data:application/octet-stream;base64,AQIDBA==", mediaType); 274var content = new DataContent("data:application/octet-stream;base64,AQIDBA==", mediaType); 287var content = new DataContent(data, "application/octet-stream"); 297var content = new DataContent("data:text/plain,hello world"); 306DataContent content = new(new byte[] { 1, 2, 3 }, "application/octet-stream"); 323DataContent content = await DataContent.LoadFromAsync(tempPath); 350DataContent content = await DataContent.LoadFromAsync(tempPath, "custom/type"); 377DataContent content = await DataContent.LoadFromAsync(tempPath); 404DataContent content = await DataContent.LoadFromAsync(fs); 428DataContent content = await DataContent.LoadFromAsync(ms, "video/mp4"); 444DataContent content = await DataContent.LoadFromAsync(ms); 457DataContent content = new(testData, "application/octet-stream"); 484DataContent content = new(testData, "application/json"); 511DataContent content = new(testData, "application/json") 543DataContent content = new(testData, "application/json"); 572DataContent content = new(testData, "application/json"); 598DataContent content = new(testData, "application/json"); 626DataContent content = new(testData, "image/png") { Name = "myimage.png" }; 655DataContent content = new(testData, "text/plain") { Name = $"testfile_{Guid.NewGuid()}.txt" }; 680await Assert.ThrowsAsync<ArgumentNullException>("path", async () => await DataContent.LoadFromAsync((string)null!)); 686await Assert.ThrowsAsync<ArgumentException>("path", async () => await DataContent.LoadFromAsync(string.Empty)); 692await Assert.ThrowsAsync<ArgumentNullException>("stream", async () => await DataContent.LoadFromAsync((Stream)null!)); 698DataContent content = new(new byte[] { 1 }, "application/octet-stream"); 716DataContent content = await DataContent.LoadFromAsync(filePath); 735DataContent content = new(testData, "text/css"); 776await DataContent.LoadFromAsync(tempPath, cancellationToken: cts.Token)); 792DataContent content = new(new byte[] { 1, 2, 3 }, "application/octet-stream"); 825await DataContent.LoadFromAsync(ms, cancellationToken: cts.Token)); 832DataContent content = new(testData, "application/json") 863DataContent content = new(testData, "application/json"); 900DataContent content = await DataContent.LoadFromAsync(tempPath); 921DataContent content = new(testData, "application/octet-stream"); 954DataContent content = new(newContent, "application/octet-stream");
Contents\ImageGenerationToolResultContentTests.cs (5)
63Assert.IsType<DataContent>(c.Outputs[0]); 65Assert.IsType<DataContent>(c.Outputs[2]); 88Assert.IsType<DataContent>(deserializedSut.Outputs[0]); 89Assert.Equal("image/png", ((DataContent)deserializedSut.Outputs[0]).MediaType); 120Assert.IsType<DataContent>(imageResult.Outputs[0]);
Image\ImageGenerationResponseTests.cs (3)
116DataContent dataContent = Assert.IsType<DataContent>(deserialized.Contents[1]); 151Assert.IsType<DataContent>(deserialized.Contents[1]);
Image\ImageGeneratorExtensionsTests.cs (7)
64var dataContent = new DataContent(imageData, "image/png") { Name = "test.png" }; 92var dataContent = new DataContent(new byte[] { 1, 2, 3 }, "image/png"); 120var dataContent = Assert.IsType<DataContent>(Assert.Single(request.OriginalImages)); 187var dataContent = Assert.IsType<DataContent>(Assert.Single(request.OriginalImages)); 202var dataContent = new DataContent(imageData, "image/png");
SpeechToText\SpeechToTextClientExtensionsTests.cs (4)
28var content = new DataContent("data:audio/wav;base64,AQIDBA=="); 33DataContent? nullContent = null; 42var content = new DataContent("data:audio/wav;base64,AQIDBA=="); 47DataContent? nullContent = null;
SpeechToText\SpeechToTextResponseTests.cs (1)
237Assert.Equal("image/png", Assert.IsType<DataContent>(update.Contents[1]).MediaType);
Tools\HostedCodeInterpreterToolTests.cs (1)
55Assert.IsType<DataContent>(tool.Inputs[1]);
Microsoft.Extensions.AI.Evaluation (1)
EvaluationContext.cs (1)
59/// <see cref="TextContent"/> objects for text, <see cref="DataContent"/> or <see cref="UriContent"/> objects for
Microsoft.Extensions.AI.Evaluation.Safety (4)
AIContentExtensions.cs (1)
15(content is DataContent dataContent && IsSupportedImageFormat(dataContent.MediaType));
ContentSafetyServicePayloadUtilities.cs (3)
340else if (content is DataContent dataContent && dataContent.HasTopLevelMediaType("image")) 515$"The current evaluation being performed by {evaluatorName} only supports content of type '{nameof(TextContent)}', '{nameof(UriContent)}' and '{nameof(DataContent)}'. " + 516$"For '{nameof(UriContent)}' and '{nameof(DataContent)}', only content with media type 'image/png', 'image/jpeg' and 'image/gif' are supported. " +
Microsoft.Extensions.AI.Integration.Tests (29)
ImageGeneratingChatClientIntegrationTests.cs (22)
92foreach (var dataContent in toolResult.Outputs.OfType<DataContent>()) 145var imageContent = Assert.Single(imageResult.Outputs.OfType<DataContent>()); 159var originalImageData = new DataContent(testImageData, "image/png") { Name = "original.png" }; 175var originalImageContent = Assert.IsType<DataContent>(originalImage); 217var firstContent = Assert.Single(firstToolResultContent.Outputs.OfType<DataContent>()); 221Assert.Single(secondResponse.Messages.SelectMany(m => m.Contents).OfType<ImageGenerationToolResultContent>().SelectMany(t => t.Outputs!.OfType<DataContent>())); 226var editedImage = Assert.IsType<DataContent>(secondRequest.OriginalImages.First()); 271var secondImage = Assert.Single(secondToolResultContent.Outputs!.OfType<DataContent>()); 272var lastImageToEdit = Assert.Single(thirdRequest.OriginalImages.OfType<DataContent>()); 316var firstGeneratedImage = Assert.Single(firstToolResultContent.Outputs!.OfType<DataContent>()); 317var lastImageToEdit = Assert.IsType<DataContent>(thirdRequest.OriginalImages.First()); 375var originalImage = new DataContent(testImageData, "image/png") { Name = "test.png" }; 422var imageContent = new DataContent(imageData, TestImageMediaType)
ImageGeneratorIntegrationTests.cs (7)
54case DataContent dc: 83Assert.IsType<DataContent>(content); 84var dataContent = (DataContent)content; 110Assert.IsType<DataContent>(content); 111var dataContent = (DataContent)content;
Microsoft.Extensions.AI.OpenAI (9)
MicrosoftExtensionsAIChatExtensions.cs (1)
86outputAudio: lastMessage?.Contents.OfType<DataContent>().Where(dc => dc.HasTopLevelMediaType("audio")).Select(a => OpenAIChatModelFactory.ChatOutputAudio(new(a.Data))).FirstOrDefault(),
OpenAIChatClient.cs (3)
296case DataContent dataContent when dataContent.HasTopLevelMediaType("image"): 300case DataContent dataContent when dataContent.HasTopLevelMediaType("audio"): 313case DataContent dataContent when dataContent.MediaType.StartsWith("application/pdf", StringComparison.OrdinalIgnoreCase):
OpenAIImageGenerator.cs (1)
64if (originalImage is DataContent dataContent)
OpenAIResponsesChatClient.cs (4)
967case DataContent dataContent when dataContent.HasTopLevelMediaType("image"): 971case DataContent dataContent when dataContent.MediaType.StartsWith("application/pdf", StringComparison.OrdinalIgnoreCase): 1031case DataContent dc when dc.HasTopLevelMediaType("image"): 1039case DataContent dc:
Microsoft.Extensions.AI.OpenAI.Tests (16)
OpenAIAssistantChatClientIntegrationTests.cs (1)
77if (toolCallContent.Inputs.OfType<DataContent>().FirstOrDefault() is { } codeInput)
OpenAIResponseClientIntegrationTests.cs (2)
53var codeInput = toolCallContent.Inputs.OfType<DataContent>().FirstOrDefault();
OpenAIResponseClientTests.cs (13)
2904var codeInput = Assert.IsType<DataContent>(Assert.Single(codeCall.Inputs)); 3124var codeInput = Assert.IsType<DataContent>(Assert.Single(codeCall.Inputs)); 3223var dataContent = content.Inputs.OfType<DataContent>().FirstOrDefault(); 3250var codeInput = Assert.IsType<DataContent>(Assert.Single(codeCall.Inputs)); 5659var imageContent = userMessage.Contents.OfType<DataContent>().FirstOrDefault(); 5756var imageData = toolResult.Outputs![0] as DataContent; 6005return o is DataContent dataContent && dataContent.MediaType == "image/webp";
Microsoft.Extensions.AI.Tests (2)
Functions\AIFunctionFactoryTest.cs (2)
940await ValidateAsync<DataContent>( 944AIFunctionFactory.Create(async ValueTask<DataContent> () => new DataContent(new byte[] { 1, 2, 3 }, "application/octet-stream")),
Microsoft.Extensions.DataIngestion.MarkItDown (5)
MarkItDownMcpReader.cs (5)
47DataContent dataContent = await DataContent.LoadFromAsync(source.FullName, mediaType, cancellationToken).ConfigureAwait(false); 61DataContent dataContent = await DataContent.LoadFromAsync(source, mediaType, cancellationToken).ConfigureAwait(false); 68private async Task<string> ConvertToMarkdownAsync(DataContent dataContent, CancellationToken cancellationToken)
Microsoft.Extensions.DataIngestion.Tests (11)
IngestionPipelineTests.cs (7)
152TestEmbeddingGenerator<DataContent> embeddingGenerator = new(); 154using VectorStoreWriter<DataContent> vectorStoreWriter = new(testVectorStore, dimensionCount: TestEmbeddingGenerator<DataContent>.DimensionCount); 155using IngestionPipeline<DataContent> pipeline = new(CreateReader(), new ImageChunker(), vectorStoreWriter); 176internal class ImageChunker : IngestionChunker<DataContent> 178public override IAsyncEnumerable<IngestionChunk<DataContent>> ProcessAsync(IngestionDocument document, CancellationToken cancellationToken = default) 181.Select(image => new IngestionChunk<DataContent>(
Processors\AlternativeTextEnricherTests.cs (4)
54DataContent dataContent = Assert.IsType<DataContent>(content); 141DataContent dataContent = Assert.IsType<DataContent>(content);