Added a way to read what the AI received from your sources (#1100)

Co-authored-by: Thorsten Sommer <SommerEngineering@users.noreply.github.com>
This commit is contained in:
Paul KoudelkaandThorsten Sommer authored and GitHub committed 2026-10-26 10:00:01 +01:00
1 parent e0d8e18f34
commit cbc4ce5413
229 files changed
+12739 -1269

No files matched your search

@@ -10,8 +10,9 @@ namespace AIStudio.Tests.Tools;
/// <remarks>
/// The page a passage sits on travels from the runtime through the index into the retrieval
/// context, but it used to stop there: the AI was given the file and nothing else, so an answer
/// could name the document it rests on but never the place in it. A source which has no page, a
/// slide for instance, must stay silent rather than claim one.
/// could name the document it rests on but never the place in it. A passage over several pages
/// names all of them. A source which has no page, a slide for instance, must stay silent rather
/// than claim one.
/// </remarks>
[TestFixture]
public sealed class RetrievalContextDescriptionTests
@@ -24,12 +25,38 @@ public sealed class RetrievalContextDescriptionTests
Assert.That(description, Does.Contain("Content location: page 12"), "The AI is told the page, so it can say where an answer comes from.");
}
[Test]
public void APassageOverSeveralPagesNamesThemAll()
{
Assert.Multiple(() =>
{
Assert.That(Describe(TextContext(pageNumber: 12, endPageNumber: 14)), Does.Contain("Content location: pages 12 to 14"), "The AI can say on which pages an answer stands.");
Assert.That(Describe(TextContext(pageNumber: 12, endPageNumber: 12)), Does.Contain("Content location: page 12").And.Not.Contain("pages"), "A passage on one page names one page.");
});
}
[Test]
public void APassageWithoutAPageClaimsNone()
{
var description = Describe(TextContext(pageNumber: null));
Assert.That(description, Does.Not.Contain("Content location"), "A slide or a sheet has no page, and none is invented for it.");
Assert.That(description, Does.Not.Contain("Content location"), "A slide names no location, and none is invented for it.");
}
/// <remarks>
/// A document without pages names where a passage is the same way: a spreadsheet by its sheet
/// and rows, a table without sheets, such as a CSV file, by its rows alone, a text by its lines.
/// </remarks>
[Test]
public void APassageWithoutPagesNamesItsRowsOrItsLines()
{
Assert.Multiple(() =>
{
Assert.That(Describe(TableContext(sheetName: "Budget", startRow: 3, endRow: 9)), Does.Contain("Content location: sheet \"Budget\", rows 3 to 9"));
Assert.That(Describe(TableContext(startRow: 12)), Does.Contain("Content location: row 12"));
Assert.That(Describe(TableContext(startLine: 40, endLine: 85)), Does.Contain("Content location: lines 40 to 85"));
Assert.That(Describe(TableContext(startLine: 40, endLine: 40)), Does.Contain("Content location: line 40").And.Not.Contain("lines"), "A passage on one line names one line.");
});
}
/// <remarks>
@@ -138,7 +165,7 @@ public sealed class RetrievalContextDescriptionTests
return builder.ToString();
}
private static RetrievalTextContext TextContext(int? pageNumber, IReadOnlyList<string>? links = null) => new()
private static RetrievalTextContext TextContext(int? pageNumber, IReadOnlyList<string>? links = null, int? endPageNumber = null) => new()
{
DataSourceName = "Handbooks",
Category = RetrievalContentCategory.TEXT,
@@ -147,5 +174,20 @@ public sealed class RetrievalContextDescriptionTests
Links = links ?? [],
MatchedText = "The mixing console is described here.",
PageNumber = pageNumber,
EndPageNumber = endPageNumber,
};
private static RetrievalTextContext TableContext(string? sheetName = null, int? startRow = null, int? endRow = null, int? startLine = null, int? endLine = null) => new()
{
DataSourceName = "Budgets",
Category = RetrievalContentCategory.TEXT,
Type = RetrievalContentType.TEXT_SPREADSHEET,
Path = "/docs/budget.xlsx",
MatchedText = "rent,1200",
SheetName = sheetName,
StartRow = startRow,
EndRow = endRow,
StartLine = startLine,
EndLine = endLine,
};
}