mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-10-06 14:49:40 +00:00
Let chat templates preselect tools and data sources (#995)
This commit is contained in:
1 parent
c95cc5bacc
commit
559f3f7fa6
20 files changed
+1374
-83
No files matched your search
@@ -69,6 +69,8 @@ public partial class SettingsDialogChatTemplate : SettingsDialogBase
|
||||
{ x => x.ExampleConversation, chatTemplate.ExampleConversation },
|
||||
{ x => x.FileAttachments, chatTemplate.FileAttachments },
|
||||
{ x => x.AllowProfileUsage, chatTemplate.AllowProfileUsage },
|
||||
{ x => x.ToolIds, chatTemplate.ToolIds },
|
||||
{ x => x.DataSourceOptions, chatTemplate.DataSourceOptions },
|
||||
};
|
||||
|
||||
var dialogReference = await this.DialogService.ShowAsync<ChatTemplateDialog>(T("Edit Chat Template"), dialogParameters, DialogOptions.FULLSCREEN);
|
||||
@@ -97,6 +99,8 @@ public partial class SettingsDialogChatTemplate : SettingsDialogBase
|
||||
{ x => x.ExampleConversation, chatTemplate.ExampleConversation },
|
||||
{ x => x.FileAttachments, chatTemplate.FileAttachments },
|
||||
{ x => x.AllowProfileUsage, chatTemplate.AllowProfileUsage },
|
||||
{ x => x.ToolIds, chatTemplate.ToolIds },
|
||||
{ x => x.DataSourceOptions, chatTemplate.DataSourceOptions },
|
||||
};
|
||||
|
||||
await this.DialogService.ShowAsync<ChatTemplateDialog>(T("View Chat Template"), dialogParameters, DialogOptions.FULLSCREEN);
|
||||
@@ -128,6 +132,9 @@ public partial class SettingsDialogChatTemplate : SettingsDialogBase
|
||||
if (chatTemplate == ChatTemplate.NO_CHAT_TEMPLATE || chatTemplate.IsEnterpriseConfiguration)
|
||||
return;
|
||||
|
||||
if (!await this.ConfirmExportOfLocalDataSources(chatTemplate))
|
||||
return;
|
||||
|
||||
await this.CopyChatTemplateLuaToClipboard(chatTemplate);
|
||||
}
|
||||
|
||||
@@ -141,10 +148,14 @@ public partial class SettingsDialogChatTemplate : SettingsDialogBase
|
||||
|
||||
if (chatTemplate.FileAttachments.Count == 0)
|
||||
{
|
||||
// That way asks about the local data sources itself, so we must not ask twice:
|
||||
await this.ExportChatTemplateWithSharedAttachmentPaths(chatTemplate);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!await this.ConfirmExportOfLocalDataSources(chatTemplate))
|
||||
return;
|
||||
|
||||
this.isPluginDirectoryDialogOpen = true;
|
||||
try
|
||||
{
|
||||
@@ -160,6 +171,35 @@ public partial class SettingsDialogChatTemplate : SettingsDialogBase
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Asks whether to export a template although it preselects data sources of this machine.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The export writes the preselected data source IDs unchanged, which is what makes a template
|
||||
/// usable across an organization — but a local file or folder exists here and nowhere else, so
|
||||
/// its ID points at nothing on the machine reading the plugin. Nothing breaks, the chat simply
|
||||
/// starts without that source, and that is precisely why it has to be said beforehand: nobody
|
||||
/// would notice it afterwards. Exporting anyway is a fair choice, because the rest of the
|
||||
/// template is worth rolling out.
|
||||
/// </remarks>
|
||||
/// <param name="chatTemplate">The chat template about to be exported.</param>
|
||||
/// <returns>True when the export may go ahead.</returns>
|
||||
private async Task<bool> ConfirmExportOfLocalDataSources(ChatTemplate chatTemplate)
|
||||
{
|
||||
var localDataSourceNames = ChatTemplate.GetPreselectedLocalDataSourceNames(chatTemplate, this.SettingsManager.ConfigurationData.DataSources);
|
||||
if (localDataSourceNames.Count == 0)
|
||||
return true;
|
||||
|
||||
var dialogParameters = new DialogParameters<ConfirmDialog>
|
||||
{
|
||||
{ x => x.Message, string.Format(T("This chat template preselects data sources which exist on this machine only: {0}. They cannot be rolled out, so a chat started with this template elsewhere begins without them. Do you want to export the template anyway?"), string.Join(", ", localDataSourceNames)) },
|
||||
};
|
||||
|
||||
var dialogReference = await this.DialogService.ShowAsync<ConfirmDialog>(T("Export Chat Template"), dialogParameters, DialogOptions.FULLSCREEN);
|
||||
var dialogResult = await dialogReference.Result;
|
||||
return dialogResult is { Canceled: false };
|
||||
}
|
||||
|
||||
private async Task CopyChatTemplateLuaToClipboard(ChatTemplate chatTemplate)
|
||||
{
|
||||
if (!chatTemplate.TryExportAsConfigurationSection(out var luaCode, out var issue))
|
||||
|
||||
Reference in new issue
Block a user