-
Notifications
You must be signed in to change notification settings - Fork 177
Expand file tree
/
Copy pathLoggingEmbeddingGenerator.cs
More file actions
23 lines (20 loc) · 1.02 KB
/
LoggingEmbeddingGenerator.cs
File metadata and controls
23 lines (20 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
using Microsoft.Extensions.AI;
using Microsoft.Extensions.Logging;
public class LoggingEmbeddingGenerator : DelegatingEmbeddingGenerator<string, Embedding<float>>
{
private readonly ILogger _logger;
private readonly IEmbeddingGenerator<string, Embedding<float>> _innerGenerator;
public LoggingEmbeddingGenerator(IEmbeddingGenerator<string, Embedding<float>> innerGenerator, ILogger? logger = null) : base(innerGenerator)
{
_innerGenerator = innerGenerator;
_logger = logger ?? LoggerFactory.Create(builder => builder.AddConsole()).CreateLogger<LoggingEmbeddingGenerator>();
}
public override async Task<GeneratedEmbeddings<Embedding<float>>> GenerateAsync(
IEnumerable<string> values,
EmbeddingGenerationOptions? options = null,
CancellationToken cancellationToken = default)
{
_logger.LogInformation("Generating embeddings for {count} values", values.Count());
return await _innerGenerator.GenerateAsync(values, options, cancellationToken);
}
}