mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-12-06 04:31:36 +00:00
Added whole documents to the Translation, Grammar & Spelling, and Rewrite & Improve assistants (#1179)
Co-authored-by: Thorsten Sommer <SommerEngineering@users.noreply.github.com>
This commit is contained in:
1 parent
f7666861f1
commit
918572c158
150 files changed
+12850
-302
No files matched your search
@@ -0,0 +1,58 @@
|
||||
using AIStudio.Tools.DocumentSegments;
|
||||
|
||||
namespace AIStudio.Tests.Tools.DocumentSegments;
|
||||
|
||||
/// <summary>
|
||||
/// Checks how the segments of a document are grouped into the requests to a model.
|
||||
/// </summary>
|
||||
[TestFixture]
|
||||
public sealed class SegmentBatchPlannerTests
|
||||
{
|
||||
[Test]
|
||||
public void EveryTextGoesOnceInTheOrderOfTheDocument()
|
||||
{
|
||||
var segments = Segments("Introduction", "Page 1", "2026", "Introduction", "Summary", "Page 1");
|
||||
|
||||
var batches = SegmentBatchPlanner.Plan(segments);
|
||||
|
||||
Assert.That(batches.Single().Select(segment => segment.Key), Is.EqualTo(new[] { "Introduction", "Page 1", "Summary" }), "A repeated text goes once, and a text without letters stays out.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ABatchEndsBeforeItGetsTooLong()
|
||||
{
|
||||
var segments = Segments("aaaa", "bbbb", "cccc", "dddd", "eeee");
|
||||
|
||||
var batches = SegmentBatchPlanner.Plan(segments, maxCharacters: 10, maxSegments: 40);
|
||||
|
||||
Assert.That(batches.Select(batch => batch.Count), Is.EqualTo(new[] { 2, 2, 1 }));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ABatchEndsAfterItsLastSegment()
|
||||
{
|
||||
var segments = Segments("a", "b", "c", "d", "e");
|
||||
|
||||
var batches = SegmentBatchPlanner.Plan(segments, maxCharacters: 1_000, maxSegments: 2);
|
||||
|
||||
Assert.That(batches.Select(batch => batch.Count), Is.EqualTo(new[] { 2, 2, 1 }));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ASegmentLongerThanABatchGetsABatchOfItsOwn()
|
||||
{
|
||||
var segments = Segments("short", new string('x', 50), "end");
|
||||
|
||||
var batches = SegmentBatchPlanner.Plan(segments, maxCharacters: 20, maxSegments: 40);
|
||||
|
||||
Assert.That(batches.Select(batch => batch.Count), Is.EqualTo(new[] { 1, 1, 1 }));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ADocumentWithoutWordsNeedsNoRequest()
|
||||
{
|
||||
Assert.That(SegmentBatchPlanner.Plan(Segments("1", "2026-11-09", "—")), Is.Empty);
|
||||
}
|
||||
|
||||
private static IEnumerable<DocumentSegment> Segments(params string[] texts) => texts.Select(text => new DocumentSegment(new TaggedTextBuilder().Words(text).Build()));
|
||||
}
|
||||
Reference in new issue
Block a user