196 instantiations of DataContent
Microsoft.Extensions.AI.Abstractions (5)
ChatCompletion\ChatResponseExtensions.cs (1)
345return 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)
Files\HostedFileDownloadStream.cs (1)
107return new DataContent(
Generated\Basic.CompilerLog.Util\Basic.CompilerLog.Util.Impl.BasicGeneratedFilesAnalyzerReference\JsonContext.DataContent.g.cs (1)
34ObjectWithParameterizedConstructorCreator = static args => new global::Microsoft.Extensions.AI.DataContent((string)args[0], (string)args[1]),
Image\ImageGeneratorExtensions.cs (1)
184var dataContent = new DataContent(originalImageData, mediaType) { Name = fileName };
Microsoft.Extensions.AI.Abstractions.Tests (110)
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 (6)
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"), 185new DataContent("data:image/png;base64,aGVsbG8="), 187new DataContent("data"u8.ToArray(), "text/plain"),
Contents\AIContentTests.cs (2)
69new DataContent(new byte[] { 1, 2, 3 }, "application/octet-stream"), 84new ImageGenerationToolResultContent("img456") { Outputs = [new DataContent(new byte[] { 4, 5, 6 }, "image/png")] },
Contents\CodeInterpreterToolCallContentTests.cs (1)
54new DataContent(new byte[] { 1, 2, 3 }, "application/octet-stream")
Contents\CodeInterpreterToolResultContentTests.cs (1)
54new 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"); 628DataContent content = new(testData, "image/png") { Name = "myimage.png" }; 657DataContent content = new(testData, "text/plain") { Name = $"testfile_{Guid.NewGuid()}.txt" }; 702DataContent content = new(new byte[] { 1 }, "application/octet-stream"); 739DataContent content = new(testData, "text/css"); 796DataContent content = new(new byte[] { 1, 2, 3 }, "application/octet-stream"); 836DataContent content = new(testData, "application/json") 867DataContent content = new(testData, "application/json"); 925DataContent content = new(testData, "application/octet-stream"); 958DataContent content = new(newContent, "application/octet-stream");
Contents\ImageGenerationToolResultContentTests.cs (5)
31IList<AIContent> outputs = [new DataContent(new byte[] { 1, 2, 3 }, "image/png")]; 53new DataContent(new byte[] { 1, 2, 3 }, "image/png"), 55new DataContent(new byte[] { 4, 5, 6 }, "image/gif") 73new DataContent(new byte[] { 1, 2, 3 }, "image/png"), 98new DataContent(new byte[] { 7, 8, 9 }, "image/png"),
Contents\ToolApprovalRequestContentTests.cs (1)
26new CodeInterpreterToolCallContent("CI1") { Inputs = [new DataContent("print('hello')"u8.ToArray(), "text/x-python")] },
Contents\ToolApprovalResponseContentTests.cs (1)
26new CodeInterpreterToolCallContent("CI1") { Inputs = [new DataContent("print('hello')"u8.ToArray(), "text/x-python")] },
Files\HostedFileClientExtensionsTests.cs (2)
19var content = new DataContent(data, "application/pdf") { Name = "doc.pdf" }; 49var content = new DataContent(new byte[] { 1 }, "text/plain");
Generated\Basic.CompilerLog.Util\Basic.CompilerLog.Util.Impl.BasicGeneratedFilesAnalyzerReference\TestJsonSerializerContext.DataContent.g.cs (1)
32ObjectWithParameterizedConstructorCreator = static args => new global::Microsoft.Extensions.AI.DataContent((string)args[0], (string)args[1]),
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")];
Realtime\RealtimeClientMessageTests.cs (4)
76var audioContent = new DataContent(new byte[] { 1, 2, 3 }, "audio/pcm"); 85var audioContent = new DataContent(new byte[] { 1, 2, 3 }, "audio/pcm"); 88var newContent = new DataContent(new byte[] { 4, 5, 6 }, "audio/wav"); 97var audioContent = new DataContent(new byte[] { 1, 2, 3 }, "audio/pcm");
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")
TextToSpeech\DelegatingTextToSpeechClientTests.cs (2)
61new([new DataContent(new byte[] { 1, 2 }, "audio/mpeg")]), 62new([new DataContent(new byte[] { 3, 4 }, "audio/mpeg")])
TextToSpeech\TextToSpeechClientTests.cs (4)
24return Task.FromResult(new TextToSpeechResponse([new DataContent(new byte[] { 1, 2, 3 }, "audio/mpeg")])); 68yield return new([new DataContent(new byte[] { 1 }, "audio/mpeg")]); 69yield return new([new DataContent(new byte[] { 2 }, "audio/mpeg")]); 70yield return new([new DataContent(new byte[] { 3 }, "audio/mpeg")]);
TextToSpeech\TextToSpeechResponseTests.cs (6)
41content.Add(new DataContent(new byte[] { (byte)i }, "audio/mpeg")); 84List<AIContent> newContents = [new DataContent(new byte[] { 1 }, "audio/mpeg"), new DataContent(new byte[] { 2 }, "audio/mpeg")]; 101new DataContent(new byte[] { 1, 2, 3 }, "audio/mpeg"), 142new DataContent(new byte[] { 1, 2, 3 }, "audio/mpeg"), 143new DataContent(new byte[] { 4, 5, 6 }, "audio/wav"),
TextToSpeech\TextToSpeechResponseUpdateExtensionsTests.cs (5)
26new([new DataContent(new byte[] { 1 }, "audio/mpeg")]) { ModelId = "model123", AdditionalProperties = new() { ["a"] = "b" } }, 27new([new DataContent(new byte[] { 2 }, "audio/mpeg")]) { ModelId = "model123" }, 28new([new DataContent(new byte[] { 3 }, "audio/mpeg")]) { ModelId = "model123", AdditionalProperties = new() { ["c"] = "d" } }, 57new() { Contents = [new DataContent(new byte[] { 1 }, "audio/mpeg")] }, 59new() { Contents = [new DataContent(new byte[] { 2 }, "audio/mpeg")] },
TextToSpeech\TextToSpeechResponseUpdateTests.cs (2)
33List<AIContent> newList = [new DataContent(new byte[] { 1 }, "audio/mpeg")]; 53new DataContent(new byte[] { 1, 2, 3 }, "audio/mpeg"),
Tools\HostedCodeInterpreterToolTests.cs (1)
48new DataContent(new byte[] { 1, 2, 3 }, "application/octet-stream")
Microsoft.Extensions.AI.Evaluation.Integration.Tests (2)
SafetyEvaluatorTests.cs (2)
378new DataContent(ImageDataUri.GetImageDataUri())], 412new DataContent(ImageDataUri.GetImageDataUri())],
Microsoft.Extensions.AI.Evaluation.Reporting (1)
Generated\Basic.CompilerLog.Util\Basic.CompilerLog.Util.Impl.BasicGeneratedFilesAnalyzerReference\JsonContext.DataContent.g.cs (1)
34ObjectWithParameterizedConstructorCreator = static args => new global::Microsoft.Extensions.AI.DataContent((string)args[0], (string)args[1]),
Microsoft.Extensions.AI.Evaluation.Reporting.Azure (1)
Generated\Basic.CompilerLog.Util\Basic.CompilerLog.Util.Impl.BasicGeneratedFilesAnalyzerReference\JsonContext.DataContent.g.cs (1)
34ObjectWithParameterizedConstructorCreator = static args => new global::Microsoft.Extensions.AI.DataContent((string)args[0], (string)args[1]),
Microsoft.Extensions.AI.Evaluation.Reporting.Tests (1)
ScenarioRunResultTests.cs (1)
238new DataContent(new byte[] { 0x89, 0x50, 0x4E, 0x47 }, "image/png"),
Microsoft.Extensions.AI.Integration.Tests (6)
ChatClientIntegrationTests.cs (2)
186new DataContent(ImageDataUri.GetImageDataUri(), "image/png"), 204new DataContent(ImageDataUri.GetPdfDataUri(), "application/pdf") { Name = "sample.pdf" },
ImageGeneratingChatClientIntegrationTests.cs (3)
158var originalImageData = new DataContent(testImageData, "image/png") { Name = "original.png" }; 374var originalImage = new DataContent(testImageData, "image/png") { Name = "test.png" }; 421var imageContent = new DataContent(imageData, TestImageMediaType)
ImageGeneratorIntegrationTests.cs (1)
95AIContent[] originalImages = [new DataContent(imageData, "image/png") { Name = "dotnet.png" }];
Microsoft.Extensions.AI.OpenAI (18)
OpenAIAssistantsChatClient.cs (1)
207Inputs = [new DataContent(Encoding.UTF8.GetBytes(details.CodeInterpreterInput), OpenAIClientExtensions.PythonMediaType)],
OpenAIChatClient.cs (4)
402responseUpdate.Contents.Add(new DataContent(audioUpdate.AudioBytesUpdate.ToMemory(), GetOutputAudioMimeType(options)) 529returnMessage.Contents.Add(new DataContent(audio.AudioBytes.ToMemory(), GetOutputAudioMimeType(chatCompletionOptions)) 795contentPart.ImageBytes is not null ? new DataContent(contentPart.ImageBytes.ToMemory(), contentPart.ImageBytesMediaType) : 809contentPart.FileBytes is not null ? new DataContent(contentPart.FileBytes.ToMemory(), contentPart.FileBytesMediaType) { Name = contentPart.Filename } :
OpenAIFileDownloadStream.cs (1)
49return Task.FromResult(new DataContent(_data.ToMemory(), MediaType ?? "application/octet-stream")
OpenAIImageGenerator.cs (1)
120contents.Add(new DataContent(image.ImageBytes.ToMemory(), contentType));
OpenAIRealtimeClientSession.cs (3)
1140contents.Add(new DataContent($"data:audio/pcm;base64,{Convert.ToBase64String(audioPart.AudioBytes.ToArray())}")); 1152contents.Add(new DataContent($"data:audio/pcm;base64,{Convert.ToBase64String(outputAudioPart.AudioBytes.ToArray())}")); 1157contents.Add(new DataContent(imagePart.ImageUri.ToString()));
OpenAIResponsesChatClient.cs (6)
258Inputs = !string.IsNullOrWhiteSpace(cicri.Code) ? [new DataContent(Encoding.UTF8.GetBytes(cicri.Code), OpenAIClientExtensions.PythonMediaType)] : null, 501Inputs = [new DataContent(Encoding.UTF8.GetBytes(codeInterpreterDeltaUpdate.Delta), OpenAIClientExtensions.PythonMediaType)], 1706content = new DataContent(part.InputFileBytes, part.InputFileBytesMediaType ?? "application/octet-stream") { Name = part.InputFilename }; 1712content = new DataContent(inputImageUrl); 1975Outputs = [new DataContent(outputItem.ImageResultBytes, $"image/{outputFormat}")] 1989new DataContent(update.PartialImageBytes, $"image/{outputType}")
OpenAITextToSpeechClient.cs (2)
72return new TextToSpeechResponse([new DataContent(result.Value.ToMemory(), mediaType)]) 121Contents = [new DataContent(deltaUpdate.AudioBytes.ToMemory(), mediaType)],
Microsoft.Extensions.AI.OpenAI.Tests (12)
OpenAIChatClientTests.cs (1)
1590new DataContent(ImageDataUri.GetImageDataUri(), "image/png")
OpenAIConversionTests.cs (2)
442new Uri(new DataContent((byte[])[0x89, 0x50, 0x4E, 0x47], "image/png").Uri)); 1523new DataContent(new byte[] { 1, 2, 3, 4 }, "application/octet-stream")
OpenAIHostedFileClientIntegrationTests.cs (1)
178var dataContent = new DataContent(contentBytes, "text/plain") { Name = fileName };
OpenAIResponseClientIntegrationTests.cs (3)
615Tools = [AIFunctionFactory.Create(() => new DataContent(ImageDataUri.GetImageDataUri(), "image/png"), "GetDotnetLogo", "Returns the .NET logo image")] 640Tools = [AIFunctionFactory.Create(() => new DataContent(ImageDataUri.GetPdfDataUri(), "application/pdf") { Name = "document.pdf" }, "GetDocument", "Returns a PDF document")] 666new DataContent(imageBytes, "image/png"),
OpenAIResponseClientTests.cs (5)
4942new FunctionResultContent("call_789", new DataContent(imageData, "image/png")) 5178new FunctionResultContent("call_pdf", new DataContent(pdfData, "application/pdf") { Name = "report.pdf" }) 5573new DataContent(imageData, "image/png"), 5574new DataContent(imageData, "image/png") { AdditionalProperties = new AdditionalPropertiesDictionary { ["detail"] = ResponseImageDetailLevel.Low }}, 5575new DataContent(pdfData, "application/pdf") { Name = "doc.pdf" },
Microsoft.Extensions.AI.Stabilization.Tests (9)
Generated\361d1da7f942c932\AIContentSerializationRegressionContext.DataContent.g.cs (1)
32ObjectWithParameterizedConstructorCreator = static args => new global::Microsoft.Extensions.AI.DataContent((string)args[0], (string)args[1]),
parent\Microsoft.Extensions.AI.Abstractions.Tests\Contents\CodeInterpreterToolCallContentTests.cs (1)
54new DataContent(new byte[] { 1, 2, 3 }, "application/octet-stream")
parent\Microsoft.Extensions.AI.Abstractions.Tests\Contents\CodeInterpreterToolResultContentTests.cs (1)
54new DataContent(new byte[] { 1, 2, 3 }, "application/octet-stream"),
parent\Microsoft.Extensions.AI.Abstractions.Tests\Contents\ImageGenerationToolResultContentTests.cs (5)
31IList<AIContent> outputs = [new DataContent(new byte[] { 1, 2, 3 }, "image/png")]; 53new DataContent(new byte[] { 1, 2, 3 }, "image/png"), 55new DataContent(new byte[] { 4, 5, 6 }, "image/gif") 73new DataContent(new byte[] { 1, 2, 3 }, "image/png"), 98new DataContent(new byte[] { 7, 8, 9 }, "image/png"),
parent\Microsoft.Extensions.AI.Abstractions.Tests\Tools\HostedCodeInterpreterToolTests.cs (1)
48new DataContent(new byte[] { 1, 2, 3 }, "application/octet-stream")
Microsoft.Extensions.AI.Tests (29)
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)
1172AIFunctionFactory.Create(() => new DataContent(new byte[] { 1, 2, 3 }, "application/octet-stream")), 1173AIFunctionFactory.Create(async () => new DataContent(new byte[] { 1, 2, 3 }, "application/octet-stream")), 1174AIFunctionFactory.Create(async ValueTask<DataContent> () => new DataContent(new byte[] { 1, 2, 3 }, "application/octet-stream")), 1179AIFunctionFactory.Create(() => (IEnumerable<AIContent>)[new TextContent("text"), new DataContent(new byte[] { 1, 2, 3 }, "application/octet-stream")]), 1180AIFunctionFactory.Create(async () => (IEnumerable<AIContent>)[new TextContent("text"), new DataContent(new byte[] { 1, 2, 3 }, "application/octet-stream")]), 1181AIFunctionFactory.Create(async ValueTask<IEnumerable<AIContent>> () => (IEnumerable<AIContent>)[new TextContent("text"), new DataContent(new byte[] { 1, 2, 3 }, "application/octet-stream")]), 1186AIFunctionFactory.Create(() => (AIContent[])[new TextContent("text"), new DataContent(new byte[] { 1, 2, 3 }, "application/octet-stream")]), 1187AIFunctionFactory.Create(async () => (AIContent[])[new TextContent("text"), new DataContent(new byte[] { 1, 2, 3 }, "application/octet-stream")]), 1188AIFunctionFactory.Create(async ValueTask<AIContent[]> () => (AIContent[])[new TextContent("text"), new DataContent(new byte[] { 1, 2, 3 }, "application/octet-stream")]), 1193AIFunctionFactory.Create(() => (List<AIContent>)[new TextContent("text"), new DataContent(new byte[] { 1, 2, 3 }, "application/octet-stream")]), 1194AIFunctionFactory.Create(async () => (List<AIContent>)[new TextContent("text"), new DataContent(new byte[] { 1, 2, 3 }, "application/octet-stream")]), 1195AIFunctionFactory.Create(async ValueTask<List<AIContent>> () => (List<AIContent>)[new TextContent("text"), new DataContent(new byte[] { 1, 2, 3 }, "application/octet-stream")]), 1200AIFunctionFactory.Create(() => (IList<AIContent>)[new TextContent("text"), new DataContent(new byte[] { 1, 2, 3 }, "application/octet-stream")]), 1201AIFunctionFactory.Create(async () => (IList<AIContent>)[new TextContent("text"), new DataContent(new byte[] { 1, 2, 3 }, "application/octet-stream")]), 1202AIFunctionFactory.Create(async ValueTask<IList<AIContent>> () => (List<AIContent>)[new TextContent("text"), new DataContent(new byte[] { 1, 2, 3 }, "application/octet-stream")]),
Generated\Basic.CompilerLog.Util\Basic.CompilerLog.Util.Impl.BasicGeneratedFilesAnalyzerReference\TestJsonSerializerContext.DataContent.g.cs (1)
32ObjectWithParameterizedConstructorCreator = static args => new global::Microsoft.Extensions.AI.DataContent((string)args[0], (string)args[1]),
Image\LoggingImageGeneratorTests.cs (1)
116AIContent[] originalImages = [new DataContent((byte[])[1, 2, 3, 4], "image/png")];
Image\OpenTelemetryImageGeneratorTests.cs (1)
48new DataContent(new byte[] { 1, 2, 3, 4 }, "image/png") { Name = "moreOutput.png" },
Realtime\OpenTelemetryRealtimeClientTests.cs (2)
580yield return new InputAudioBufferAppendRealtimeClientMessage(new DataContent(new byte[] { 1, 2, 3 }, "audio/pcm")); 1020var imageData = new DataContent(new byte[] { 0x89, 0x50, 0x4E, 0x47 }, "image/png");
TextToSpeech\LoggingTextToSpeechClientTests.cs (3)
59return Task.FromResult(new TextToSpeechResponse([new DataContent(new byte[] { 1, 2, 3 }, "audio/mpeg")])); 110yield return new([new DataContent(new byte[] { 1 }, "audio/mpeg")]); 111yield return new([new DataContent(new byte[] { 2 }, "audio/mpeg")]);
TextToSpeech\OpenTelemetryTextToSpeechClientTests.cs (3)
44return new([new DataContent(new byte[] { 1, 2, 3 }, "audio/mpeg")]) 66yield return new([new DataContent(new byte[] { 1 }, "audio/mpeg")]); 71new DataContent(new byte[] { 2 }, "audio/mpeg"),
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!),
454 references to DataContent
Microsoft.Extensions.AI (14)
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")) 394if (content is DataContent imageContent && imageContent.MediaType.StartsWith("image/", StringComparison.OrdinalIgnoreCase)) 439var originalImage = RetrieveImageContent(imageId); 457if (content is DataContent imageContent && imageContent.MediaType.StartsWith("image/", StringComparison.OrdinalIgnoreCase)) 485private DataContent? RetrieveImageContent(string imageId) 489return imageContent as DataContent; 495private string StoreImage(DataContent imageContent, bool isGenerated = false)
Common\OtelMessageSerializer.cs (2)
94case DataContent dc: 290if (input is DataContent dc && dc.HasTopLevelMediaType("text"))
Image\LoggingImageGenerator.cs (1)
81if (_logger.IsEnabled(LogLevel.Trace) && response.Contents.All(c => c is not DataContent))
Realtime\OpenTelemetryRealtimeClientSession.cs (1)
557case DataContent dc:
Microsoft.Extensions.AI.Abstractions (66)
ChatCompletion\ChatResponseExtensions.cs (5)
320Coalesce<DataContent>( 331var current = (DataContent)contents[i]; 344var first = (DataContent)contents[start];
Contents\AIContent.cs (1)
11[JsonDerivedType(typeof(DataContent), typeDiscriminator: "data")]
Contents\CodeInterpreterToolCallContent.cs (2)
31/// <see cref="DataContent"/> for binary data, or other <see cref="AIContent"/> types as supported 32/// by the service. Typically <see cref="Inputs"/> includes a <see cref="DataContent"/> with a "text/x-python"
Contents\CodeInterpreterToolResultContent.cs (1)
27/// <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)
17/// 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)
30/// 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)
17/// For data URIs, use <see cref="DataContent"/> instead.
Files\HostedFileClientExtensions.cs (5)
23/// Uploads content from a <see cref="DataContent"/>. 34DataContent content, 168/// Downloads a file and returns its content as a buffered <see cref="DataContent"/>. 174/// <returns>The file content as a <see cref="DataContent"/>.</returns> 183public static async Task<DataContent> DownloadAsDataContentAsync(
Files\HostedFileDownloadStream.cs (4)
25/// the entire stream content into a <see cref="DataContent"/> instance. 89/// Reads the entire stream content from its current position and returns it as a <see cref="DataContent"/>. 92/// <returns>A <see cref="DataContent"/> containing the buffered file content.</returns> 97public virtual async Task<DataContent> ToDataContentAsync(CancellationToken cancellationToken = default)
Generated\Basic.CompilerLog.Util\Basic.CompilerLog.Util.Impl.BasicGeneratedFilesAnalyzerReference\JsonContext.DataContent.g.cs (22)
15private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.DataContent>? _DataContent; 21public global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.DataContent> DataContent 24get => _DataContent ??= (global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.DataContent>)Options.GetTypeInfo(typeof(global::Microsoft.Extensions.AI.DataContent)); 27private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.DataContent> Create_DataContent(global::System.Text.Json.JsonSerializerOptions options) 29if (!TryGetTypeInfoForRuntimeCustomConverter<global::Microsoft.Extensions.AI.DataContent>(options, out global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.DataContent> jsonTypeInfo)) 31var objectInfo = new global::System.Text.Json.Serialization.Metadata.JsonObjectInfoValues<global::Microsoft.Extensions.AI.DataContent> 37ConstructorAttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.DataContent).GetConstructor(InstanceMemberBindingFlags, binder: null, new[] {typeof(string), typeof(string)}, modifiers: null), 41jsonTypeInfo = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreateObjectInfo<global::Microsoft.Extensions.AI.DataContent>(options, objectInfo); 58DeclaringType = typeof(global::Microsoft.Extensions.AI.DataContent), 60Getter = static obj => ((global::Microsoft.Extensions.AI.DataContent)obj).Uri, 68AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.DataContent).GetProperty("Uri", InstanceMemberBindingFlags, null, typeof(string), global::System.Array.Empty<global::System.Type>(), null), 79DeclaringType = typeof(global::Microsoft.Extensions.AI.DataContent), 89AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.DataContent).GetProperty("MediaType", InstanceMemberBindingFlags, null, typeof(string), global::System.Array.Empty<global::System.Type>(), null), 100DeclaringType = typeof(global::Microsoft.Extensions.AI.DataContent), 102Getter = static obj => ((global::Microsoft.Extensions.AI.DataContent)obj).Name, 103Setter = static (obj, value) => ((global::Microsoft.Extensions.AI.DataContent)obj).Name = value!, 110AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.DataContent).GetProperty("Name", InstanceMemberBindingFlags, null, typeof(string), global::System.Array.Empty<global::System.Type>(), null), 120DeclaringType = typeof(global::Microsoft.Extensions.AI.DataContent), 130AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.DataContent).GetProperty("Data", InstanceMemberBindingFlags, null, typeof(global::System.ReadOnlyMemory<byte>), global::System.Array.Empty<global::System.Type>(), null), 140DeclaringType = typeof(global::Microsoft.Extensions.AI.DataContent),
Generated\Basic.CompilerLog.Util\Basic.CompilerLog.Util.Impl.BasicGeneratedFilesAnalyzerReference\JsonContext.GetJsonTypeInfo.g.cs (1)
152if (type == typeof(global::Microsoft.Extensions.AI.DataContent))
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 };
Realtime\InputAudioBufferAppendRealtimeClientMessage.cs (3)
17private DataContent _content; 24public InputAudioBufferAppendRealtimeClientMessage(DataContent audioContent) 36public DataContent Content
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 (149)
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 (10)
147Assert.IsType<DataContent>(result.Contents[1]); 148Assert.Equal("data:image/png;base64,aGVsbG8=", ((DataContent)result.Contents[1]).Uri); 153Assert.IsType<DataContent>(result.Contents[3]); 154Assert.Equal("data"u8.ToArray(), ((DataContent)result.Contents[3]).Data.ToArray()); 211Assert.IsType<DataContent>(result.Contents[1]); 212Assert.Equal("data:image/png;base64,aGVsbG8=", ((DataContent)result.Contents[1]).Uri); 217Assert.IsType<DataContent>(result.Contents[3]); 218Assert.Equal("data"u8.ToArray(), ((DataContent)result.Contents[3]).Data.ToArray()); 441var dataContent = Assert.IsType<DataContent>(result.Contents[1]);
Contents\CodeInterpreterToolCallContentTests.cs (1)
62Assert.IsType<DataContent>(c.Inputs[2]);
Contents\CodeInterpreterToolResultContentTests.cs (1)
63Assert.IsType<DataContent>(c.Outputs[2]);
Contents\DataContentTests.cs (55)
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"); 628DataContent content = new(testData, "image/png") { Name = "myimage.png" }; 657DataContent content = new(testData, "text/plain") { Name = $"testfile_{Guid.NewGuid()}.txt" }; 684await Assert.ThrowsAsync<ArgumentNullException>("path", async () => await DataContent.LoadFromAsync((string)null!)); 690await Assert.ThrowsAsync<ArgumentException>("path", async () => await DataContent.LoadFromAsync(string.Empty)); 696await Assert.ThrowsAsync<ArgumentNullException>("stream", async () => await DataContent.LoadFromAsync((Stream)null!)); 702DataContent content = new(new byte[] { 1 }, "application/octet-stream"); 720DataContent content = await DataContent.LoadFromAsync(filePath); 739DataContent content = new(testData, "text/css"); 780await DataContent.LoadFromAsync(tempPath, cancellationToken: cts.Token)); 796DataContent content = new(new byte[] { 1, 2, 3 }, "application/octet-stream"); 829await DataContent.LoadFromAsync(ms, cancellationToken: cts.Token)); 836DataContent content = new(testData, "application/json") 867DataContent content = new(testData, "application/json"); 904DataContent content = await DataContent.LoadFromAsync(tempPath); 925DataContent content = new(testData, "application/octet-stream"); 958DataContent content = new(newContent, "application/octet-stream"); 994var dataContent = Assert.IsType<DataContent>(result);
Contents\ImageGenerationToolResultContentTests.cs (5)
61Assert.IsType<DataContent>(c.Outputs[0]); 63Assert.IsType<DataContent>(c.Outputs[2]); 85Assert.IsType<DataContent>(deserializedSut.Outputs[0]); 86Assert.Equal("image/png", ((DataContent)deserializedSut.Outputs[0]).MediaType); 116Assert.IsType<DataContent>(imageResult.Outputs[0]);
Files\HostedFileClientExtensionsTests.cs (4)
19var content = new DataContent(data, "application/pdf") { Name = "doc.pdf" }; 49var content = new DataContent(new byte[] { 1 }, "text/plain"); 57await Assert.ThrowsAsync<ArgumentNullException>("content", () => client.UploadAsync((DataContent)null!)); 372var result = await client.DownloadAsDataContentAsync("file-dc");
Files\HostedFileDownloadStreamTests.cs (3)
28var content = await stream.ToDataContentAsync(); 39var content = await stream.ToDataContentAsync(); 49var content = await stream.ToDataContentAsync();
Generated\361d1da7f942c932\TestJsonSerializerContext.GetJsonTypeInfo.g.cs (1)
146if (type == typeof(global::Microsoft.Extensions.AI.DataContent))
Generated\Basic.CompilerLog.Util\Basic.CompilerLog.Util.Impl.BasicGeneratedFilesAnalyzerReference\TestJsonSerializerContext.DataContent.g.cs (22)
13private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.DataContent>? _DataContent; 19public global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.DataContent> DataContent 22get => _DataContent ??= (global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.DataContent>)Options.GetTypeInfo(typeof(global::Microsoft.Extensions.AI.DataContent)); 25private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.DataContent> Create_DataContent(global::System.Text.Json.JsonSerializerOptions options) 27if (!TryGetTypeInfoForRuntimeCustomConverter<global::Microsoft.Extensions.AI.DataContent>(options, out global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.DataContent> jsonTypeInfo)) 29var objectInfo = new global::System.Text.Json.Serialization.Metadata.JsonObjectInfoValues<global::Microsoft.Extensions.AI.DataContent> 35ConstructorAttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.DataContent).GetConstructor(InstanceMemberBindingFlags, binder: null, new[] {typeof(string), typeof(string)}, modifiers: null), 39jsonTypeInfo = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreateObjectInfo<global::Microsoft.Extensions.AI.DataContent>(options, objectInfo); 56DeclaringType = typeof(global::Microsoft.Extensions.AI.DataContent), 58Getter = static obj => ((global::Microsoft.Extensions.AI.DataContent)obj).Uri, 66AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.DataContent).GetProperty("Uri", InstanceMemberBindingFlags, null, typeof(string), global::System.Array.Empty<global::System.Type>(), null), 77DeclaringType = typeof(global::Microsoft.Extensions.AI.DataContent), 87AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.DataContent).GetProperty("MediaType", InstanceMemberBindingFlags, null, typeof(string), global::System.Array.Empty<global::System.Type>(), null), 98DeclaringType = typeof(global::Microsoft.Extensions.AI.DataContent), 100Getter = static obj => ((global::Microsoft.Extensions.AI.DataContent)obj).Name, 101Setter = static (obj, value) => ((global::Microsoft.Extensions.AI.DataContent)obj).Name = value!, 108AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.DataContent).GetProperty("Name", InstanceMemberBindingFlags, null, typeof(string), global::System.Array.Empty<global::System.Type>(), null), 118DeclaringType = typeof(global::Microsoft.Extensions.AI.DataContent), 128AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.DataContent).GetProperty("Data", InstanceMemberBindingFlags, null, typeof(global::System.ReadOnlyMemory<byte>), global::System.Array.Empty<global::System.Type>(), null), 138DeclaringType = typeof(global::Microsoft.Extensions.AI.DataContent),
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");
Realtime\RealtimeClientMessageTests.cs (4)
76var audioContent = new DataContent(new byte[] { 1, 2, 3 }, "audio/pcm"); 85var audioContent = new DataContent(new byte[] { 1, 2, 3 }, "audio/pcm"); 88var newContent = new DataContent(new byte[] { 4, 5, 6 }, "audio/wav"); 97var audioContent = new DataContent(new byte[] { 1, 2, 3 }, "audio/pcm");
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);
TextToSpeech\TextToSpeechClientTests.cs (5)
33Assert.IsType<DataContent>(response.Contents[0]); 34Assert.Equal("audio/mpeg", ((DataContent)response.Contents[0]).MediaType); 61Assert.IsType<DataContent>(updates[0].Contents[0]); 62Assert.IsType<DataContent>(updates[1].Contents[0]); 63Assert.IsType<DataContent>(updates[2].Contents[0]);
TextToSpeech\TextToSpeechResponseTests.cs (6)
56DataContent dc = Assert.IsType<DataContent>(response.Contents[i]); 163Assert.Equal("audio/mpeg", Assert.IsType<DataContent>(update.Contents[0]).MediaType); 164Assert.Equal("audio/wav", Assert.IsType<DataContent>(update.Contents[1]).MediaType); 208var dataContent = Assert.IsType<DataContent>(result.Contents[0]);
TextToSpeech\TextToSpeechResponseUpdateExtensionsTests.cs (2)
47Assert.All(response.Contents, c => Assert.IsType<DataContent>(c)); 72Assert.All(response.Contents, c => Assert.IsType<DataContent>(c));
TextToSpeech\TextToSpeechResponseUpdateTests.cs (2)
93var dataContent = Assert.IsType<DataContent>(result.Contents[0]);
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.Reporting (22)
Generated\Basic.CompilerLog.Util\Basic.CompilerLog.Util.Impl.BasicGeneratedFilesAnalyzerReference\JsonContext.DataContent.g.cs (21)
15private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.DataContent>? _DataContent; 21public global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.DataContent> DataContent 24get => _DataContent ??= (global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.DataContent>)Options.GetTypeInfo(typeof(global::Microsoft.Extensions.AI.DataContent)); 27private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.DataContent> Create_DataContent(global::System.Text.Json.JsonSerializerOptions options) 29if (!TryGetTypeInfoForRuntimeCustomConverter<global::Microsoft.Extensions.AI.DataContent>(options, out global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.DataContent> jsonTypeInfo)) 31var objectInfo = new global::System.Text.Json.Serialization.Metadata.JsonObjectInfoValues<global::Microsoft.Extensions.AI.DataContent> 37ConstructorAttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.DataContent).GetConstructor(InstanceMemberBindingFlags, binder: null, new[] {typeof(string), typeof(string)}, modifiers: null), 41jsonTypeInfo = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreateObjectInfo<global::Microsoft.Extensions.AI.DataContent>(options, objectInfo); 58DeclaringType = typeof(global::Microsoft.Extensions.AI.DataContent), 60Getter = static obj => ((global::Microsoft.Extensions.AI.DataContent)obj).Uri, 68AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.DataContent).GetProperty("Uri", InstanceMemberBindingFlags, null, typeof(string), global::System.Array.Empty<global::System.Type>(), null), 79DeclaringType = typeof(global::Microsoft.Extensions.AI.DataContent), 89AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.DataContent).GetProperty("MediaType", InstanceMemberBindingFlags, null, typeof(string), global::System.Array.Empty<global::System.Type>(), null), 100DeclaringType = typeof(global::Microsoft.Extensions.AI.DataContent), 102Getter = static obj => ((global::Microsoft.Extensions.AI.DataContent)obj).Name, 103Setter = static (obj, value) => ((global::Microsoft.Extensions.AI.DataContent)obj).Name = value!, 110AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.DataContent).GetProperty("Name", InstanceMemberBindingFlags, null, typeof(string), global::System.Array.Empty<global::System.Type>(), null), 120DeclaringType = typeof(global::Microsoft.Extensions.AI.DataContent), 140DeclaringType = typeof(global::Microsoft.Extensions.AI.DataContent),
Generated\Basic.CompilerLog.Util\Basic.CompilerLog.Util.Impl.BasicGeneratedFilesAnalyzerReference\JsonContext.GetJsonTypeInfo.g.cs (1)
92if (type == typeof(global::Microsoft.Extensions.AI.DataContent))
Microsoft.Extensions.AI.Evaluation.Reporting.Azure (22)
Generated\Basic.CompilerLog.Util\Basic.CompilerLog.Util.Impl.BasicGeneratedFilesAnalyzerReference\JsonContext.DataContent.g.cs (21)
15private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.DataContent>? _DataContent; 21public global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.DataContent> DataContent 24get => _DataContent ??= (global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.DataContent>)Options.GetTypeInfo(typeof(global::Microsoft.Extensions.AI.DataContent)); 27private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.DataContent> Create_DataContent(global::System.Text.Json.JsonSerializerOptions options) 29if (!TryGetTypeInfoForRuntimeCustomConverter<global::Microsoft.Extensions.AI.DataContent>(options, out global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.DataContent> jsonTypeInfo)) 31var objectInfo = new global::System.Text.Json.Serialization.Metadata.JsonObjectInfoValues<global::Microsoft.Extensions.AI.DataContent> 37ConstructorAttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.DataContent).GetConstructor(InstanceMemberBindingFlags, binder: null, new[] {typeof(string), typeof(string)}, modifiers: null), 41jsonTypeInfo = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreateObjectInfo<global::Microsoft.Extensions.AI.DataContent>(options, objectInfo); 58DeclaringType = typeof(global::Microsoft.Extensions.AI.DataContent), 60Getter = static obj => ((global::Microsoft.Extensions.AI.DataContent)obj).Uri, 68AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.DataContent).GetProperty("Uri", InstanceMemberBindingFlags, null, typeof(string), global::System.Array.Empty<global::System.Type>(), null), 79DeclaringType = typeof(global::Microsoft.Extensions.AI.DataContent), 89AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.DataContent).GetProperty("MediaType", InstanceMemberBindingFlags, null, typeof(string), global::System.Array.Empty<global::System.Type>(), null), 100DeclaringType = typeof(global::Microsoft.Extensions.AI.DataContent), 102Getter = static obj => ((global::Microsoft.Extensions.AI.DataContent)obj).Name, 103Setter = static (obj, value) => ((global::Microsoft.Extensions.AI.DataContent)obj).Name = value!, 110AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.DataContent).GetProperty("Name", InstanceMemberBindingFlags, null, typeof(string), global::System.Array.Empty<global::System.Type>(), null), 120DeclaringType = typeof(global::Microsoft.Extensions.AI.DataContent), 140DeclaringType = typeof(global::Microsoft.Extensions.AI.DataContent),
Generated\Basic.CompilerLog.Util\Basic.CompilerLog.Util.Impl.BasicGeneratedFilesAnalyzerReference\JsonContext.GetJsonTypeInfo.g.cs (1)
92if (type == typeof(global::Microsoft.Extensions.AI.DataContent))
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 (39)
ImageGeneratingChatClientIntegrationTests.cs (22)
91foreach (var dataContent in toolResult.Outputs.OfType<DataContent>()) 144var imageContent = Assert.Single(imageResult.Outputs.OfType<DataContent>()); 158var originalImageData = new DataContent(testImageData, "image/png") { Name = "original.png" }; 174var originalImageContent = Assert.IsType<DataContent>(originalImage); 216var firstContent = Assert.Single(firstToolResultContent.Outputs.OfType<DataContent>()); 220Assert.Single(secondResponse.Messages.SelectMany(m => m.Contents).OfType<ImageGenerationToolResultContent>().SelectMany(t => t.Outputs!.OfType<DataContent>())); 225var editedImage = Assert.IsType<DataContent>(secondRequest.OriginalImages.First()); 270var secondImage = Assert.Single(secondToolResultContent.Outputs!.OfType<DataContent>()); 271var lastImageToEdit = Assert.Single(thirdRequest.OriginalImages.OfType<DataContent>()); 315var firstGeneratedImage = Assert.Single(firstToolResultContent.Outputs!.OfType<DataContent>()); 316var lastImageToEdit = Assert.IsType<DataContent>(thirdRequest.OriginalImages.First()); 374var originalImage = new DataContent(testImageData, "image/png") { Name = "test.png" }; 421var imageContent = new DataContent(imageData, TestImageMediaType)
ImageGeneratorIntegrationTests.cs (7)
53case DataContent dc: 82Assert.IsType<DataContent>(content); 83var dataContent = (DataContent)content; 109Assert.IsType<DataContent>(content); 110var dataContent = (DataContent)content;
TextToSpeechClientIntegrationTests.cs (10)
42var dataContent = Assert.IsType<DataContent>(content); 61var dataContent = Assert.IsType<DataContent>(content); 80var dataContent = Assert.IsType<DataContent>(content); 99var dataContent = Assert.IsType<DataContent>(content); 114var dataContents = update.Contents.OfType<DataContent>().ToList(); 117foreach (var dataContent in dataContents)
Microsoft.Extensions.AI.OpenAI (12)
MicrosoftExtensionsAIChatExtensions.cs (1)
86outputAudio: lastMessage?.Contents.OfType<DataContent>().Where(dc => dc.HasTopLevelMediaType("audio")).Select(a => OpenAIChatModelFactory.ChatOutputAudio(new(a.Data))).FirstOrDefault(),
OpenAIChatClient.cs (3)
301case DataContent dataContent when dataContent.HasTopLevelMediaType("image"): 305case DataContent dataContent when dataContent.HasTopLevelMediaType("audio"): 318case DataContent dataContent when dataContent.MediaType.StartsWith("application/pdf", StringComparison.OrdinalIgnoreCase):
OpenAIFileDownloadStream.cs (1)
45public override Task<DataContent> ToDataContentAsync(CancellationToken cancellationToken = default)
OpenAIImageGenerator.cs (1)
59if (originalImage is DataContent dataContent)
OpenAIRealtimeClientSession.cs (2)
672else if (content is DataContent dataContent) 732private static BinaryData ExtractAudioBinaryData(DataContent content)
OpenAIResponsesChatClient.cs (4)
1359case DataContent dataContent when dataContent.HasTopLevelMediaType("image"): 1363case DataContent dataContent when dataContent.MediaType.StartsWith("application/pdf", StringComparison.OrdinalIgnoreCase): 1431case DataContent dc when dc.HasTopLevelMediaType("image"): 1439case DataContent dc:
Microsoft.Extensions.AI.OpenAI.Tests (36)
OpenAIAssistantChatClientIntegrationTests.cs (1)
76if (toolCallContent.Inputs.OfType<DataContent>().FirstOrDefault() is { } codeInput)
OpenAIHostedFileClientIntegrationTests.cs (2)
178var dataContent = new DataContent(contentBytes, "text/plain") { Name = fileName }; 211var dataContent = await RetryAsync(() => _client.DownloadAsDataContentAsync(uploadedFileId));
OpenAIResponseClientIntegrationTests.cs (4)
56var codeInput = toolCallContent.Inputs.OfType<DataContent>().FirstOrDefault(); 176var imageContent = Assert.Single(igResult.Outputs.OfType<DataContent>());
OpenAIResponseClientTests.cs (13)
3398var codeInput = Assert.IsType<DataContent>(Assert.Single(codeCall.Inputs)); 3618var codeInput = Assert.IsType<DataContent>(Assert.Single(codeCall.Inputs)); 3717var dataContent = content.Inputs.OfType<DataContent>().FirstOrDefault(); 3744var codeInput = Assert.IsType<DataContent>(Assert.Single(codeCall.Inputs)); 6294var imageContent = userMessage.Contents.OfType<DataContent>().FirstOrDefault(); 6391var imageData = toolResult.Outputs![0] as DataContent; 6640return o is DataContent dataContent && dataContent.MediaType == "image/webp";
OpenAITextToSpeechClientIntegrationTests.cs (2)
41var dataContent = update.Contents.OfType<DataContent>().Single();
OpenAITextToSpeechClientTests.cs (14)
87var content = Assert.IsType<DataContent>(response.Contents[0]); 116var content = Assert.IsType<DataContent>(response.Contents[0]); 178var content = Assert.IsType<DataContent>(response.Contents[0]); 214var content = Assert.IsType<DataContent>(response.Contents[0]); 272var content = update.Contents.OfType<DataContent>().Single(); 322var data0 = updates[0].Contents.OfType<DataContent>().Single(); 329var data1 = updates[1].Contents.OfType<DataContent>().Single();
Microsoft.Extensions.AI.Stabilization.Tests (30)
Generated\361d1da7f942c932\AIContentSerializationRegressionContext.DataContent.g.cs (21)
13private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.DataContent>? _DataContent; 19public global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.DataContent> DataContent 22get => _DataContent ??= (global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.DataContent>)Options.GetTypeInfo(typeof(global::Microsoft.Extensions.AI.DataContent)); 25private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.DataContent> Create_DataContent(global::System.Text.Json.JsonSerializerOptions options) 27if (!TryGetTypeInfoForRuntimeCustomConverter<global::Microsoft.Extensions.AI.DataContent>(options, out global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.DataContent> jsonTypeInfo)) 29var objectInfo = new global::System.Text.Json.Serialization.Metadata.JsonObjectInfoValues<global::Microsoft.Extensions.AI.DataContent> 35ConstructorAttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.DataContent).GetConstructor(InstanceMemberBindingFlags, binder: null, new[] {typeof(string), typeof(string)}, modifiers: null), 39jsonTypeInfo = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreateObjectInfo<global::Microsoft.Extensions.AI.DataContent>(options, objectInfo); 56DeclaringType = typeof(global::Microsoft.Extensions.AI.DataContent), 58Getter = static obj => ((global::Microsoft.Extensions.AI.DataContent)obj).Uri, 66AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.DataContent).GetProperty("Uri", InstanceMemberBindingFlags, null, typeof(string), global::System.Array.Empty<global::System.Type>(), null), 77DeclaringType = typeof(global::Microsoft.Extensions.AI.DataContent), 87AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.DataContent).GetProperty("MediaType", InstanceMemberBindingFlags, null, typeof(string), global::System.Array.Empty<global::System.Type>(), null), 98DeclaringType = typeof(global::Microsoft.Extensions.AI.DataContent), 100Getter = static obj => ((global::Microsoft.Extensions.AI.DataContent)obj).Name, 101Setter = static (obj, value) => ((global::Microsoft.Extensions.AI.DataContent)obj).Name = value!, 108AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.DataContent).GetProperty("Name", InstanceMemberBindingFlags, null, typeof(string), global::System.Array.Empty<global::System.Type>(), null), 118DeclaringType = typeof(global::Microsoft.Extensions.AI.DataContent), 138DeclaringType = typeof(global::Microsoft.Extensions.AI.DataContent),
Generated\361d1da7f942c932\AIContentSerializationRegressionContext.GetJsonTypeInfo.g.cs (1)
58if (type == typeof(global::Microsoft.Extensions.AI.DataContent))
parent\Microsoft.Extensions.AI.Abstractions.Tests\Contents\CodeInterpreterToolCallContentTests.cs (1)
62Assert.IsType<DataContent>(c.Inputs[2]);
parent\Microsoft.Extensions.AI.Abstractions.Tests\Contents\CodeInterpreterToolResultContentTests.cs (1)
63Assert.IsType<DataContent>(c.Outputs[2]);
parent\Microsoft.Extensions.AI.Abstractions.Tests\Contents\ImageGenerationToolResultContentTests.cs (5)
61Assert.IsType<DataContent>(c.Outputs[0]); 63Assert.IsType<DataContent>(c.Outputs[2]); 85Assert.IsType<DataContent>(deserializedSut.Outputs[0]); 86Assert.Equal("image/png", ((DataContent)deserializedSut.Outputs[0]).MediaType); 116Assert.IsType<DataContent>(imageResult.Outputs[0]);
parent\Microsoft.Extensions.AI.Abstractions.Tests\Tools\HostedCodeInterpreterToolTests.cs (1)
55Assert.IsType<DataContent>(tool.Inputs[1]);
Microsoft.Extensions.AI.Tests (25)
Functions\AIFunctionFactoryTest.cs (2)
1170await ValidateAsync<DataContent>( 1174AIFunctionFactory.Create(async ValueTask<DataContent> () => new DataContent(new byte[] { 1, 2, 3 }, "application/octet-stream")),
Generated\361d1da7f942c932\TestJsonSerializerContext.GetJsonTypeInfo.g.cs (1)
126if (type == typeof(global::Microsoft.Extensions.AI.DataContent))
Generated\Basic.CompilerLog.Util\Basic.CompilerLog.Util.Impl.BasicGeneratedFilesAnalyzerReference\TestJsonSerializerContext.DataContent.g.cs (21)
13private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.DataContent>? _DataContent; 19public global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.DataContent> DataContent 22get => _DataContent ??= (global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.DataContent>)Options.GetTypeInfo(typeof(global::Microsoft.Extensions.AI.DataContent)); 25private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.DataContent> Create_DataContent(global::System.Text.Json.JsonSerializerOptions options) 27if (!TryGetTypeInfoForRuntimeCustomConverter<global::Microsoft.Extensions.AI.DataContent>(options, out global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.DataContent> jsonTypeInfo)) 29var objectInfo = new global::System.Text.Json.Serialization.Metadata.JsonObjectInfoValues<global::Microsoft.Extensions.AI.DataContent> 35ConstructorAttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.DataContent).GetConstructor(InstanceMemberBindingFlags, binder: null, new[] {typeof(string), typeof(string)}, modifiers: null), 39jsonTypeInfo = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreateObjectInfo<global::Microsoft.Extensions.AI.DataContent>(options, objectInfo); 56DeclaringType = typeof(global::Microsoft.Extensions.AI.DataContent), 58Getter = static obj => ((global::Microsoft.Extensions.AI.DataContent)obj).Uri, 66AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.DataContent).GetProperty("Uri", InstanceMemberBindingFlags, null, typeof(string), global::System.Array.Empty<global::System.Type>(), null), 77DeclaringType = typeof(global::Microsoft.Extensions.AI.DataContent), 87AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.DataContent).GetProperty("MediaType", InstanceMemberBindingFlags, null, typeof(string), global::System.Array.Empty<global::System.Type>(), null), 98DeclaringType = typeof(global::Microsoft.Extensions.AI.DataContent), 100Getter = static obj => ((global::Microsoft.Extensions.AI.DataContent)obj).Name, 101Setter = static (obj, value) => ((global::Microsoft.Extensions.AI.DataContent)obj).Name = value!, 108AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.DataContent).GetProperty("Name", InstanceMemberBindingFlags, null, typeof(string), global::System.Array.Empty<global::System.Type>(), null), 118DeclaringType = typeof(global::Microsoft.Extensions.AI.DataContent), 138DeclaringType = typeof(global::Microsoft.Extensions.AI.DataContent),
Realtime\OpenTelemetryRealtimeClientTests.cs (1)
1020var imageData = new DataContent(new byte[] { 0x89, 0x50, 0x4E, 0x47 }, "image/png");
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);
Microsoft.Extensions.VectorData.Abstractions (18)
IKeywordHybridSearchable.cs (3)
34/// A <see cref="string"/> or <see cref="DataContent"/> (for images, sound...) if an appropriate <see cref="IEmbeddingGenerator"/> has been configured that accepts that type as input. 37/// Some databases support generating embeddings at the database side. In this case, you can pass in a <see cref="string"/> or <see cref="DataContent"/> without configuring an 43/// <see cref="DataContent"/>, you must use the generic <see cref="VectorStoreVectorProperty{TInput}"/> in your record definition.
IVectorSearchable.cs (3)
33/// A <see cref="string"/> or <see cref="DataContent"/> (for images, sound...) if an appropriate <see cref="IEmbeddingGenerator"/> has been configured that accepts that type as input. 36/// Some databases support generating embeddings at the database side. In this case, you can pass in a <see cref="string"/> or <see cref="DataContent"/> without configuring an 42/// <see cref="DataContent"/>, you must use the generic <see cref="VectorStoreVectorProperty{TInput}"/> in your record definition.
ProviderServices\VectorPropertyModel.cs (11)
93/// for any input type known to this property model. The base implementation checks for <see cref="string"/> and <see cref="DataContent"/>; 102|| embeddingGenerator is IEmbeddingGenerator<DataContent, TEmbedding>; 107/// and <see cref="DataContent"/> as input types for <see cref="EmbeddingGenerator"/>. 122IEmbeddingGenerator<DataContent, TEmbedding> when Type == typeof(DataContent) && (userRequestedEmbeddingType is null || userRequestedEmbeddingType == typeof(TEmbedding)) 163IEmbeddingGenerator<DataContent, TEmbedding> generator when EmbeddingType == typeof(TEmbedding) 165values.Select(v => v is DataContent c 167: throw new InvalidOperationException($"Property '{ModelName}' was configured with an embedding generator accepting a {nameof(DataContent)}, but {v?.GetType().Name ?? "null"} was provided.")), 186IEmbeddingGenerator<DataContent, TEmbedding> generator when value is DataContent c 199public virtual Type[] GetSupportedInputTypes() => [typeof(string), typeof(DataContent)];
RecordDefinition\VectorStoreVectorProperty{TInput}.cs (1)
21/// configured on the property, and a custom .NET type is used as input (any type other than <see cref="string"/> or <see cref="DataContent"/>).