openai/openai-dotnet
Publicmirrored from https://github.com/openai/openai-dotnetAvailable
src/Custom/Embeddings/OpenAIEmbeddingsModelFactory.cs
43lines · modecode
| 1 | using System.Collections.Generic; |
| 2 | using System.Linq; |
| 3 | |
| 4 | namespace OpenAI.Embeddings; |
| 5 | |
| 6 | /// <summary> Model factory for models. </summary> |
| 7 | public static partial class OpenAIEmbeddingsModelFactory |
| 8 | { |
| 9 | /// <summary> Initializes a new instance of <see cref="OpenAI.Embeddings.OpenAIEmbedding"/>. </summary> |
| 10 | /// <returns> A new <see cref="OpenAI.Embeddings.Embeddings"/> instance for mocking. </returns> |
| 11 | public static OpenAIEmbedding OpenAIEmbedding(int index = default, IEnumerable<float> vector = null) |
| 12 | { |
| 13 | vector ??= new List<float>(); |
| 14 | |
| 15 | return new OpenAIEmbedding( |
| 16 | index, |
| 17 | vector.ToArray()); |
| 18 | } |
| 19 | |
| 20 | /// <summary> Initializes a new instance of <see cref="OpenAI.Embeddings.OpenAIEmbeddingCollection"/>. </summary> |
| 21 | /// <returns> A new <see cref="OpenAI.Embeddings.OpenAIEmbeddingCollection"/> instance for mocking. </returns> |
| 22 | public static OpenAIEmbeddingCollection OpenAIEmbeddingCollection(IEnumerable<OpenAIEmbedding> items = null, string model = null, EmbeddingTokenUsage usage = null) |
| 23 | { |
| 24 | items ??= new List<OpenAIEmbedding>(); |
| 25 | |
| 26 | return new OpenAIEmbeddingCollection( |
| 27 | items.ToList(), |
| 28 | model, |
| 29 | InternalCreateEmbeddingResponseObject.List, |
| 30 | usage, |
| 31 | serializedAdditionalRawData: null); |
| 32 | } |
| 33 | |
| 34 | /// <summary> Initializes a new instance of <see cref="OpenAI.Embeddings.EmbeddingTokenUsage"/>. </summary> |
| 35 | /// <returns> A new <see cref="OpenAI.Embeddings.EmbeddingTokenUsage"/> instance for mocking. </returns> |
| 36 | public static EmbeddingTokenUsage EmbeddingTokenUsage(int inputTokenCount = default, int totalTokenCount = default) |
| 37 | { |
| 38 | return new EmbeddingTokenUsage( |
| 39 | inputTokenCount, |
| 40 | totalTokenCount, |
| 41 | additionalBinaryDataProperties: null); |
| 42 | } |
| 43 | } |
| 44 | |