openai/openai-dotnet
Publicmirrored from https://github.com/openai/openai-dotnetAvailable
src/Custom/Files/OpenAIFileCollection.cs
69lines · modecode
| 1 | using System; |
| 2 | using System.ClientModel; |
| 3 | using System.ClientModel.Primitives; |
| 4 | using System.Collections.Generic; |
| 5 | using System.Collections.ObjectModel; |
| 6 | using System.Text.Json; |
| 7 | |
| 8 | namespace OpenAI.Files; |
| 9 | |
| 10 | [CodeGenType("ListFilesResponse")] |
| 11 | [CodeGenSuppress("Data")] |
| 12 | [CodeGenSuppress(nameof(OpenAIFileCollection))] |
| 13 | [CodeGenSuppress(nameof(OpenAIFileCollection), typeof(string), typeof(string), typeof(bool))] |
| 14 | [CodeGenSuppress(nameof(OpenAIFileCollection), typeof(string), typeof(string), typeof(string), typeof(bool), typeof(IDictionary<string, BinaryData>))] |
| 15 | public partial class OpenAIFileCollection : ReadOnlyCollection<OpenAIFile> |
| 16 | { |
| 17 | // CUSTOM: Made private. This property does not add value in the context of a strongly-typed class. |
| 18 | [CodeGenMember("Object")] |
| 19 | private string Object { get; } = "list"; |
| 20 | |
| 21 | // CUSTOM: Internalizing pending stanardized pagination representation for the list operation. |
| 22 | [CodeGenMember("FirstId")] |
| 23 | internal string FirstId { get; } |
| 24 | |
| 25 | [CodeGenMember("LastId")] |
| 26 | internal string LastId { get; } |
| 27 | |
| 28 | [CodeGenMember("HasMore")] |
| 29 | internal bool HasMore { get; } |
| 30 | |
| 31 | /// <summary> Initializes a new instance of <see cref="OpenAIFileCollection"/>. </summary> |
| 32 | /// <param name="data"></param> |
| 33 | /// <exception cref="ArgumentNullException"> <paramref name="data"/> is null. </exception> |
| 34 | internal OpenAIFileCollection(IEnumerable<OpenAIFile> data, string firstId, string lastId, bool hasMore) |
| 35 | : base([.. data]) |
| 36 | { |
| 37 | Argument.AssertNotNull(data, nameof(data)); |
| 38 | FirstId = firstId; |
| 39 | LastId = lastId; |
| 40 | HasMore = hasMore; |
| 41 | } |
| 42 | |
| 43 | /// <summary> Initializes a new instance of <see cref="OpenAIFileCollection"/>. </summary> |
| 44 | /// <param name="data"></param> |
| 45 | /// <param name="object"></param> |
| 46 | /// <param name="serializedAdditionalRawData"> Keeps track of any properties unknown to the library. </param> |
| 47 | internal OpenAIFileCollection(IReadOnlyList<OpenAIFile> data, string @object, string firstId, string lastId, bool hasMore, IDictionary<string, BinaryData> serializedAdditionalRawData) |
| 48 | : base([.. data]) |
| 49 | { |
| 50 | Object = @object; |
| 51 | SerializedAdditionalRawData = serializedAdditionalRawData; |
| 52 | FirstId = firstId; |
| 53 | LastId = lastId; |
| 54 | HasMore = hasMore; |
| 55 | } |
| 56 | |
| 57 | /// <summary> Initializes a new instance of <see cref="OpenAIFileCollection"/> for deserialization. </summary> |
| 58 | internal OpenAIFileCollection() |
| 59 | : base([]) |
| 60 | { |
| 61 | } |
| 62 | |
| 63 | internal static OpenAIFileCollection FromClientResult(ClientResult result) |
| 64 | { |
| 65 | using PipelineResponse response = result.GetRawResponse(); |
| 66 | using JsonDocument document = JsonDocument.Parse(response.Content); |
| 67 | return DeserializeOpenAIFileCollection(document.RootElement, ModelSerializationExtensions.WireOptions); |
| 68 | } |
| 69 | } |