mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-11-04 14:27:21 +00:00
Added profile, provider, and workspace preselection to chat templates (#1099)
Co-authored-by: Thorsten Sommer <SommerEngineering@users.noreply.github.com>
This commit is contained in:
1 parent
ab9df99cf0
commit
24c4c31035
34 files changed
+2084
-142
No files matched your search
@@ -118,6 +118,9 @@ public sealed class ConfigurationSnippetImportTests : ToolRegistryTestBase
|
||||
Assert.That(imported.DataSourceOptions!.AutomaticDataSourceSelection, Is.EqualTo(template.DataSourceOptions!.AutomaticDataSourceSelection));
|
||||
Assert.That(imported.DataSourceOptions.AutomaticValidation, Is.EqualTo(template.DataSourceOptions.AutomaticValidation));
|
||||
Assert.That(imported.DataSourceOptions.PreselectedDataSourceIds, Is.EqualTo(template.DataSourceOptions.PreselectedDataSourceIds));
|
||||
Assert.That(imported.ProviderId, Is.EqualTo(template.ProviderId));
|
||||
Assert.That(imported.ProfileId, Is.EqualTo(template.ProfileId));
|
||||
Assert.That(imported.WorkspaceName, Is.EqualTo(template.WorkspaceName));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -417,14 +420,66 @@ public sealed class ConfigurationSnippetImportTests : ToolRegistryTestBase
|
||||
public async Task MissingReferencesOfAChatTemplateAreNamed()
|
||||
{
|
||||
var missingDataSourceId = Guid.NewGuid().ToString();
|
||||
var snippet = ExportChatTemplate([], toolIds: [TOOL_ID, "missing_tool"], dataSourceIds: [missingDataSourceId]);
|
||||
var missingProviderId = Guid.NewGuid().ToString();
|
||||
var missingProfileId = Guid.NewGuid().ToString();
|
||||
var snippet = ExportChatTemplate([], toolIds: [TOOL_ID, "missing_tool"], dataSourceIds: [missingDataSourceId], providerId: missingProviderId, profileId: missingProfileId);
|
||||
var result = await ConfigurationSnippetImport.ResolveReferencesAsync(Import(snippet, PluginConfigurationObjectType.CHAT_TEMPLATE), this.SettingsManager, this.CreateRegistry(new TestTool(Definition())));
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(result.Hints, Has.Count.EqualTo(2), "One sentence for each kind of reference.");
|
||||
Assert.That(result.Hints, Has.Count.EqualTo(4), "One sentence for each kind of reference.");
|
||||
Assert.That(result.Hints, Has.Exactly(1).Contains(missingDataSourceId));
|
||||
Assert.That(result.Hints, Has.Exactly(1).Contains("missing_tool"));
|
||||
Assert.That(result.Hints, Has.Exactly(1).Contains(missingProviderId));
|
||||
Assert.That(result.Hints, Has.Exactly(1).Contains(missingProfileId));
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AChatTemplateWhichStartsWithoutAProfileNamesNothingMissing()
|
||||
{
|
||||
var snippet = ExportChatTemplate([], profileId: Profile.NO_PROFILE.Id);
|
||||
var result = await ConfigurationSnippetImport.ResolveReferencesAsync(Import(snippet, PluginConfigurationObjectType.CHAT_TEMPLATE), this.SettingsManager, this.CreateRegistry(new TestTool(Definition())));
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(result.Hints, Is.Empty, "Starting without a profile is a statement, not a reference to a profile which could be missing.");
|
||||
Assert.That(((ChatTemplate)result.ConfigurationObject).ProfileId, Is.EqualTo(Profile.NO_PROFILE.Id));
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AProviderBelowTheConfidenceOfTheChatIsNamed()
|
||||
{
|
||||
// A chat template names its provider by a GUID, as every provider of the app has one:
|
||||
var provider = LessTrustedProvider() with { Id = Guid.NewGuid().ToString() };
|
||||
this.SettingsManager.ConfigurationData.Providers.Add(provider);
|
||||
this.SettingsManager.ConfigurationData.Confidence.EnforceGlobalMinimumConfidence = true;
|
||||
this.SettingsManager.ConfigurationData.Confidence.GlobalMinimumConfidence = ConfidenceLevel.HIGH;
|
||||
|
||||
var snippet = ExportChatTemplate([], providerId: provider.Id);
|
||||
var result = await ConfigurationSnippetImport.ResolveReferencesAsync(Import(snippet, PluginConfigurationObjectType.CHAT_TEMPLATE), this.SettingsManager, this.CreateRegistry(new TestTool(Definition())));
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(result.Hints, Has.Count.EqualTo(1), "The provider exists, but chats started with the template would not use it.");
|
||||
Assert.That(result.Hints, Has.Exactly(1).Contains(provider.InstanceName));
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AProfileOfATemplateWhichForbidsProfilesIsNamed()
|
||||
{
|
||||
var missingProfileId = Guid.NewGuid().ToString();
|
||||
var template = ChatTemplateWith([], null, null, profileId: missingProfileId) with { AllowProfileUsage = false };
|
||||
Assert.That(template.TryExportAsConfigurationSection(out var snippet, out var issue), Is.True, issue);
|
||||
|
||||
var result = await ConfigurationSnippetImport.ResolveReferencesAsync(Import(snippet, PluginConfigurationObjectType.CHAT_TEMPLATE), this.SettingsManager, this.CreateRegistry(new TestTool(Definition())));
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(result.Hints, Has.Count.EqualTo(1), "Whether the profile exists does not matter, since chats ignore it anyway.");
|
||||
Assert.That(result.Hints, Has.None.Contains(missingProfileId));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -440,7 +495,7 @@ public sealed class ConfigurationSnippetImportTests : ToolRegistryTestBase
|
||||
var registry = this.CreateRegistry(new TestTool(Definition()));
|
||||
|
||||
var policy = await ConfigurationSnippetImport.ResolveReferencesAsync(Import(ExportPolicy(provider.Id, profile.Id, [TOOL_ID]), PluginConfigurationObjectType.DOCUMENT_ANALYSIS_POLICY), this.SettingsManager, registry);
|
||||
var template = await ConfigurationSnippetImport.ResolveReferencesAsync(Import(ExportChatTemplate([], [TOOL_ID], [dataSource.Id]), PluginConfigurationObjectType.CHAT_TEMPLATE), this.SettingsManager, registry);
|
||||
var template = await ConfigurationSnippetImport.ResolveReferencesAsync(Import(ExportChatTemplate([], [TOOL_ID], [dataSource.Id], provider.Id, profile.Id), PluginConfigurationObjectType.CHAT_TEMPLATE), this.SettingsManager, registry);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
@@ -589,7 +644,7 @@ public sealed class ConfigurationSnippetImportTests : ToolRegistryTestBase
|
||||
return (profile, profile.ExportAsConfigurationSection());
|
||||
|
||||
case PluginConfigurationObjectType.CHAT_TEMPLATE:
|
||||
var template = ChatTemplateWith([], ["web_search"], [Guid.NewGuid().ToString()]);
|
||||
var template = ChatTemplateWith([], ["web_search"], [Guid.NewGuid().ToString()], Guid.NewGuid().ToString(), Guid.NewGuid().ToString()) with { WorkspaceName = "Contracts" };
|
||||
Assert.That(template.TryExportAsConfigurationSection(out var luaCode, out var issue), Is.True, issue);
|
||||
return (template, luaCode);
|
||||
|
||||
@@ -677,14 +732,14 @@ public sealed class ConfigurationSnippetImportTests : ToolRegistryTestBase
|
||||
return (dataSource, dataSource.ExportAsConfigurationSection(encryptedSecret, usernamePasswordMode));
|
||||
}
|
||||
|
||||
private static string ExportChatTemplate(IReadOnlyList<string> attachmentPaths, IReadOnlyList<string>? toolIds = null, IReadOnlyList<string>? dataSourceIds = null)
|
||||
private static string ExportChatTemplate(IReadOnlyList<string> attachmentPaths, IReadOnlyList<string>? toolIds = null, IReadOnlyList<string>? dataSourceIds = null, string? providerId = null, string? profileId = null)
|
||||
{
|
||||
var template = ChatTemplateWith(attachmentPaths, toolIds, dataSourceIds);
|
||||
var template = ChatTemplateWith(attachmentPaths, toolIds, dataSourceIds, providerId, profileId);
|
||||
Assert.That(template.TryExportAsConfigurationSection(out var luaCode, out var issue), Is.True, issue);
|
||||
return luaCode;
|
||||
}
|
||||
|
||||
private static ChatTemplate ChatTemplateWith(IReadOnlyList<string> attachmentPaths, IReadOnlyList<string>? toolIds, IReadOnlyList<string>? dataSourceIds) => new()
|
||||
private static ChatTemplate ChatTemplateWith(IReadOnlyList<string> attachmentPaths, IReadOnlyList<string>? toolIds, IReadOnlyList<string>? dataSourceIds, string? providerId = null, string? profileId = null) => new()
|
||||
{
|
||||
Num = 1,
|
||||
Id = Guid.NewGuid().ToString(),
|
||||
@@ -700,6 +755,8 @@ public sealed class ConfigurationSnippetImportTests : ToolRegistryTestBase
|
||||
],
|
||||
ToolIds = toolIds?.ToHashSet(StringComparer.Ordinal),
|
||||
DataSourceOptions = dataSourceIds is null ? null : new() { DisableDataSources = false, AutomaticValidation = true, PreselectedDataSourceIds = [..dataSourceIds] },
|
||||
ProviderId = providerId,
|
||||
ProfileId = profileId,
|
||||
};
|
||||
|
||||
private static string ExportPolicy(string preselectedProvider = "", string preselectedProfile = "", IReadOnlyList<string>? allowedToolIds = null) => PolicyWith(preselectedProvider, preselectedProfile, allowedToolIds ?? []).ExportAsConfigurationSection();
|
||||
|
||||
@@ -270,8 +270,12 @@ public sealed class ConfigurationSnippetParserTests
|
||||
],
|
||||
ToolIds = ["web_search"],
|
||||
|
||||
// Preselected data sources make the export start with a comment:
|
||||
// Preselected data sources make the export start with a comment, and so do a preselected
|
||||
// provider and profile, with a comment of their own:
|
||||
DataSourceOptions = new() { DisableDataSources = false, PreselectedDataSourceIds = [Guid.NewGuid().ToString()] },
|
||||
ProviderId = Guid.NewGuid().ToString(),
|
||||
ProfileId = Guid.NewGuid().ToString(),
|
||||
WorkspaceName = QUOTED_TEXT,
|
||||
};
|
||||
|
||||
Assert.That(template.TryExportAsConfigurationSection(out var luaCode, out var issue), Is.True, issue);
|
||||
|
||||
Reference in new issue
Block a user