mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-11-04 21: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
@@ -79,6 +79,25 @@ public partial class ChatTemplateDialog : MSGComponentBase
|
||||
[Parameter]
|
||||
public DataSourceOptions? DataSourceOptions { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The profile this template preselects, the ID of the no-profile entry to start without one,
|
||||
/// or null when it says nothing about profiles.
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public string? ProfileId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The provider this template preselects, or null when it says nothing about providers.
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public string? ProviderId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The name of the workspace this template keeps its chats in, or null when it says nothing about workspaces.
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public string? WorkspaceName { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public bool CreateFromExistingChatThread { get; set; }
|
||||
|
||||
@@ -105,6 +124,12 @@ public partial class ChatTemplateDialog : MSGComponentBase
|
||||
private HashSet<string> selectedToolIds = new(StringComparer.Ordinal);
|
||||
private bool preselectDataSources;
|
||||
private DataSourceOptions templateDataSourceOptions = new();
|
||||
private bool preselectProfile;
|
||||
private string selectedProfileId = Profile.NO_PROFILE.Id;
|
||||
private bool preselectProvider;
|
||||
private string selectedProviderId = string.Empty;
|
||||
private bool preselectWorkspace;
|
||||
private string selectedWorkspaceName = string.Empty;
|
||||
private string[] dataIssues = [];
|
||||
private string dataEditingPreviousName = string.Empty;
|
||||
private bool isInlineEditOnGoing;
|
||||
@@ -138,6 +163,14 @@ public partial class ChatTemplateDialog : MSGComponentBase
|
||||
// them, so the switch inside the selection starts on instead of at its usual default:
|
||||
this.templateDataSourceOptions = this.DataSourceOptions?.CreateCopy() ?? new DataSourceOptions { DisableDataSources = false };
|
||||
|
||||
// The profile and the provider follow the same pattern, with a switch each:
|
||||
this.preselectProfile = this.ProfileId is not null;
|
||||
this.selectedProfileId = this.ProfileId ?? Profile.NO_PROFILE.Id;
|
||||
this.preselectProvider = this.ProviderId is not null;
|
||||
this.selectedProviderId = this.ProviderId ?? string.Empty;
|
||||
this.preselectWorkspace = this.WorkspaceName is not null;
|
||||
this.selectedWorkspaceName = this.WorkspaceName ?? string.Empty;
|
||||
|
||||
// When editing, we need to load the data:
|
||||
if(this.IsEditing)
|
||||
this.dataEditingPreviousName = this.DataName.ToLowerInvariant();
|
||||
@@ -183,6 +216,11 @@ public partial class ChatTemplateDialog : MSGComponentBase
|
||||
ToolIds = this.preselectTools ? new HashSet<string>(this.selectedToolIds, StringComparer.Ordinal) : null,
|
||||
DataSourceOptions = this.preselectDataSources ? this.templateDataSourceOptions.CreateCopy() : null,
|
||||
|
||||
// A template which forbids profiles has no use for a profile, so none is kept for it:
|
||||
ProfileId = this.AllowProfileUsage && this.preselectProfile ? this.selectedProfileId : null,
|
||||
ProviderId = this.preselectProvider && !string.IsNullOrWhiteSpace(this.selectedProviderId) ? this.selectedProviderId : null,
|
||||
WorkspaceName = this.preselectWorkspace && !string.IsNullOrWhiteSpace(this.selectedWorkspaceName) ? this.selectedWorkspaceName.Trim() : null,
|
||||
|
||||
EnterpriseConfigurationPluginId = Guid.Empty,
|
||||
IsEnterpriseConfiguration = false,
|
||||
};
|
||||
@@ -205,6 +243,57 @@ public partial class ChatTemplateDialog : MSGComponentBase
|
||||
|
||||
private void SetSelectedToolIds(HashSet<string> toolIds) => this.selectedToolIds = toolIds;
|
||||
|
||||
/// <summary>
|
||||
/// Whether the preselected profile is gone, so that chats started with this template keep their usual profile.
|
||||
/// </summary>
|
||||
private bool IsPreselectedProfileMissing => this.preselectProfile
|
||||
&& this.selectedProfileId != Profile.NO_PROFILE.Id
|
||||
&& this.SettingsManager.GetProfileById(this.selectedProfileId) == Profile.NO_PROFILE;
|
||||
|
||||
/// <summary>
|
||||
/// Whether the preselected provider is gone or may not be used for chats, so that chats started
|
||||
/// with this template keep their usual provider.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The list to pick from holds only the providers which may be used for chats. A template from
|
||||
/// another machine or from a configuration plugin may name another one, though, and the list
|
||||
/// alone would then show nothing about it.
|
||||
/// </remarks>
|
||||
private bool IsPreselectedProviderUnusable => this.preselectProvider
|
||||
&& !string.IsNullOrWhiteSpace(this.selectedProviderId)
|
||||
&& this.SettingsManager.GetChatTemplateProvider(this.selectedProviderId) == AIStudio.Settings.Provider.NONE;
|
||||
|
||||
/// <summary>
|
||||
/// Whether workspaces are switched off, so that a workspace of this template has no effect for now.
|
||||
/// </summary>
|
||||
private bool AreWorkspacesDisabled => this.SettingsManager.ConfigurationData.Workspace.StorageBehavior is WorkspaceStorageBehavior.DISABLE_WORKSPACES;
|
||||
|
||||
/// <summary>
|
||||
/// Whether the workspace of this template can be changed right now.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Not while workspaces are switched off: a choice made then would take effect for no chat,
|
||||
/// and nothing in the chat would say so. A workspace the template already names stays as it
|
||||
/// is, so it applies again once workspaces are back.
|
||||
/// </remarks>
|
||||
private bool IsWorkspaceChoiceLocked => this.IsReadOnly || this.AreWorkspacesDisabled;
|
||||
|
||||
private string? ValidateWorkspaceName(string workspaceName)
|
||||
{
|
||||
if (this.preselectWorkspace && string.IsNullOrWhiteSpace(workspaceName))
|
||||
return T("Please enter the workspace for the chats of this template, or switch the preselection off.");
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private string? ValidatePreselectedProvider(string providerId)
|
||||
{
|
||||
if (this.preselectProvider && string.IsNullOrWhiteSpace(providerId))
|
||||
return T("Please choose the provider this chat template preselects, or switch the preselection off.");
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private void RemoveMessage(ContentBlock item)
|
||||
{
|
||||
if (this.IsReadOnly)
|
||||
|
||||
Reference in new issue
Block a user