mirror of
https://github.com/marcominerva/SqlDatabaseVectorSearch.git
synced 2026-06-20 12:23:10 +00:00
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:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user