Skip to content

Commit 59b0725

Browse files
authored
Add DataContent.Name property (#6616)
* Add DataContent.Name property Enables a name (e.g. file name) to optionally be associated with a DataContent. DataContent is often used to represent named entities, such as when uploading files.
1 parent e717e4a commit 59b0725

File tree

13 files changed

+34
-7
lines changed

13 files changed

+34
-7
lines changed

src/Libraries/Microsoft.Extensions.AI.Abstractions/Contents/AIAnnotation.cs

Whitespace-only changes.

src/Libraries/Microsoft.Extensions.AI.Abstractions/Contents/AIAnnotationExtensions.cs

Whitespace-only changes.

src/Libraries/Microsoft.Extensions.AI.Abstractions/Contents/AIAnnotationKind.cs

Whitespace-only changes.

src/Libraries/Microsoft.Extensions.AI.Abstractions/Contents/AIAnnotationReference.cs

Whitespace-only changes.

src/Libraries/Microsoft.Extensions.AI.Abstractions/Contents/DataContent.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,13 @@ public string Uri
183183
[JsonIgnore]
184184
public string MediaType { get; }
185185

186+
/// <summary>Gets or sets an optional name associated with the data.</summary>
187+
/// <remarks>
188+
/// A service might use this name as part of citations or to help infer the type of data
189+
/// being represented based on a file extension.
190+
/// </remarks>
191+
public string? Name { get; set; }
192+
186193
/// <summary>Gets the data represented by this instance.</summary>
187194
/// <remarks>
188195
/// If the instance was constructed from a <see cref="ReadOnlyMemory{Byte}"/>, this property returns that data.

src/Libraries/Microsoft.Extensions.AI.Abstractions/Microsoft.Extensions.AI.Abstractions.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,6 +1349,10 @@
13491349
"Member": "System.ReadOnlyMemory<byte> Microsoft.Extensions.AI.DataContent.Data { get; }",
13501350
"Stage": "Stable"
13511351
},
1352+
{
1353+
"Member": "string? Microsoft.Extensions.AI.DataContent.Name { get; set; }",
1354+
"Stage": "Stable"
1355+
},
13521356
{
13531357
"Member": "string Microsoft.Extensions.AI.DataContent.MediaType { get; }",
13541358
"Stage": "Stable"

src/Libraries/Microsoft.Extensions.AI.OpenAI/OpenAIChatClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ private static List<ChatMessageContentPart> ToOpenAIChatContent(IList<AIContent>
264264
break;
265265

266266
case DataContent dataContent when dataContent.MediaType.StartsWith("application/pdf", StringComparison.OrdinalIgnoreCase):
267-
return ChatMessageContentPart.CreateFilePart(BinaryData.FromBytes(dataContent.Data), dataContent.MediaType, $"{Guid.NewGuid():N}.pdf");
267+
return ChatMessageContentPart.CreateFilePart(BinaryData.FromBytes(dataContent.Data), dataContent.MediaType, dataContent.Name ?? $"{Guid.NewGuid():N}.pdf");
268268

269269
case AIContent when content.RawRepresentation is ChatMessageContentPart rawContentPart:
270270
return rawContentPart;

src/Libraries/Microsoft.Extensions.AI.OpenAI/OpenAIResponseChatClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ private static List<ResponseContentPart> ToOpenAIResponsesContent(IList<AIConten
639639
break;
640640

641641
case DataContent dataContent when dataContent.MediaType.StartsWith("application/pdf", StringComparison.OrdinalIgnoreCase):
642-
parts.Add(ResponseContentPart.CreateInputFilePart(BinaryData.FromBytes(dataContent.Data), dataContent.MediaType, $"{Guid.NewGuid():N}.pdf"));
642+
parts.Add(ResponseContentPart.CreateInputFilePart(BinaryData.FromBytes(dataContent.Data), dataContent.MediaType, dataContent.Name ?? $"{Guid.NewGuid():N}.pdf"));
643643
break;
644644

645645
case ErrorContent errorContent when errorContent.ErrorCode == nameof(ResponseContentPartKind.Refusal):

test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/Contents/AIAnnotationReferenceTests.cs

Whitespace-only changes.

test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/Contents/AIAnnotationTests.cs

Whitespace-only changes.

0 commit comments

Comments
 (0)