Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion api/OpenAI.net8.0.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5066,8 +5066,9 @@ public class CustomMcpToolCallApprovalPolicy : IJsonModel<CustomMcpToolCallAppro
}
[Experimental("OPENAI001")]
public class FileCitationMessageAnnotation : ResponseMessageAnnotation, IJsonModel<FileCitationMessageAnnotation>, IPersistableModel<FileCitationMessageAnnotation> {
public FileCitationMessageAnnotation(string fileId, int index);
public FileCitationMessageAnnotation(string fileId, int index, string filename);
public string FileId { get; set; }
public string Filename { get; set; }
public int Index { get; set; }
protected override ResponseMessageAnnotation JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options);
protected override void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options);
Expand Down
3 changes: 2 additions & 1 deletion api/OpenAI.netstandard2.0.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4425,8 +4425,9 @@ public class CustomMcpToolCallApprovalPolicy : IJsonModel<CustomMcpToolCallAppro
protected virtual BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options);
}
public class FileCitationMessageAnnotation : ResponseMessageAnnotation, IJsonModel<FileCitationMessageAnnotation>, IPersistableModel<FileCitationMessageAnnotation> {
public FileCitationMessageAnnotation(string fileId, int index);
public FileCitationMessageAnnotation(string fileId, int index, string filename);
public string FileId { get; set; }
public string Filename { get; set; }
public int Index { get; set; }
protected override ResponseMessageAnnotation JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options);
protected override void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options);
Expand Down
3 changes: 3 additions & 0 deletions specification/base/typespec/responses/models.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -1064,6 +1064,9 @@ model AnnotationFileCitation extends Annotation {

/** The index of the file in the list of files. */
index: int32;

/** The filename of the file cited. */
filename: string;
}

// Tool customization (apply_discriminator): Apply discriminated base type, rename for consistency and clarity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace OpenAI.Responses
{
public partial class FileCitationMessageAnnotation : ResponseMessageAnnotation, IJsonModel<FileCitationMessageAnnotation>
{
internal FileCitationMessageAnnotation() : this(ResponseMessageAnnotationKind.FileCitation, default, null, default)
internal FileCitationMessageAnnotation() : this(ResponseMessageAnnotationKind.FileCitation, default, null, default, null)
{
}

Expand Down Expand Up @@ -50,6 +50,11 @@ protected override void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWri
writer.WritePropertyName("index"u8);
writer.WriteNumberValue(Index);
}
if (!Patch.Contains("$.filename"u8))
{
writer.WritePropertyName("filename"u8);
writer.WriteStringValue(Filename);
}

Patch.WriteTo(writer);
#pragma warning restore SCME0001 // Type is for evaluation purposes only and is subject to change or removal in future updates.
Expand Down Expand Up @@ -80,6 +85,7 @@ internal static FileCitationMessageAnnotation DeserializeFileCitationMessageAnno
#pragma warning restore SCME0001 // Type is for evaluation purposes only and is subject to change or removal in future updates.
string fileId = default;
int index = default;
string filename = default;
foreach (var prop in element.EnumerateObject())
{
if (prop.NameEquals("type"u8))
Expand All @@ -97,9 +103,14 @@ internal static FileCitationMessageAnnotation DeserializeFileCitationMessageAnno
index = prop.Value.GetInt32();
continue;
}
if (prop.NameEquals("filename"u8))
{
filename = prop.Value.GetString();
continue;
}
patch.Set([.. "$."u8, .. Encoding.UTF8.GetBytes(prop.Name)], prop.Value.GetUtf8Bytes());
}
return new FileCitationMessageAnnotation(kind, patch, fileId, index);
return new FileCitationMessageAnnotation(kind, patch, fileId, index, filename);
}

BinaryData IPersistableModel<FileCitationMessageAnnotation>.Write(ModelReaderWriterOptions options) => PersistableModelWriteCore(options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,29 @@ namespace OpenAI.Responses
[Experimental("OPENAI001")]
public partial class FileCitationMessageAnnotation : ResponseMessageAnnotation
{
public FileCitationMessageAnnotation(string fileId, int index) : base(ResponseMessageAnnotationKind.FileCitation)
public FileCitationMessageAnnotation(string fileId, int index, string filename) : base(ResponseMessageAnnotationKind.FileCitation)
{
Argument.AssertNotNull(fileId, nameof(fileId));
Argument.AssertNotNull(filename, nameof(filename));

FileId = fileId;
Index = index;
Filename = filename;
}

#pragma warning disable SCME0001 // Type is for evaluation purposes only and is subject to change or removal in future updates.
internal FileCitationMessageAnnotation(ResponseMessageAnnotationKind kind, in JsonPatch patch, string fileId, int index) : base(kind, patch)
internal FileCitationMessageAnnotation(ResponseMessageAnnotationKind kind, in JsonPatch patch, string fileId, int index, string filename) : base(kind, patch)
{
FileId = fileId;
Index = index;
Filename = filename;
}
#pragma warning restore SCME0001 // Type is for evaluation purposes only and is subject to change or removal in future updates.

public string FileId { get; set; }

public int Index { get; set; }

public string Filename { get; set; }
}
}
4 changes: 2 additions & 2 deletions src/Generated/OpenAIModelFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -584,9 +584,9 @@ public static ResponseMessageAnnotation ResponseMessageAnnotation(string kind =
return new InternalUnknownAnnotation(kind.ToResponseMessageAnnotationKind(), default);
}

public static FileCitationMessageAnnotation FileCitationMessageAnnotation(string fileId = default, int index = default)
public static FileCitationMessageAnnotation FileCitationMessageAnnotation(string fileId = default, int index = default, string filename = default)
{
return new FileCitationMessageAnnotation(ResponseMessageAnnotationKind.FileCitation, default, fileId, index);
return new FileCitationMessageAnnotation(ResponseMessageAnnotationKind.FileCitation, default, fileId, index, filename);
}

public static UriCitationMessageAnnotation UriCitationMessageAnnotation(Uri uri = default, int startIndex = default, int endIndex = default, string title = default)
Expand Down
1 change: 1 addition & 0 deletions tests/Responses/ResponsesToolTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ public async Task FileSearch()
Assert.That(messageContentPart.OutputTextAnnotations, Is.Not.Null.And.Not.Empty);
FileCitationMessageAnnotation annotation = messageContentPart.OutputTextAnnotations[0] as FileCitationMessageAnnotation;
Assert.That(annotation.FileId, Is.EqualTo(testFile.Id));
Assert.That(annotation.Filename, Is.EqualTo(testFile.Filename));
Assert.That(annotation.Index, Is.GreaterThan(0));

await foreach (ResponseItem inputItem in client.GetResponseInputItemsAsync(response.Id))
Expand Down
Loading
Loading