AI-Studio/app/Tests/Chat/ConversationTokensTests.cs
Thorsten Sommer d85b4e71b6
Some checks are pending
Build and Release / Determine run mode (push) Waiting to run
Build and Release / Sync Flatpak repo (push) Blocked by required conditions
Build and Release / Collect Flatpak artifacts (push) Blocked by required conditions
Build and Release / Verify (push) Waiting to run
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-apple-darwin, osx-arm64, macos-latest, aarch64-apple-darwin, dmg,app,updater, dmg) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-pc-windows-msvc.exe, win-arm64, windows-latest, aarch64-pc-windows-msvc, nsis,updater, nsis) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-unknown-linux-gnu, linux-arm64, ubuntu-22.04-arm, aarch64-unknown-linux-gnu, appimage,updater, appimage) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-apple-darwin, osx-x64, macos-latest, x86_64-apple-darwin, dmg,app,updater, dmg) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-pc-windows-msvc.exe, win-x64, windows-latest, x86_64-pc-windows-msvc, nsis,updater, nsis) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-unknown-linux-gnu, linux-x64, ubuntu-22.04, x86_64-unknown-linux-gnu, appimage,updater, appimage) (push) Blocked by required conditions
Build and Release / Prepare & create release (push) Blocked by required conditions
Build and Release / Publish release (push) Blocked by required conditions
Rebuilt how AI Studio knows what a model can do (#960)
2026-09-13 14:17:25 +02:00

96 lines
3.2 KiB
C#

using AIStudio.Chat;
using AIStudio.Models;
namespace AIStudio.Tests.Chat;
/// <summary>
/// Checks what the chat says about the images a conversation carries.
/// </summary>
/// <remarks>
/// The visual briefing refuses a build with too many pictures, because that build is expensive and
/// fails late. A chat cannot refuse anything: the pictures are already in the conversation, and
/// taking them back out means deleting messages. So the chat says so instead, and what is checked
/// here is that it says so at the right moment -- and, more importantly, that it stays quiet when
/// nobody wrote a limit down.
/// </remarks>
[TestFixture]
public sealed class ConversationTokensTests
{
[TestCase(1, 100, false)]
[TestCase(100, 100, false, Description = "Exactly the limit still fits. It is a maximum, not a threshold.")]
[TestCase(101, 100, true)]
[TestCase(3_601, 3_600, true)]
public void TooManyPicturesIsAQuestionOfTheNumberTheVendorStated(int images, int allowed, bool tooMany)
{
var counted = new ConversationTokens
{
IsKnown = true,
UncountedImages = images,
ImageLimits = new ImageLimits(null, allowed),
};
Assert.That(counted.TooManyImages, Is.EqualTo(tooMany));
}
[Test]
public void WithoutAStatedLimitThereIsNoSuchThingAsTooMany()
{
//
// The common case. Most models are served at whatever their operator configured, and an app
// which warned about the seventh picture would be inventing a ceiling nobody wrote.
//
var counted = new ConversationTokens
{
IsKnown = true,
UncountedImages = 500,
ImageLimits = ImageLimits.UNKNOWN,
};
Assert.That(counted.TooManyImages, Is.False);
}
[Test]
public void TheSmallerOfTwoStatedLimitsIsTheOneWhichDecides()
{
//
// A message is part of a request, so a conversation which fits the request limit can still
// be too much for one message. Both are compared against the same number of pictures,
// because a chat sends all of them in one message.
//
var counted = new ConversationTokens
{
IsKnown = true,
UncountedImages = 20,
ImageLimits = new ImageLimits(8, 100),
};
Assert.Multiple(() =>
{
Assert.That(counted.TooManyImages, Is.True);
Assert.That(counted.ImageLimits.MaxInOneMessage, Is.EqualTo(8));
});
}
[Test]
public void AConversationWithoutPicturesNeverComplainsAboutThem()
{
var counted = new ConversationTokens
{
IsKnown = true,
UncountedImages = 0,
ImageLimits = new ImageLimits(null, 0),
};
Assert.That(counted.TooManyImages, Is.False, "Not even against a model which takes none at all.");
}
[Test]
public void AnUnavailableCountClaimsNothingAboutPictures()
{
//
// Nothing could be counted, so nothing is known -- including how many pictures travel. A
// warning built on that would be made up.
//
Assert.That(ConversationTokens.UNAVAILABLE.TooManyImages, Is.False);
}
}