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.Embedding"/>. </summary> |
| 10 | /// <returns> A new <see cref="OpenAI.Embeddings.Embeddings"/> instance for mocking. </returns> |
| 11 | public static Embedding Embedding(int index = default, IEnumerable<float> vector = null) |
| 12 | { |
| 13 | vector ??= new List<float>(); |
| 14 | |
| 15 | return new Embedding( |
| 16 | index, |
| 17 | vector.ToArray()); |
| 18 | } |
| 19 | |
| 20 | /// <summary> Initializes a new instance of <see cref="OpenAI.Embeddings.EmbeddingCollection"/>. </summary> |
| 21 | /// <returns> A new <see cref="OpenAI.Embeddings.EmbeddingCollection"/> instance for mocking. </returns> |
| 22 | public static EmbeddingCollection EmbeddingCollection(IEnumerable<Embedding> items = null, string model = null, EmbeddingTokenUsage usage = null) |
| 23 | { |
| 24 | items ??= new List<Embedding>(); |
| 25 | |
| 26 | return new EmbeddingCollection( |
| 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 inputTokens = default, int totalTokens = default) |
| 37 | { |
| 38 | return new EmbeddingTokenUsage( |
| 39 | inputTokens, |
| 40 | totalTokens, |
| 41 | serializedAdditionalRawData: null); |
| 42 | } |
| 43 | } |
| 44 | |