openai/openai-dotnet

Public

mirrored from https://github.com/openai/openai-dotnetAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
OpenAI_2.3.0

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

src/Custom/Embeddings/OpenAIEmbeddingCollection.cs

68lines · modecode

1using System;
2using System.ClientModel;
3using System.ClientModel.Primitives;
4using System.Collections.Generic;
5using System.Collections.ObjectModel;
6using System.Text.Json;
7
8namespace OpenAI.Embeddings;
9
10[CodeGenType("CreateEmbeddingResponse")]
11[CodeGenSuppress("Data")]
12[CodeGenSuppress(nameof(OpenAIEmbeddingCollection))]
13[CodeGenSuppress(nameof(OpenAIEmbeddingCollection), typeof(string), typeof(EmbeddingTokenUsage))]
14[CodeGenSuppress(nameof(OpenAIEmbeddingCollection), typeof(string), typeof(EmbeddingTokenUsage), typeof(string), typeof(IDictionary<string, BinaryData>))]
15public partial class OpenAIEmbeddingCollection : ReadOnlyCollection<OpenAIEmbedding>
16{
17 // CUSTOM: Made private. This property does not add value in the context of a strongly-typed class.
18 /// <summary> The object type, which is always "list". </summary>
19 [CodeGenMember("Object")]
20 private string Object { get; } = "list";
21
22 // CUSTOM: Set the inherited Items property via the base constructor in favor of the suppressed Data property.
23 /// <summary> Initializes a new instance of <see cref="OpenAIEmbeddingCollection"/>. </summary>
24 /// <param name="data"> The list of embeddings generated by the model. </param>
25 /// <param name="model"> The name of the model used to generate the embedding. </param>
26 /// <param name="usage"> The usage information for the request. </param>
27 /// <exception cref="ArgumentNullException"> <paramref name="data"/>, <paramref name="model"/> or <paramref name="usage"/> is null. </exception>
28 internal OpenAIEmbeddingCollection(IEnumerable<OpenAIEmbedding> data, string model, EmbeddingTokenUsage usage)
29 : base([.. data])
30 {
31 Argument.AssertNotNull(data, nameof(data));
32 Argument.AssertNotNull(model, nameof(model));
33 Argument.AssertNotNull(usage, nameof(usage));
34
35 Model = model;
36 Usage = usage;
37 }
38
39 // CUSTOM: Set the inherited Items property via the base constructor in favor of the suppressed Data property.
40 /// <summary> Initializes a new instance of <see cref="OpenAIEmbeddingCollection"/>. </summary>
41 /// <param name="data"> The list of embeddings generated by the model. </param>
42 /// <param name="model"> The name of the model used to generate the embedding. </param>
43 /// <param name="object"> The object type, which is always "list". </param>
44 /// <param name="usage"> The usage information for the request. </param>
45 /// <param name="serializedAdditionalRawData"> Keeps track of any properties unknown to the library. </param>
46 internal OpenAIEmbeddingCollection(IReadOnlyList<OpenAIEmbedding> data, string model, string @object, EmbeddingTokenUsage usage, IDictionary<string, BinaryData> serializedAdditionalRawData)
47 : base([.. data])
48 {
49 Model = model;
50 Object = @object;
51 Usage = usage;
52 _additionalBinaryDataProperties = serializedAdditionalRawData;
53 }
54
55 // CUSTOM: Set the inherited Items property via the base constructor in favor of the suppressed Data property.
56 /// <summary> Initializes a new instance of <see cref="OpenAIEmbeddingCollection"/> for deserialization. </summary>
57 internal OpenAIEmbeddingCollection()
58 : base([])
59 {
60 }
61
62 internal static OpenAIEmbeddingCollection FromClientResult(ClientResult result)
63 {
64 using PipelineResponse response = result.GetRawResponse();
65 using JsonDocument document = JsonDocument.Parse(response.Content);
66 return DeserializeOpenAIEmbeddingCollection(document.RootElement, ModelSerializationExtensions.WireOptions);
67 }
68}