diff --git a/app/MindWork AI Studio/Tools/ContentStreamSseHandler.cs b/app/MindWork AI Studio/Tools/ContentStreamSseHandler.cs index ba640f01..fc8c46f2 100644 --- a/app/MindWork AI Studio/Tools/ContentStreamSseHandler.cs +++ b/app/MindWork AI Studio/Tools/ContentStreamSseHandler.cs @@ -8,7 +8,7 @@ public static class ContentStreamSseHandler private static readonly ConcurrentDictionary> CHUNKED_IMAGES = new(); private static readonly ConcurrentDictionary CURRENT_SLIDE_NUMBERS = new(); - public static string ProcessEvent(ContentStreamSseEvent? sseEvent, bool extractImages = true) + public static string? ProcessEvent(ContentStreamSseEvent? sseEvent, bool extractImages = true) { switch (sseEvent) { @@ -41,15 +41,18 @@ public static class ContentStreamSseHandler var image = presentationMetadata.Presentation?.Image ?? null; var presentationResult = new StringBuilder(); var streamId = sseEvent.StreamId; - + CURRENT_SLIDE_NUMBERS.TryGetValue(streamId!, out var currentSlideNumber); - if (slideNumber != currentSlideNumber) + { + presentationResult.AppendLine(); presentationResult.AppendLine($"# Slide {slideNumber}"); + } - presentationResult.Append($"{sseEvent.Content}"); - - if (image is not null) + if(!string.IsNullOrWhiteSpace(sseEvent.Content)) + presentationResult.AppendLine(sseEvent.Content); + + if (extractImages && image is not null) { var imageId = $"{streamId}-{image.Id!}"; var isEnd = ProcessImageSegment(imageId, image); @@ -58,8 +61,8 @@ public static class ContentStreamSseHandler } CURRENT_SLIDE_NUMBERS[streamId!] = slideNumber; - - return presentationResult.ToString(); + return presentationResult.Length is 0 ? null : presentationResult.ToString(); + default: return sseEvent.Content; } diff --git a/app/MindWork AI Studio/Tools/Services/RustService.Retrieval.cs b/app/MindWork AI Studio/Tools/Services/RustService.Retrieval.cs index 3d43eb72..7bebdc32 100644 --- a/app/MindWork AI Studio/Tools/Services/RustService.Retrieval.cs +++ b/app/MindWork AI Studio/Tools/Services/RustService.Retrieval.cs @@ -37,7 +37,9 @@ public sealed partial class RustService if (sseEvent is not null) { var content = ContentStreamSseHandler.ProcessEvent(sseEvent, false); - resultBuilder.Append(content); + if(content is not null) + resultBuilder.AppendLine(content); + chunkCount++; } }