mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-11-04 15:27:21 +00:00
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:
1 parent
e0d8e18f34
commit
cbc4ce5413
229 files changed
+12739
-1269
No files matched your search
@@ -0,0 +1,92 @@
|
||||
using AIStudio.Components;
|
||||
using AIStudio.Tools;
|
||||
|
||||
using Markdig.Extensions.Mathematics;
|
||||
using Markdig.Syntax;
|
||||
|
||||
namespace AIStudio.Tests.Components;
|
||||
|
||||
/// <summary>
|
||||
/// Checks how much of a long text the content viewer shows.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The viewer shows only the beginning of a text which is too long to render, and it must not tear
|
||||
/// a line apart while doing so: a cut through a table row or a code fence would show the user a
|
||||
/// broken document, as if we had read it wrong.
|
||||
/// </remarks>
|
||||
[TestFixture]
|
||||
public sealed class ContentViewerTests
|
||||
{
|
||||
[Test]
|
||||
public void ATextWhichFitsIsShownEntirely()
|
||||
{
|
||||
const string TEXT = "# Heading\nA short passage.";
|
||||
|
||||
var shown = ContentViewer.CutAtLineBreak(TEXT, 100, out var cutOffCharacters);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(shown, Is.SameAs(TEXT));
|
||||
Assert.That(cutOffCharacters, Is.Zero);
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ATextOfExactlyTheLimitIsShownEntirely()
|
||||
{
|
||||
var text = new string('a', 50);
|
||||
|
||||
var shown = ContentViewer.CutAtLineBreak(text, 50, out var cutOffCharacters);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(shown, Is.EqualTo(text));
|
||||
Assert.That(cutOffCharacters, Is.Zero);
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ALongTextIsCutAfterTheLastLineBreakBeforeTheLimit()
|
||||
{
|
||||
const string TEXT = "| a | b |\n| 1 | 2 |\n| 3 | 4 |";
|
||||
|
||||
var shown = ContentViewer.CutAtLineBreak(TEXT, 25, out var cutOffCharacters);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(shown, Is.EqualTo("| a | b |\n| 1 | 2 |\n"), "The last table row would be torn apart, so it goes as a whole.");
|
||||
Assert.That(cutOffCharacters, Is.EqualTo(TEXT.Length - shown.Length));
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DollarSignsInContentAreNoMath()
|
||||
{
|
||||
//
|
||||
// Taken for math, the text would have MudMarkdown typeset the whole page with MathJax, which
|
||||
// replaces elements Blazor renders, so that the next render of the viewer fails:
|
||||
//
|
||||
const string TEXT = "The budget $\\rho$ is spent on the hardest tokens.";
|
||||
static bool HasMath(Markdig.MarkdownPipeline pipeline) => Markdig.Markdown.Parse(TEXT, pipeline).Descendants<MathInline>().Any();
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(HasMath(Markdown.SAFE_MARKDOWN_PIPELINE), Is.True, "The safe pipeline reads this as math.");
|
||||
Assert.That(HasMath(Markdown.CONTENT_MARKDOWN_PIPELINE), Is.False, "What AI Studio read from a document stays text.");
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ALongTextWithoutLineBreaksIsCutAtTheLimit()
|
||||
{
|
||||
var text = new string('a', 30);
|
||||
|
||||
var shown = ContentViewer.CutAtLineBreak(text, 20, out var cutOffCharacters);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(shown, Has.Length.EqualTo(20));
|
||||
Assert.That(cutOffCharacters, Is.EqualTo(10));
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
using AIStudio.Components;
|
||||
using AIStudio.Tools;
|
||||
|
||||
namespace AIStudio.Tests.Components;
|
||||
|
||||
/// <summary>
|
||||
/// Checks which actions a path gets: those of a file, those of a web page, or none.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// A button which cannot work must not show: a relative path would open another file depending on
|
||||
/// where it is opened from, and the address of a mail names it for AI Studio only.
|
||||
/// </remarks>
|
||||
[TestFixture]
|
||||
public sealed class FileActionsTests
|
||||
{
|
||||
[Test]
|
||||
public void AnAbsolutePathIsAFile() => Assert.That(FileActions.DetermineKind(Path.Combine(Path.GetTempPath(), "minutes.pdf")), Is.EqualTo(FileActions.FileActionsKind.FILE));
|
||||
|
||||
[TestCase("https://example.org/budget-2026")]
|
||||
[TestCase("http://intranet.example.org/wiki/page")]
|
||||
public void AWebAddressIsAWebPage(string address) => Assert.That(FileActions.DetermineKind(address), Is.EqualTo(FileActions.FileActionsKind.WEB_PAGE));
|
||||
|
||||
[TestCase("")]
|
||||
[TestCase("notes/minutes.txt")]
|
||||
public void ARelativePathOrNothingGetsNoActions(string path) => Assert.That(FileActions.DetermineKind(path), Is.EqualTo(FileActions.FileActionsKind.NONE));
|
||||
|
||||
[Test]
|
||||
public void AMailGetsNoActions() => Assert.That(FileActions.DetermineKind(SourceExtensions.CreateMailSourceUrl("6a1f2b3c-4d5e-4f60-8a7b-9c0d1e2f3a4b", "mail-1")), Is.EqualTo(FileActions.FileActionsKind.NONE));
|
||||
|
||||
[Test]
|
||||
public void WhatOnlyADataSourceKnowsGetsNoActions() => Assert.That(FileActions.DetermineKind(SourceExtensions.CreateRetrievalSourceUrl("handbook.pdf", "docs/handbook.pdf")), Is.EqualTo(FileActions.FileActionsKind.NONE));
|
||||
}
|
||||
Reference in new issue
Block a user