|
123456789101112131415161718192021222324252627282930 |
- using LLama;
- using Microsoft.SemanticKernel;
- using Microsoft.SemanticKernel.Embeddings;
-
- namespace LLamaSharp.SemanticKernel.TextEmbedding;
-
- public sealed class LLamaSharpEmbeddingGeneration : ITextEmbeddingGenerationService
- {
- private readonly LLamaEmbedder _embedder;
-
- private readonly Dictionary<string, object?> _attributes = new();
-
- public IReadOnlyDictionary<string, object?> Attributes => this._attributes;
-
- public LLamaSharpEmbeddingGeneration(LLamaEmbedder embedder)
- {
- _embedder = embedder;
- }
-
- /// <inheritdoc/>
- public async Task<IList<ReadOnlyMemory<float>>> GenerateEmbeddingsAsync(IList<string> data, Kernel? kernel = null, CancellationToken cancellationToken = default)
- {
- var result = new List<ReadOnlyMemory<float>>();
-
- foreach (var item in data)
- result.Add(await _embedder.GetEmbeddings(item, cancellationToken));
-
- return result;
- }
- }
|