Added local RAG (#756)

Co-authored-by: Thorsten Sommer <SommerEngineering@users.noreply.github.com>
This commit is contained in:
Paul KoudelkaandThorsten Sommer authored and GitHub committed 2026-09-09 18:43:37 +02:00
1 parent d043fbc8f0
commit c7b42bee96
179 files changed
+276977 -1421

No files matched your search

+30 -8
View File
@@ -6,7 +6,7 @@ public sealed class SlideManager
{
private readonly Dictionary<int, Slide> slides = new();
public void AddSlide(ContentStreamPresentationMetadata metadata, string? content, bool extractImages = false)
public void AddSlide(ContentStreamPresentationMetadata metadata, string? content, int? tokenCount, bool extractImages = false)
{
var slideNumber = metadata.Presentation?.SlideNumber ?? 0;
if(slideNumber is 0)
@@ -42,11 +42,15 @@ public sealed class SlideManager
var createdSlide = new Slide
{
Delivered = false,
Position = slideNumber
Position = slideNumber,
// The count of the text we just added. It travels with the slide, because the slide
// is delivered long after this event:
TokenCount = tokenCount
};
createdSlide.Content.Add(slideText);
//
// Add image content to the slide?
//
@@ -54,7 +58,12 @@ public sealed class SlideManager
{
var markdownImage = ContentStreamSseHandler.BuildImageMarkdown(image!.Id!, image.MediaType);
if (markdownImage is not null)
{
createdSlide.Content.Add(new SlideImageContent(markdownImage));
// The runtime counted the text of the slide, not the data URI we just added:
createdSlide.TokenCount = null;
}
}
this.slides[slideNumber] = createdSlide;
@@ -70,24 +79,37 @@ public sealed class SlideManager
{
var textContent = slide.Content.OfType<SlideTextContent>().First();
textContent.Text.AppendLine(content);
slide.TokenCount = ContentStreamPendingContent.AddTokenCounts(slide.TokenCount, tokenCount);
}
// Add any image content?
if (addImage)
{
var markdownImage = ContentStreamSseHandler.BuildImageMarkdown(image!.Id!, image.MediaType);
if (markdownImage is not null)
{
slide.Content.Add(new SlideImageContent(markdownImage));
// The runtime counted the text of the slide, not the data URI we just added:
slide.TokenCount = null;
}
}
}
}
public string? GetAllSlidesInOrder()
public ContentStreamPendingContent? GetAllSlidesInOrder()
{
var content = new StringBuilder();
// Starts at zero and stays a number only as long as every slide contributes a count of its
// own. One slide without one makes the total unknown, which is what the caller has to know:
int? tokenCount = 0;
foreach (var slide in this.slides.Values.Where(s => !s.Delivered).OrderBy(s => s.Position))
{
slide.Delivered = true;
tokenCount = ContentStreamPendingContent.AddTokenCounts(tokenCount, slide.TokenCount);
foreach (var text in slide.Content.OfType<SlideTextContent>())
{
content.AppendLine(text.Text.ToString());
@@ -100,7 +122,7 @@ public sealed class SlideManager
content.AppendLine();
}
}
return content.Length > 0 ? content.ToString() : null;
return content.Length > 0 ? new ContentStreamPendingContent(content.ToString(), tokenCount) : null;
}
}