mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-11-21 02:33:48 +00:00
Improved the assistants page with categories for assistant plugins (#1211)
This commit is contained in:
1 parent
ef059ffd15
commit
1db0f85898
74 files changed
+3392
-380
No files matched your search
@@ -0,0 +1,64 @@
|
||||
using AIStudio.Tools.PluginSystem;
|
||||
using AIStudio.Tools.PluginSystem.Assistants;
|
||||
|
||||
namespace AIStudio.Tests.Tools.PluginSystem;
|
||||
|
||||
/// <summary>
|
||||
/// Checks that AI Studio writes the categories of a direct chat launcher so that they load back.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// AI Studio writes the plugin.lua of a launcher itself, when the Assistant Builder creates one and
|
||||
/// whenever a user changes its chat settings. Its categories decide where the assistants page shows it,
|
||||
/// so they have to survive both.
|
||||
/// </remarks>
|
||||
[TestFixture]
|
||||
public sealed class DirectChatLauncherCategoriesTests
|
||||
{
|
||||
private static readonly Guid PLUGIN_ID = Guid.Parse("5b7d9f1a-3c5e-4a7b-8d9f-1b3d5f7a9c2e");
|
||||
|
||||
[Test]
|
||||
public async Task CustomCategoriesLoadBack()
|
||||
{
|
||||
var lua = DirectChatLauncherLuaWriter.Write(CreateMetadata([PluginCategory.BUSINESS, PluginCategory.CUSTOM], ["Space Travel"]), CreateDefinition());
|
||||
using var plugin = await PluginFactory.Load(null, lua);
|
||||
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(plugin.IsValid, Is.True, string.Join(" ", plugin.Issues));
|
||||
Assert.That(plugin.Categories, Is.EqualTo(new[] { PluginCategory.BUSINESS, PluginCategory.CUSTOM }));
|
||||
Assert.That(plugin.CustomCategories, Is.EqualTo(new[] { "Space Travel" }));
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ALauncherWithoutCustomCategoriesWritesNoTableForThem()
|
||||
{
|
||||
var lua = DirectChatLauncherLuaWriter.Write(CreateMetadata([PluginCategory.EDUCATION], []), CreateDefinition());
|
||||
using var plugin = await PluginFactory.Load(null, lua);
|
||||
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(lua, Does.Not.Contain("CUSTOM_CATEGORIES"));
|
||||
Assert.That(plugin.IsValid, Is.True, string.Join(" ", plugin.Issues));
|
||||
Assert.That(plugin.Categories, Is.EqualTo(new[] { PluginCategory.EDUCATION }));
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task CustomWithoutItsNamesFallsBackInsteadOfBreakingThePlugin()
|
||||
{
|
||||
var lua = DirectChatLauncherLuaWriter.Write(CreateMetadata([PluginCategory.CUSTOM], []), CreateDefinition());
|
||||
using var plugin = await PluginFactory.Load(null, lua);
|
||||
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(plugin.IsValid, Is.True, string.Join(" ", plugin.Issues));
|
||||
Assert.That(plugin.Categories, Is.EqualTo(new[] { PluginCategory.COMMON }), "A launcher which lost the names of its custom categories lands under \"General\".");
|
||||
}
|
||||
}
|
||||
|
||||
private static DirectChatLauncherPluginMetadata CreateMetadata(PluginCategory[] categories, string[] customCategories) => new(PLUGIN_ID, "1.0.0", null, ["MindWork AI"], "MindWork AI",
|
||||
"https://github.com/MindWorkAI/AI-Studio", categories, customCategories, [PluginTargetGroup.EVERYONE], IsMaintained: true, DeprecationMessage: string.Empty, IsAssistantBuilderGenerated: true);
|
||||
|
||||
private static DirectChatLauncherDefinition CreateDefinition() => new("Launcher for the tests", "Launcher for the tests", "Opens a disappearing chat.", new AssistantChatLaunchConfiguration(string.Empty, null, null, null, null, null));
|
||||
}
|
||||
@@ -108,6 +108,8 @@ public sealed class LeftOverConfigurationObjectsTests
|
||||
|
||||
public PluginCategory[] Categories => [];
|
||||
|
||||
public string[] CustomCategories => [];
|
||||
|
||||
public PluginTargetGroup[] TargetGroups => [];
|
||||
|
||||
public bool IsMaintained => true;
|
||||
|
||||
@@ -0,0 +1,179 @@
|
||||
using AIStudio.Tools.PluginSystem;
|
||||
|
||||
namespace AIStudio.Tests.Tools.PluginSystem;
|
||||
|
||||
/// <summary>
|
||||
/// Checks how a plugin states its categories, its custom ones included.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The assistants page shows each assistant under its categories. A plugin may also name categories of
|
||||
/// its own: it declares CUSTOM in CATEGORIES and lists their names in CUSTOM_CATEGORIES. Both belong
|
||||
/// together, so a plugin which states only one of them is invalid, and its authors notice it right away.
|
||||
/// </remarks>
|
||||
[TestFixture]
|
||||
public sealed class PluginCategoriesTests
|
||||
{
|
||||
private static readonly Guid PLUGIN_ID = Guid.Parse("8d2e4b6a-1c3f-4a5e-9b7d-0f2a4c6e8b1d");
|
||||
|
||||
[Test]
|
||||
public async Task TheNewCategoriesAreRead()
|
||||
{
|
||||
using var plugin = await LoadModelPlugin("""CATEGORIES = {"COMMON", "AI_STUDIO_DEVELOPMENT"}""");
|
||||
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(plugin.IsValid, Is.True, string.Join(" ", plugin.Issues));
|
||||
Assert.That(plugin.Categories, Is.EqualTo(new[] { PluginCategory.COMMON, PluginCategory.AI_STUDIO_DEVELOPMENT }));
|
||||
Assert.That(plugin.CustomCategories, Is.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task CustomCategoriesAreRead()
|
||||
{
|
||||
using var plugin = await LoadModelPlugin("""
|
||||
CATEGORIES = {"SCIENCE", "CUSTOM"}
|
||||
CUSTOM_CATEGORIES = {"Space Travel", " Deep Space "}
|
||||
""");
|
||||
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(plugin.IsValid, Is.True, string.Join(" ", plugin.Issues));
|
||||
Assert.That(plugin.Categories, Is.EqualTo(new[] { PluginCategory.SCIENCE, PluginCategory.CUSTOM }));
|
||||
Assert.That(plugin.CustomCategories, Is.EqualTo(new[] { "Space Travel", "Deep Space" }), "Names are trimmed, so that equal names share one heading.");
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ASingleCustomCategoryIsRead()
|
||||
{
|
||||
using var plugin = await LoadModelPlugin("""
|
||||
CATEGORIES = {"CUSTOM"}
|
||||
CUSTOM_CATEGORIES = {"Space Travel"}
|
||||
""");
|
||||
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(plugin.IsValid, Is.True, string.Join(" ", plugin.Issues));
|
||||
Assert.That(plugin.CustomCategories, Is.EqualTo(new[] { "Space Travel" }));
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task NamesWhichDifferOnlyInTheirCaseAreMerged()
|
||||
{
|
||||
using var plugin = await LoadModelPlugin("""
|
||||
CATEGORIES = {"CUSTOM"}
|
||||
CUSTOM_CATEGORIES = {"Space Travel", "space travel", "Deep Space"}
|
||||
""");
|
||||
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(plugin.IsValid, Is.True, string.Join(" ", plugin.Issues));
|
||||
Assert.That(plugin.CustomCategories, Is.EqualTo(new[] { "Space Travel", "Deep Space" }), "The first spelling wins.");
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AnEmptyTableWithoutCustomIsNoIssue()
|
||||
{
|
||||
using var plugin = await LoadModelPlugin("""
|
||||
CATEGORIES = {"BUSINESS"}
|
||||
CUSTOM_CATEGORIES = {}
|
||||
""");
|
||||
|
||||
Assert.That(plugin.IsValid, Is.True, string.Join(" ", plugin.Issues));
|
||||
}
|
||||
|
||||
[TestCase("""CATEGORIES = {"CUSTOM"}""", TestName = "CustomWithoutTheTable")]
|
||||
[TestCase("""
|
||||
CATEGORIES = {"CUSTOM"}
|
||||
CUSTOM_CATEGORIES = {}
|
||||
""", TestName = "CustomWithAnEmptyTable")]
|
||||
[TestCase("""
|
||||
CATEGORIES = {"BUSINESS"}
|
||||
CUSTOM_CATEGORIES = {"Space Travel"}
|
||||
""", TestName = "NamesWithoutCustom")]
|
||||
[TestCase("""
|
||||
CATEGORIES = {"CUSTOM"}
|
||||
CUSTOM_CATEGORIES = {"Space Travel", " "}
|
||||
""", TestName = "AnEmptyName")]
|
||||
[TestCase("""
|
||||
CATEGORIES = {"CUSTOM"}
|
||||
CUSTOM_CATEGORIES = {"Space Travel", 42}
|
||||
""", TestName = "ANameWhichIsNoText")]
|
||||
[TestCase("""
|
||||
CATEGORIES = {"CUSTOM"}
|
||||
CUSTOM_CATEGORIES = "Space Travel"
|
||||
""", TestName = "ANameInsteadOfATable")]
|
||||
public async Task AnIncompleteDeclarationMakesThePluginInvalid(string categoriesLines)
|
||||
{
|
||||
using var plugin = await LoadModelPlugin(categoriesLines);
|
||||
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(plugin.IsValid, Is.False);
|
||||
Assert.That(plugin.Issues, Has.Some.Contains("CUSTOM"));
|
||||
}
|
||||
}
|
||||
|
||||
[TestCase("""CATEGORIES = {"1"}""", TestName = "ANumberIsNoCategory")]
|
||||
[TestCase("""CATEGORIES = {"BUSINESS, SCIENCE"}""", TestName = "TwoNamesInOneAreNoCategory")]
|
||||
[TestCase("""CATEGORIES = {"NONE"}""", TestName = "NoneIsNoCategory")]
|
||||
public async Task OnlyTheNameOfACategoryCounts(string categoriesLine)
|
||||
{
|
||||
using var plugin = await LoadModelPlugin(categoriesLine);
|
||||
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(plugin.IsValid, Is.False, "Enum.TryParse would turn such a value into a category nobody named.");
|
||||
Assert.That(plugin.Issues, Has.Some.Contains("CATEGORIES"));
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TheCaseOfANameDoesNotMatter()
|
||||
{
|
||||
using var plugin = await LoadModelPlugin("""CATEGORIES = {" business "}""");
|
||||
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(plugin.IsValid, Is.True, string.Join(" ", plugin.Issues));
|
||||
Assert.That(plugin.Categories, Is.EqualTo(new[] { PluginCategory.BUSINESS }), "Plugins read names like configuration plugins do.");
|
||||
}
|
||||
}
|
||||
|
||||
[TestCase("""TARGET_GROUPS = {"1"}""", TestName = "ANumberIsNoTargetGroup")]
|
||||
[TestCase("""TARGET_GROUPS = {"EVERYONE, STUDENTS"}""", TestName = "TwoNamesInOneAreNoTargetGroup")]
|
||||
public async Task OnlyTheNameOfATargetGroupCounts(string targetGroupsLine)
|
||||
{
|
||||
using var plugin = await LoadModelPlugin("""CATEGORIES = {"BUSINESS"}""", targetGroupsLine);
|
||||
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(plugin.IsValid, Is.False);
|
||||
Assert.That(plugin.Issues, Has.Some.Contains("TARGET_GROUPS"));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads a model plugin, the plugin type with the fewest fields beyond the ones every plugin has.
|
||||
/// </summary>
|
||||
/// <param name="categoriesLines">The Lua lines which state CATEGORIES and, optionally, CUSTOM_CATEGORIES.</param>
|
||||
/// <param name="targetGroupsLine">The Lua line which states TARGET_GROUPS.</param>
|
||||
private static Task<PluginBase> LoadModelPlugin(string categoriesLines, string targetGroupsLine = """TARGET_GROUPS = {"EVERYONE"}""") => PluginFactory.Load(null, $$"""
|
||||
ID = "{{PLUGIN_ID}}"
|
||||
NAME = "Models for the tests"
|
||||
DESCRIPTION = "A model plugin which declares no models."
|
||||
VERSION = "1.0.0"
|
||||
TYPE = "MODEL"
|
||||
AUTHORS = {"MindWork AI"}
|
||||
SUPPORT_CONTACT = "MindWork AI"
|
||||
SOURCE_URL = "https://github.com/MindWorkAI/AI-Studio"
|
||||
{{categoriesLines}}
|
||||
{{targetGroupsLine}}
|
||||
IS_MAINTAINED = true
|
||||
DEPRECATION_MESSAGE = ""
|
||||
MODELS = {}
|
||||
""");
|
||||
}
|
||||
@@ -116,7 +116,7 @@ public sealed class PluginLastChangedTests
|
||||
""");
|
||||
|
||||
private static DirectChatLauncherPluginMetadata CreateLauncherMetadata(DateTimeOffset? lastChanged) => new(PLUGIN_ID, "1.0.0", lastChanged, ["MindWork AI"], "MindWork AI",
|
||||
"https://github.com/MindWorkAI/AI-Studio", [PluginCategory.CORE], [PluginTargetGroup.EVERYONE], IsMaintained: true, DeprecationMessage: string.Empty, IsAssistantBuilderGenerated: false);
|
||||
"https://github.com/MindWorkAI/AI-Studio", [PluginCategory.CORE], [], [PluginTargetGroup.EVERYONE], IsMaintained: true, DeprecationMessage: string.Empty, IsAssistantBuilderGenerated: false);
|
||||
|
||||
private static DirectChatLauncherDefinition CreateLauncherDefinition() => new("Launcher for the tests", "Launcher for the tests", "Opens a disappearing chat.", new AssistantChatLaunchConfiguration(string.Empty, null, null, null, null, null));
|
||||
}
|
||||
Reference in new issue
Block a user