Refactor response handling and content decoding

- Updated `TextContentDecoder` to use `ITextChunker` for paragraph splitting and return a list of `Chunk` objects.
- Changed return type of `Stream` method in `AskEndpoints.cs` from `IAsyncEnumerable<QuestionResponse>` to `IAsyncEnumerable<Response>`.
- Removed `QuestionResponse` class and introduced `Response` class to better handle streaming responses.
- Modified `AskQuestionAsync` and `AskStreamingAsync` methods in `VectorSearchService` to return `Response` instead of `QuestionResponse`, and adjusted token count calculation.
- Added namespace declaration in `Response.cs` and defined properties to align with new response structure.
This commit is contained in:
Marco Minerva
2025-06-04 10:22:15 +02:00
parent a7fef36b66
commit 2fc070d0aa
5 changed files with 22 additions and 17 deletions
@@ -1,12 +1,17 @@
namespace SqlDatabaseVectorSearch.ContentDecoders;
using SqlDatabaseVectorSearch.TextChunkers;
public class TextContentDecoder : IContentDecoder
namespace SqlDatabaseVectorSearch.ContentDecoders;
public class TextContentDecoder(IServiceProvider serviceProvider) : IContentDecoder
{
public async Task<IEnumerable<Chunk>> DecodeAsync(Stream stream, string contentType, CancellationToken cancellationToken = default)
{
var textChunker = serviceProvider.GetRequiredKeyedService<ITextChunker>(contentType);
using var readStream = new StreamReader(stream);
var content = await readStream.ReadToEndAsync(cancellationToken);
return [new(1, 0, content)];
var paragraphs = textChunker.Split(content);
return paragraphs.Select((text, index) => new Chunk(1, index, text)).ToList();
}
}