mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-11-04 20:27:21 +00:00
Scaled down and converted images before sending them to AI models (#1101)
This commit is contained in:
1 parent
1c8632bbe0
commit
ba99bf6fae
33 files changed
+1550
-264
No files matched your search
@@ -0,0 +1,46 @@
|
||||
using AIStudio.Chat;
|
||||
using AIStudio.Tools.Rust;
|
||||
|
||||
namespace AIStudio.Tests.Tools;
|
||||
|
||||
/// <summary>
|
||||
/// Checks which image formats may be attached for an AI model.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The runtime decides which formats it can prepare for a model, see prepare_image_for_model in
|
||||
/// runtime/src/image.rs. An image the app lets through but the runtime cannot prepare would only
|
||||
/// fail once the message is sent; one the app refuses although the runtime could prepare it would
|
||||
/// be refused for nothing.
|
||||
/// </remarks>
|
||||
[TestFixture]
|
||||
public sealed class ModelImageFormatTests
|
||||
{
|
||||
/// <summary>
|
||||
/// The extensions model_input_format in runtime/src/image.rs accepts.
|
||||
/// </summary>
|
||||
private static readonly string[] RUNTIME_MODEL_FORMATS = ["jpg", "jpeg", "png", "webp", "gif", "bmp", "tif", "tiff"];
|
||||
|
||||
[Test]
|
||||
public void EveryFormatTheRuntimePreparesMayBeAttached()
|
||||
{
|
||||
Assert.That(FileTypes.MODEL_IMAGE.FlattenExtensions(), Is.EquivalentTo(RUNTIME_MODEL_FORMATS));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void OnlyFormatsWithoutADecoderAreRefused()
|
||||
{
|
||||
var refused = FileTypes.IMAGE.FlattenExtensions().Except(FileTypes.MODEL_IMAGE.FlattenExtensions());
|
||||
|
||||
Assert.That(refused, Is.EquivalentTo(new[] { "svg", "heic", "avif" }));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ATifFileIsAnImage()
|
||||
{
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(FileAttachment.FromPath("/tmp/scan.tif").IsImage, Is.True);
|
||||
Assert.That(FileTypes.IsAllowedPath("/tmp/scan.tif", FileTypes.MODEL_IMAGE), Is.True);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user