openai/openai-dotnet
Publicmirrored from https://github.com/openai/openai-dotnetAvailable
src/Custom/Embeddings/EmbeddingCollection.cs
90lines · modecode
| 1 | using System; |
| 2 | using System.Collections.Generic; |
| 3 | using System.Collections.ObjectModel; |
| 4 | |
| 5 | namespace OpenAI.Embeddings; |
| 6 | |
| 7 | [CodeGenModel("CreateEmbeddingResponse")] |
| 8 | [CodeGenSuppress("Data")] |
| 9 | [CodeGenSuppress(nameof(EmbeddingCollection))] |
| 10 | [CodeGenSuppress(nameof(EmbeddingCollection), typeof(IReadOnlyList<Embedding>), typeof(string), typeof(InternalCreateEmbeddingResponseObject), typeof(EmbeddingTokenUsage))] |
| 11 | public partial class EmbeddingCollection : ReadOnlyCollection<Embedding> |
| 12 | { |
| 13 | // CUSTOM: Made private. This property does not add value in the context of a strongly-typed class. |
| 14 | /// <summary> The object type, which is always "list". </summary> |
| 15 | [CodeGenMember("Object")] |
| 16 | private InternalCreateEmbeddingResponseObject Object { get; } = InternalCreateEmbeddingResponseObject.List; |
| 17 | |
| 18 | // CUSTOM: Recovered this field. See https://github.com/Azure/autorest.csharp/issues/4636. |
| 19 | /// <summary> |
| 20 | /// Keeps track of any properties unknown to the library. |
| 21 | /// <para> |
| 22 | /// To assign an object to the value of this property use <see cref="BinaryData.FromObjectAsJson{T}(T, System.Text.Json.JsonSerializerOptions?)"/>. |
| 23 | /// </para> |
| 24 | /// <para> |
| 25 | /// To assign an already formatted json string to this property use <see cref="BinaryData.FromString(string)"/>. |
| 26 | /// </para> |
| 27 | /// <para> |
| 28 | /// Examples: |
| 29 | /// <list type="bullet"> |
| 30 | /// <item> |
| 31 | /// <term>BinaryData.FromObjectAsJson("foo")</term> |
| 32 | /// <description>Creates a payload of "foo".</description> |
| 33 | /// </item> |
| 34 | /// <item> |
| 35 | /// <term>BinaryData.FromString("\"foo\"")</term> |
| 36 | /// <description>Creates a payload of "foo".</description> |
| 37 | /// </item> |
| 38 | /// <item> |
| 39 | /// <term>BinaryData.FromObjectAsJson(new { key = "value" })</term> |
| 40 | /// <description>Creates a payload of { "key": "value" }.</description> |
| 41 | /// </item> |
| 42 | /// <item> |
| 43 | /// <term>BinaryData.FromString("{\"key\": \"value\"}")</term> |
| 44 | /// <description>Creates a payload of { "key": "value" }.</description> |
| 45 | /// </item> |
| 46 | /// </list> |
| 47 | /// </para> |
| 48 | /// </summary> |
| 49 | private IDictionary<string, BinaryData> SerializedAdditionalRawData; |
| 50 | |
| 51 | // CUSTOM: Set the inherited Items property via the base constructor in favor of the suppressed Data property. |
| 52 | /// <summary> Initializes a new instance of <see cref="EmbeddingCollection"/>. </summary> |
| 53 | /// <param name="data"> The list of embeddings generated by the model. </param> |
| 54 | /// <param name="model"> The name of the model used to generate the embedding. </param> |
| 55 | /// <param name="usage"> The usage information for the request. </param> |
| 56 | /// <exception cref="ArgumentNullException"> <paramref name="data"/>, <paramref name="model"/> or <paramref name="usage"/> is null. </exception> |
| 57 | internal EmbeddingCollection(IEnumerable<Embedding> data, string model, EmbeddingTokenUsage usage) |
| 58 | : base([.. data]) |
| 59 | { |
| 60 | Argument.AssertNotNull(data, nameof(data)); |
| 61 | Argument.AssertNotNull(model, nameof(model)); |
| 62 | Argument.AssertNotNull(usage, nameof(usage)); |
| 63 | |
| 64 | Model = model; |
| 65 | Usage = usage; |
| 66 | } |
| 67 | |
| 68 | // CUSTOM: Set the inherited Items property via the base constructor in favor of the suppressed Data property. |
| 69 | /// <summary> Initializes a new instance of <see cref="EmbeddingCollection"/>. </summary> |
| 70 | /// <param name="data"> The list of embeddings generated by the model. </param> |
| 71 | /// <param name="model"> The name of the model used to generate the embedding. </param> |
| 72 | /// <param name="object"> The object type, which is always "list". </param> |
| 73 | /// <param name="usage"> The usage information for the request. </param> |
| 74 | /// <param name="serializedAdditionalRawData"> Keeps track of any properties unknown to the library. </param> |
| 75 | internal EmbeddingCollection(IReadOnlyList<Embedding> data, string model, InternalCreateEmbeddingResponseObject @object, EmbeddingTokenUsage usage, IDictionary<string, BinaryData> serializedAdditionalRawData) |
| 76 | : base([.. data]) |
| 77 | { |
| 78 | Model = model; |
| 79 | Object = @object; |
| 80 | Usage = usage; |
| 81 | SerializedAdditionalRawData = serializedAdditionalRawData; |
| 82 | } |
| 83 | |
| 84 | // CUSTOM: Set the inherited Items property via the base constructor in favor of the suppressed Data property. |
| 85 | /// <summary> Initializes a new instance of <see cref="EmbeddingCollection"/> for deserialization. </summary> |
| 86 | internal EmbeddingCollection() |
| 87 | : base([]) |
| 88 | { |
| 89 | } |
| 90 | } |