mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2025-07-28 06:02:56 +00:00
changed image and slide number context to use the guid to identify the right stream in case of parallel processing
This commit is contained in:
parent
8240a83662
commit
3c40348fb4
@ -6,7 +6,7 @@ namespace AIStudio.Tools;
|
|||||||
public static class ContentStreamSseHandler
|
public static class ContentStreamSseHandler
|
||||||
{
|
{
|
||||||
private static readonly ConcurrentDictionary<string, List<ContentStreamPptxImageData>> PPTX_IMAGES = new();
|
private static readonly ConcurrentDictionary<string, List<ContentStreamPptxImageData>> PPTX_IMAGES = new();
|
||||||
private static int CURRENT_SLIDE_NUMBER;
|
private static readonly ConcurrentDictionary<string, int> CURRENT_SLIDE_NUMBERS = new();
|
||||||
|
|
||||||
public static string ProcessEvent(ContentStreamSseEvent? sseEvent, bool extractImages = true)
|
public static string ProcessEvent(ContentStreamSseEvent? sseEvent, bool extractImages = true)
|
||||||
{
|
{
|
||||||
@ -40,21 +40,26 @@ public static class ContentStreamSseHandler
|
|||||||
var slideNumber = presentationMetadata.Presentation?.SlideNumber ?? 0;
|
var slideNumber = presentationMetadata.Presentation?.SlideNumber ?? 0;
|
||||||
var image = presentationMetadata.Presentation?.Image ?? null;
|
var image = presentationMetadata.Presentation?.Image ?? null;
|
||||||
var presentationResult = new StringBuilder();
|
var presentationResult = new StringBuilder();
|
||||||
if (slideNumber != CURRENT_SLIDE_NUMBER)
|
var streamId = sseEvent.StreamId;
|
||||||
|
|
||||||
|
CURRENT_SLIDE_NUMBERS.TryGetValue(streamId!, out var currentSlideNumber);
|
||||||
|
|
||||||
|
if (slideNumber != currentSlideNumber)
|
||||||
presentationResult.AppendLine($"# Slide {slideNumber}");
|
presentationResult.AppendLine($"# Slide {slideNumber}");
|
||||||
|
|
||||||
presentationResult.Append($"{sseEvent.Content}");
|
presentationResult.Append($"{sseEvent.Content}");
|
||||||
|
|
||||||
if (image is not null)
|
if (image is not null)
|
||||||
{
|
{
|
||||||
var isEnd = ProcessImageSegment(image);
|
var imageId = $"{streamId}-{image.Id!}";
|
||||||
|
var isEnd = ProcessImageSegment(imageId, image);
|
||||||
if (isEnd && extractImages)
|
if (isEnd && extractImages)
|
||||||
presentationResult.AppendLine(BuildImage(image.Id!));
|
presentationResult.AppendLine(BuildImage(imageId));
|
||||||
}
|
}
|
||||||
|
|
||||||
CURRENT_SLIDE_NUMBER = slideNumber;
|
CURRENT_SLIDE_NUMBERS[streamId!] = slideNumber;
|
||||||
return presentationResult.ToString();
|
|
||||||
|
|
||||||
|
return presentationResult.ToString();
|
||||||
default:
|
default:
|
||||||
return sseEvent.Content;
|
return sseEvent.Content;
|
||||||
}
|
}
|
||||||
@ -67,26 +72,25 @@ public static class ContentStreamSseHandler
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool ProcessImageSegment(ContentStreamPptxImageData contentStreamPptxImageData)
|
private static bool ProcessImageSegment(string imageId, ContentStreamPptxImageData contentStreamPptxImageData)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(contentStreamPptxImageData.Id))
|
if (string.IsNullOrWhiteSpace(contentStreamPptxImageData.Id) || string.IsNullOrWhiteSpace(imageId))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
var id = contentStreamPptxImageData.Id;
|
|
||||||
var segment = contentStreamPptxImageData.Segment ?? 0;
|
var segment = contentStreamPptxImageData.Segment ?? 0;
|
||||||
var content = contentStreamPptxImageData.Content ?? string.Empty;
|
var content = contentStreamPptxImageData.Content ?? string.Empty;
|
||||||
var isEnd = contentStreamPptxImageData.IsEnd;
|
var isEnd = contentStreamPptxImageData.IsEnd;
|
||||||
|
|
||||||
var imageSegment = new ContentStreamPptxImageData
|
var imageSegment = new ContentStreamPptxImageData
|
||||||
{
|
{
|
||||||
Id = id,
|
Id = imageId,
|
||||||
Content = content,
|
Content = content,
|
||||||
Segment = segment,
|
Segment = segment,
|
||||||
IsEnd = isEnd,
|
IsEnd = isEnd,
|
||||||
};
|
};
|
||||||
|
|
||||||
PPTX_IMAGES.AddOrUpdate(
|
PPTX_IMAGES.AddOrUpdate(
|
||||||
id,
|
imageId,
|
||||||
_ => [imageSegment],
|
_ => [imageSegment],
|
||||||
(_, existingList) =>
|
(_, existingList) =>
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user