mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-10-17 10:57:59 +00:00
Added importing of configurations exported from AI Studio (#1007)
Co-authored-by: Thorsten Sommer <SommerEngineering@users.noreply.github.com>
This commit is contained in:
1 parent
f8c0232cfd
commit
22065783c2
49 files changed
+3257
-263
No files matched your search
@@ -94,6 +94,33 @@
|
||||
<MudJustifiedText Class="mb-3" Typo="Typo.body1">
|
||||
@T("You can attach files that will be automatically included when using this chat template. These files will be added to the first message sent in any chat using this template.")
|
||||
</MudJustifiedText>
|
||||
@if (!this.IsEditing && !this.IsReadOnly)
|
||||
{
|
||||
@if (this.HasUnresolvedAttachments)
|
||||
{
|
||||
<MudAlert Severity="Severity.Warning" Variant="Variant.Filled" Icon="@Icons.Material.Filled.WarningAmber" Class="mb-3">
|
||||
@T("Some attachments of this chat template are not on this computer. Please relink or remove them before you add the template.")
|
||||
</MudAlert>
|
||||
}
|
||||
@if (!string.IsNullOrWhiteSpace(this.relinkIssue))
|
||||
{
|
||||
<MudAlert Severity="Severity.Error" Class="mb-2">@this.relinkIssue</MudAlert>
|
||||
}
|
||||
@for (var index = 0; index < this.attachmentsToRelink.Count; index++)
|
||||
{
|
||||
var currentIndex = index;
|
||||
var attachment = this.attachmentsToRelink[index];
|
||||
<MudStack Row="true" AlignItems="AlignItems.Center" Class="mb-2">
|
||||
<MudTextField T="string" Value="@attachment.ReplacementPath"
|
||||
ValueChanged="@(value => this.UpdateRelinkPath(currentIndex, value))"
|
||||
Label="@string.Format(T("Relink attachment: {0}"), attachment.OriginalPath)"
|
||||
HelperText="@T("Enter the full path of a file on this computer, or remove the attachment.")" Variant="Variant.Outlined" Immediate="@true" />
|
||||
<MudTooltip Text="@T("Remove this attachment")">
|
||||
<MudIconButton Icon="@Icons.Material.Filled.Delete" Color="Color.Error" OnClick="@(() => this.RemoveAttachmentToRelink(currentIndex))" />
|
||||
</MudTooltip>
|
||||
</MudStack>
|
||||
}
|
||||
}
|
||||
<AttachDocuments
|
||||
Name="ChatTemplateFileAttachments"
|
||||
@bind-DocumentPaths="@this.fileAttachments"
|
||||
@@ -252,7 +279,7 @@
|
||||
|
||||
@if (!this.isInlineEditOnGoing)
|
||||
{
|
||||
<MudButton OnClick="@this.Store" Variant="Variant.Filled" Color="Color.Primary">
|
||||
<MudButton OnClick="@this.Store" Variant="Variant.Filled" Color="Color.Primary" Disabled="@this.HasUnresolvedAttachments">
|
||||
@if (this.IsEditing)
|
||||
{
|
||||
@T("Update")
|
||||
|
||||
@@ -57,6 +57,13 @@ public partial class ChatTemplateDialog : MSGComponentBase
|
||||
[Parameter]
|
||||
public IReadOnlyCollection<FileAttachment> FileAttachments { get; init; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// The attachments of an imported chat template which are not on this computer, as the
|
||||
/// configuration snippet names them. The user relinks or removes each one before saving.
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public IReadOnlyList<string> AttachmentsToRelink { get; init; } = [];
|
||||
|
||||
[Parameter]
|
||||
public bool AllowProfileUsage { get; set; } = true;
|
||||
|
||||
@@ -91,6 +98,9 @@ public partial class ChatTemplateDialog : MSGComponentBase
|
||||
private bool dataIsValid;
|
||||
private List<ContentBlock> dataExampleConversation = [];
|
||||
private HashSet<FileAttachment> fileAttachments = [];
|
||||
private List<(string OriginalPath, string ReplacementPath)> attachmentsToRelink = [];
|
||||
private string relinkIssue = string.Empty;
|
||||
private bool HasUnresolvedAttachments => this.attachmentsToRelink.Any(attachment => !IsExistingFile(attachment.ReplacementPath));
|
||||
private bool preselectTools;
|
||||
private HashSet<string> selectedToolIds = new(StringComparer.Ordinal);
|
||||
private bool preselectDataSources;
|
||||
@@ -130,11 +140,12 @@ public partial class ChatTemplateDialog : MSGComponentBase
|
||||
|
||||
// When editing, we need to load the data:
|
||||
if(this.IsEditing)
|
||||
{
|
||||
this.dataEditingPreviousName = this.DataName.ToLowerInvariant();
|
||||
this.dataExampleConversation = this.ExampleConversation.Select(n => n.DeepClone()).ToList();
|
||||
this.fileAttachments = [..this.FileAttachments];
|
||||
}
|
||||
|
||||
// An edited template brings its conversation and attachments along, and so does an imported one:
|
||||
this.dataExampleConversation = this.ExampleConversation.Select(n => n.DeepClone()).ToList();
|
||||
this.fileAttachments = [..this.FileAttachments];
|
||||
this.attachmentsToRelink = this.AttachmentsToRelink.Select(path => (path, string.Empty)).ToList();
|
||||
|
||||
if (this.CreateFromExistingChatThread && this.ExistingChatThread is not null)
|
||||
{
|
||||
@@ -176,6 +187,22 @@ public partial class ChatTemplateDialog : MSGComponentBase
|
||||
IsEnterpriseConfiguration = false,
|
||||
};
|
||||
|
||||
private static bool IsExistingFile(string path) => Path.IsPathFullyQualified(path) && File.Exists(path);
|
||||
|
||||
private void UpdateRelinkPath(int index, string? path)
|
||||
{
|
||||
this.attachmentsToRelink[index] = (this.attachmentsToRelink[index].OriginalPath, path ?? string.Empty);
|
||||
if (!this.HasUnresolvedAttachments)
|
||||
this.relinkIssue = string.Empty;
|
||||
}
|
||||
|
||||
private void RemoveAttachmentToRelink(int index)
|
||||
{
|
||||
this.attachmentsToRelink.RemoveAt(index);
|
||||
if (!this.HasUnresolvedAttachments)
|
||||
this.relinkIssue = string.Empty;
|
||||
}
|
||||
|
||||
private void SetSelectedToolIds(HashSet<string> toolIds) => this.selectedToolIds = toolIds;
|
||||
|
||||
private void RemoveMessage(ContentBlock item)
|
||||
@@ -274,6 +301,18 @@ public partial class ChatTemplateDialog : MSGComponentBase
|
||||
if (this.IsReadOnly)
|
||||
return;
|
||||
|
||||
// Only check the relinked attachments here. They are added right before closing, so that a
|
||||
// failed save does not leave a path behind which the user changes afterward:
|
||||
this.relinkIssue = string.Empty;
|
||||
foreach (var (originalPath, replacementPath) in this.attachmentsToRelink)
|
||||
{
|
||||
if (!IsExistingFile(replacementPath))
|
||||
{
|
||||
this.relinkIssue = string.Format(T("Please relink the attachment '{0}' to a file on this computer or remove it before you save."), originalPath);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
await this.form.Validate();
|
||||
|
||||
// When the data is not valid, we don't store it:
|
||||
@@ -284,6 +323,10 @@ public partial class ChatTemplateDialog : MSGComponentBase
|
||||
if (this.isInlineEditOnGoing)
|
||||
return;
|
||||
|
||||
foreach (var (_, replacementPath) in this.attachmentsToRelink)
|
||||
this.fileAttachments.Add(FileAttachment.FromPath(replacementPath));
|
||||
this.attachmentsToRelink.Clear();
|
||||
|
||||
// Use the data model to store the chat template.
|
||||
// We just return this data to the parent component:
|
||||
var addedChatTemplateSettings = this.CreateChatTemplateSettings();
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
@inherits MSGComponentBase
|
||||
|
||||
<MudDialog>
|
||||
<DialogContent>
|
||||
<MudJustifiedText Typo="Typo.body1" Class="mb-3">
|
||||
@T("Paste a configuration which was exported from AI Studio, for example by a colleague. AI Studio only reads its values and never runs the pasted text. You can review and change everything afterward.")
|
||||
</MudJustifiedText>
|
||||
<MudTextField T="string" Text="@this.snippet" TextChanged="@this.SnippetChanged" Immediate="true" Label="@T("Exported configuration")" Lines="6" AutoGrow="true" MaxLines="14" Variant="Variant.Outlined" />
|
||||
@if (!string.IsNullOrWhiteSpace(this.issue))
|
||||
{
|
||||
<MudAlert Severity="Severity.Error" Class="mt-3">@this.issue</MudAlert>
|
||||
}
|
||||
@if (this.importWithHints is not null)
|
||||
{
|
||||
@foreach (var hint in this.importWithHints.Hints)
|
||||
{
|
||||
<MudAlert Severity="Severity.Warning" Variant="Variant.Outlined" Class="mt-3">@hint</MudAlert>
|
||||
}
|
||||
}
|
||||
</DialogContent>
|
||||
<DialogActions>
|
||||
<MudButton OnClick="@this.Cancel">@T("Cancel")</MudButton>
|
||||
@if (this.importWithHints is null)
|
||||
{
|
||||
<MudButton OnClick="@this.Import" Disabled="@string.IsNullOrWhiteSpace(this.snippet)" Color="Color.Primary" Variant="Variant.Filled">@this.ImportLabel</MudButton>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudButton OnClick="@this.ContinueAnyway" Color="Color.Warning" Variant="Variant.Filled">@T("Continue anyway")</MudButton>
|
||||
}
|
||||
</DialogActions>
|
||||
</MudDialog>
|
||||
@@ -0,0 +1,97 @@
|
||||
using AIStudio.Components;
|
||||
using AIStudio.Tools.PluginSystem;
|
||||
using AIStudio.Tools.ToolCallingSystem;
|
||||
|
||||
using Microsoft.AspNetCore.Components;
|
||||
|
||||
namespace AIStudio.Dialogs;
|
||||
|
||||
public partial class ConfigurationSnippetImportDialog : MSGComponentBase
|
||||
{
|
||||
[CascadingParameter]
|
||||
private IMudDialogInstance MudDialog { get; set; } = null!;
|
||||
|
||||
[Parameter]
|
||||
public PluginConfigurationObjectType Type { get; set; } = PluginConfigurationObjectType.NONE;
|
||||
|
||||
[Parameter]
|
||||
public string ImportLabel { get; set; } = string.Empty;
|
||||
|
||||
[Inject]
|
||||
private ToolRegistry ToolRegistry { get; init; } = null!;
|
||||
|
||||
private string snippet = string.Empty;
|
||||
private string issue = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// What the snippet imports, while the user still has to read its hints.
|
||||
/// </summary>
|
||||
private ConfigurationSnippetImportResult? importWithHints;
|
||||
|
||||
private void SnippetChanged(string text)
|
||||
{
|
||||
// The issue and the hints belong to the snippet they were found in:
|
||||
this.snippet = text;
|
||||
this.issue = string.Empty;
|
||||
this.importWithHints = null;
|
||||
}
|
||||
|
||||
private async Task Import()
|
||||
{
|
||||
if (!ConfigurationSnippetImport.TryImport(this.snippet, this.Type, out var imported, out this.issue))
|
||||
return;
|
||||
|
||||
imported = await ConfigurationSnippetImport.ResolveReferencesAsync(imported, this.SettingsManager, this.ToolRegistry);
|
||||
if (imported.Hints.Count > 0)
|
||||
{
|
||||
this.importWithHints = imported;
|
||||
return;
|
||||
}
|
||||
|
||||
this.Close(imported);
|
||||
}
|
||||
|
||||
private void ContinueAnyway()
|
||||
{
|
||||
if (this.importWithHints is not null)
|
||||
this.Close(this.importWithHints);
|
||||
}
|
||||
|
||||
private void Close(ConfigurationSnippetImportResult imported)
|
||||
{
|
||||
//
|
||||
// An organization can lock the import at any time, e.g., with a new version of its
|
||||
// configuration plugin, and the user may take a while to read the hints. Hence, the
|
||||
// permission is checked when the dialog hands over the imported object:
|
||||
//
|
||||
if (!this.SettingsManager.ConfigurationData.App.CanImportConfigurationSnippet(this.Type))
|
||||
{
|
||||
this.issue = T("Your organization does not allow importing this type of configuration.");
|
||||
this.importWithHints = null;
|
||||
return;
|
||||
}
|
||||
|
||||
this.MudDialog.Close(DialogResult.Ok(imported));
|
||||
}
|
||||
|
||||
private void Cancel() => this.MudDialog.Cancel();
|
||||
|
||||
/// <summary>
|
||||
/// Lets the user paste a configuration snippet and imports it as an object of the user's own.
|
||||
/// </summary>
|
||||
/// <param name="service">The dialog service.</param>
|
||||
/// <param name="type">The type of configuration object to import.</param>
|
||||
/// <param name="title">The title of the dialog, which also labels its import button.</param>
|
||||
/// <returns>The imported object, or null when the user canceled.</returns>
|
||||
public static async Task<ConfigurationSnippetImportResult?> ShowAsync(IDialogService service, PluginConfigurationObjectType type, string title)
|
||||
{
|
||||
var parameters = new DialogParameters<ConfigurationSnippetImportDialog>
|
||||
{
|
||||
{ x => x.Type, type },
|
||||
{ x => x.ImportLabel, title },
|
||||
};
|
||||
var dialog = await service.ShowAsync<ConfigurationSnippetImportDialog>(title, parameters, DialogOptions.FULLSCREEN);
|
||||
var result = await dialog.Result;
|
||||
return result is { Canceled: false, Data: ConfigurationSnippetImportResult imported } ? imported : null;
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,10 @@
|
||||
|
||||
<MudDialog>
|
||||
<DialogContent>
|
||||
@if (!string.IsNullOrWhiteSpace(this.importRetrievalIssue))
|
||||
{
|
||||
<MudAlert Severity="Severity.Warning" Class="mb-2">@this.importRetrievalIssue</MudAlert>
|
||||
}
|
||||
<MudForm @ref="@this.form" @bind-IsValid="@this.dataIsValid" @bind-Errors="@this.dataIssues">
|
||||
@* ReSharper disable once CSharpWarnings::CS8974 *@
|
||||
<MudTextField
|
||||
@@ -102,7 +106,7 @@
|
||||
|
||||
@if (this.availableRetrievalProcesses.Count > 0)
|
||||
{
|
||||
<MudSelect @bind-Value="@this.dataSelectedRetrievalProcess" Text="@this.dataSelectedRetrievalProcess.Name" Label="@T("Select one retrieval process")" Class="mb-3" OpenIcon="@Icons.Material.Filled.ExpandMore" AdornmentColor="Color.Info" Adornment="Adornment.Start" Validation="@this.dataSourceValidation.ValidateRetrievalProcess">
|
||||
<MudSelect @bind-Value="@this.dataSelectedRetrievalProcess" @bind-Value:after="@this.ClearImportRetrievalIssue" Text="@this.dataSelectedRetrievalProcess.Name" Label="@T("Select one retrieval process")" Class="mb-3" OpenIcon="@Icons.Material.Filled.ExpandMore" AdornmentColor="Color.Info" Adornment="Adornment.Start" Validation="@this.dataSourceValidation.ValidateRetrievalProcess">
|
||||
@foreach (var retrievalProcess in this.availableRetrievalProcesses)
|
||||
{
|
||||
<MudSelectItem Value="@retrievalProcess">
|
||||
|
||||
@@ -23,7 +23,20 @@ public partial class DataSourceERI_V1Dialog : MSGComponentBase, ISecretId
|
||||
|
||||
[Parameter]
|
||||
public DataSourceERI_V1 DataSource { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Whether the data source was imported. It then fills the form like an edited one, but the
|
||||
/// dialog does not connect to its server before the user tests the connection.
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public bool IsImport { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The token or password an imported data source brought along.
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public string ImportedSecret { get; set; } = string.Empty;
|
||||
|
||||
[Inject]
|
||||
private ILogger<DataSourceERI_V1Dialog> Logger { get; init; } = null!;
|
||||
|
||||
@@ -43,6 +56,8 @@ public partial class DataSourceERI_V1Dialog : MSGComponentBase, ISecretId
|
||||
private bool dataIsValid;
|
||||
private string[] dataIssues = [];
|
||||
private string dataSecretStorageIssue = string.Empty;
|
||||
private string importRetrievalIssue = string.Empty;
|
||||
private string importedRetrievalId = string.Empty;
|
||||
private string dataEditingPreviousInstanceName = string.Empty;
|
||||
private List<AuthMethod> availableAuthMethods = [];
|
||||
private DataSourceSecurity dataSecurityPolicy;
|
||||
@@ -92,13 +107,12 @@ public partial class DataSourceERI_V1Dialog : MSGComponentBase, ISecretId
|
||||
.Concat(this.SettingsManager.ConfigurationData.Mailboxes.Select(x => x.Name.ToLowerInvariant()))
|
||||
.ToList();
|
||||
|
||||
// When editing, we need to load the data:
|
||||
if(this.IsEditing)
|
||||
// An edited data source fills the form, and so does an imported one:
|
||||
if(this.IsEditing || this.IsImport)
|
||||
{
|
||||
//
|
||||
// Assign the data to the form fields:
|
||||
//
|
||||
this.dataEditingPreviousInstanceName = this.DataSource.Name.ToLowerInvariant();
|
||||
this.dataNum = this.DataSource.Num;
|
||||
this.dataId = this.DataSource.Id;
|
||||
this.dataName = this.DataSource.Name;
|
||||
@@ -114,7 +128,12 @@ public partial class DataSourceERI_V1Dialog : MSGComponentBase, ISecretId
|
||||
// restore the selected retrieval process id. That's why we
|
||||
// assign the selected retrieval id to the default retrieval process:
|
||||
this.dataSelectedRetrievalProcess = this.dataSelectedRetrievalProcess with { Id = this.DataSource.SelectedRetrievalId };
|
||||
}
|
||||
|
||||
// When editing, we need to load the data:
|
||||
if(this.IsEditing)
|
||||
{
|
||||
this.dataEditingPreviousInstanceName = this.DataSource.Name.ToLowerInvariant();
|
||||
if (this.dataAuthMethod is AuthMethod.TOKEN or AuthMethod.USERNAME_PASSWORD)
|
||||
{
|
||||
// Load the secret:
|
||||
@@ -135,7 +154,13 @@ public partial class DataSourceERI_V1Dialog : MSGComponentBase, ISecretId
|
||||
// Select the retrieval process:
|
||||
this.dataSelectedRetrievalProcess = this.availableRetrievalProcesses.FirstOrDefault(n => n.Id == this.DataSource.SelectedRetrievalId);
|
||||
}
|
||||
|
||||
else if (this.IsImport)
|
||||
{
|
||||
// The first connection test, which the user starts, selects the imported retrieval process:
|
||||
this.dataSecret = this.ImportedSecret;
|
||||
this.importedRetrievalId = this.DataSource.SelectedRetrievalId;
|
||||
}
|
||||
|
||||
await base.OnInitializedAsync();
|
||||
}
|
||||
|
||||
@@ -179,6 +204,8 @@ public partial class DataSourceERI_V1Dialog : MSGComponentBase, ISecretId
|
||||
};
|
||||
}
|
||||
|
||||
private void ClearImportRetrievalIssue() => this.importRetrievalIssue = string.Empty;
|
||||
|
||||
private bool IsConnectionEncrypted() => this.dataHostname.StartsWith("https://", StringComparison.InvariantCultureIgnoreCase);
|
||||
|
||||
private bool IsConnectionPossible()
|
||||
@@ -253,7 +280,23 @@ public partial class DataSourceERI_V1Dialog : MSGComponentBase, ISecretId
|
||||
}
|
||||
|
||||
this.availableRetrievalProcesses = retrievalInfoRequest.Data ?? [];
|
||||
|
||||
|
||||
// Only the first successful test after an import resolves the imported retrieval ID;
|
||||
// afterward, the selection belongs to the user:
|
||||
if (!string.IsNullOrWhiteSpace(this.importedRetrievalId))
|
||||
{
|
||||
var importedRetrieval = this.availableRetrievalProcesses.FirstOrDefault(item => item.Id == this.importedRetrievalId);
|
||||
if (importedRetrieval != default)
|
||||
this.dataSelectedRetrievalProcess = importedRetrieval;
|
||||
else
|
||||
{
|
||||
this.importRetrievalIssue = string.Format(T("The server does not offer the imported retrieval process '{0}'. Please select another one before you save."), this.importedRetrievalId);
|
||||
this.dataSelectedRetrievalProcess = default;
|
||||
}
|
||||
|
||||
this.importedRetrievalId = string.Empty;
|
||||
}
|
||||
|
||||
this.connectionTested = true;
|
||||
this.connectionSuccessfulTested = true;
|
||||
this.Logger.LogInformation("Connection to the ERI v1 server was successful tested.");
|
||||
|
||||
@@ -110,6 +110,12 @@ public partial class EmbeddingProviderDialog : MSGComponentBase, ISecretId
|
||||
[Parameter]
|
||||
public bool IsEnterpriseConfiguration { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The API key an imported embedding provider brought along. When editing, the dialog loads the stored key instead.
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public string ImportedAPIKey { get; set; } = string.Empty;
|
||||
|
||||
[Inject]
|
||||
private RustService RustService { get; init; } = null!;
|
||||
|
||||
@@ -204,16 +210,18 @@ public partial class EmbeddingProviderDialog : MSGComponentBase, ISecretId
|
||||
// Load the used instance names:
|
||||
this.UsedInstanceNames = this.SettingsManager.ConfigurationData.EmbeddingProviders.Select(x => x.Name.ToLowerInvariant()).ToList();
|
||||
|
||||
// An edited embedding provider fills the form, and so does an imported one:
|
||||
this.dataFilePath = this.DataTokenizerPath;
|
||||
this.dataTokenizerFingerprint = this.DataTokenizerFingerprint;
|
||||
this.showExpertSettings = !string.IsNullOrWhiteSpace(this.DataTokenizerPath)
|
||||
|| this.DataTokenLimit != EmbeddingProvider.DEFAULT_TOKEN_LIMIT
|
||||
|| this.DataEmbeddingBatchSize != EmbeddingProvider.DEFAULT_EMBEDDING_BATCH_SIZE;
|
||||
|
||||
// When editing, we need to load the data:
|
||||
if(this.IsEditing)
|
||||
{
|
||||
this.dataEditingPreviousInstanceName = this.DataName.ToLowerInvariant();
|
||||
this.dataFilePath = this.DataTokenizerPath;
|
||||
this.dataTokenizerFingerprint = this.DataTokenizerFingerprint;
|
||||
this.showExpertSettings = !string.IsNullOrWhiteSpace(this.DataTokenizerPath)
|
||||
|| this.DataTokenLimit != EmbeddingProvider.DEFAULT_TOKEN_LIMIT
|
||||
|| this.DataEmbeddingBatchSize != EmbeddingProvider.DEFAULT_EMBEDDING_BATCH_SIZE;
|
||||
|
||||
|
||||
// Load the API key. A self-hosted server may well need one: LM Studio can ask for a
|
||||
// token of its own, and any of these servers can sit behind an authenticating proxy.
|
||||
// So we try for every host and treat a missing key as the normal case (isTrying).
|
||||
@@ -239,6 +247,14 @@ public partial class EmbeddingProviderDialog : MSGComponentBase, ISecretId
|
||||
|
||||
await this.ReloadModels();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.dataAPIKey = this.ImportedAPIKey;
|
||||
|
||||
// An import does not contact the server, so its model is the only one to choose until the user loads the models:
|
||||
if (!string.IsNullOrWhiteSpace(this.DataModel.Id))
|
||||
this.availableModels.Add(this.DataModel);
|
||||
}
|
||||
}
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
@@ -603,4 +619,4 @@ public partial class EmbeddingProviderDialog : MSGComponentBase, ISecretId
|
||||
private void ToggleExpertSettings() => this.showExpertSettings = !this.showExpertSettings;
|
||||
|
||||
private string GetExpertStyles => this.showExpertSettings ? "border-2 border-dashed rounded pa-2" : string.Empty;
|
||||
}
|
||||
}
|
||||
@@ -117,7 +117,13 @@ public partial class ProviderDialog : MSGComponentBase, ISecretId
|
||||
|
||||
[Parameter]
|
||||
public ProviderCapabilityOverrides? DataCapabilityOverrides { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The API key an imported provider brought along. When editing, the dialog loads the stored key instead.
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public string ImportedAPIKey { get; set; } = string.Empty;
|
||||
|
||||
[Inject]
|
||||
private RustService RustService { get; init; } = null!;
|
||||
|
||||
@@ -254,16 +260,18 @@ public partial class ProviderDialog : MSGComponentBase, ISecretId
|
||||
|| this.capabilityOverrides.HasOverrides
|
||||
|| (this.ShowTokenizerSettings && !string.IsNullOrWhiteSpace(this.DataTokenizerPath));
|
||||
|
||||
// An edited provider fills the form, and so does an imported one:
|
||||
this.dataFilePath = this.DataTokenizerPath;
|
||||
|
||||
// When using Fireworks, we must copy the model name:
|
||||
if (this.DataLLMProvider.IsLLMModelProvidedManually())
|
||||
this.dataManuallyModel = this.DataModel.Id;
|
||||
|
||||
// When editing, we need to load the data:
|
||||
if(this.IsEditing)
|
||||
{
|
||||
this.dataEditingPreviousInstanceName = this.DataInstanceName.ToLowerInvariant();
|
||||
this.dataFilePath = this.DataTokenizerPath;
|
||||
|
||||
// When using Fireworks, we must copy the model name:
|
||||
if (this.DataLLMProvider.IsLLMModelProvidedManually())
|
||||
this.dataManuallyModel = this.DataModel.Id;
|
||||
|
||||
|
||||
// Load the API key. A self-hosted server may well need one: LM Studio can ask for a
|
||||
// token of its own, and any of these servers can sit behind an authenticating proxy.
|
||||
// So we try for every host and treat a missing key as the normal case (isTrying).
|
||||
@@ -289,6 +297,14 @@ public partial class ProviderDialog : MSGComponentBase, ISecretId
|
||||
|
||||
await this.ReloadModels();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.dataAPIKey = this.ImportedAPIKey;
|
||||
|
||||
// An import does not contact the server, so its model is the only one to choose until the user loads the models:
|
||||
if (!string.IsNullOrWhiteSpace(this.DataModel.Id))
|
||||
this.availableModels.Add(this.DataModel);
|
||||
}
|
||||
}
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
@@ -1053,4 +1069,4 @@ public partial class ProviderDialog : MSGComponentBase, ISecretId
|
||||
"top_p": 0.9,
|
||||
"frequency_penalty": 0.0
|
||||
""";
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
@using AIStudio.Tools.PluginSystem
|
||||
@inherits SettingsDialogBase
|
||||
|
||||
<MudDialog>
|
||||
@@ -81,9 +82,12 @@
|
||||
</MudText>
|
||||
}
|
||||
|
||||
<MudButton Variant="Variant.Filled" Color="@Color.Primary" StartIcon="@Icons.Material.Filled.AddRoad" Class="mt-3 mb-6" OnClick="@this.AddChatTemplate">
|
||||
@T("Add Chat Template")
|
||||
</MudButton>
|
||||
<MudStack Row="true" Wrap="Wrap.Wrap" Class="mt-3 mb-6">
|
||||
<MudButton Variant="Variant.Filled" Color="@Color.Primary" StartIcon="@Icons.Material.Filled.AddRoad" OnClick="@this.AddChatTemplate">
|
||||
@T("Add Chat Template")
|
||||
</MudButton>
|
||||
<LockableButton Text="@T("Import Chat Template")" IsLocked="@(() => !this.SettingsManager.ConfigurationData.App.CanImportConfigurationSnippet(PluginConfigurationObjectType.CHAT_TEMPLATE))" Icon="@Icons.Material.Filled.FileDownload" OnClickAsync="@this.ImportChatTemplate" ButtonVariant="Variant.Outlined" NoMargin="true" />
|
||||
</MudStack>
|
||||
</DialogContent>
|
||||
<DialogActions>
|
||||
<MudButton OnClick="@this.Close" Variant="Variant.Filled">
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using AIStudio.Chat;
|
||||
using AIStudio.Settings;
|
||||
using AIStudio.Tools.PluginSystem;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
|
||||
namespace AIStudio.Dialogs.Settings;
|
||||
@@ -39,11 +40,35 @@ public partial class SettingsDialogChatTemplate : SettingsDialogBase
|
||||
dialogParameters.Add(x => x.ExistingChatThread, this.ExistingChatThread);
|
||||
}
|
||||
|
||||
await this.AddChatTemplate(dialogParameters, isImport: false);
|
||||
}
|
||||
|
||||
private async Task ImportChatTemplate()
|
||||
{
|
||||
var import = await ConfigurationSnippetImportDialog.ShowAsync(this.DialogService, PluginConfigurationObjectType.CHAT_TEMPLATE, T("Import Chat Template"));
|
||||
if (import?.ConfigurationObject is not ChatTemplate chatTemplate)
|
||||
return;
|
||||
|
||||
var dialogParameters = CreateDialogParameters(chatTemplate, isEditing: false);
|
||||
dialogParameters.Add(x => x.AttachmentsToRelink, import.AttachmentsToRelink);
|
||||
await this.AddChatTemplate(dialogParameters, isImport: true);
|
||||
}
|
||||
|
||||
private async Task AddChatTemplate(DialogParameters<ChatTemplateDialog> dialogParameters, bool isImport)
|
||||
{
|
||||
var dialogReference = await this.DialogService.ShowAsync<ChatTemplateDialog>(T("Add Chat Template"), dialogParameters, DialogOptions.FULLSCREEN);
|
||||
var dialogResult = await dialogReference.Result;
|
||||
if (dialogResult is null || dialogResult.Canceled)
|
||||
return;
|
||||
|
||||
//
|
||||
// An organization can lock the import while the user is still filling in the form, e.g.,
|
||||
// with a new version of its configuration plugin. Hence, the permission is checked once
|
||||
// more before the imported chat template is stored:
|
||||
//
|
||||
if (isImport && !this.SettingsManager.ConfigurationData.App.CanImportConfigurationSnippet(PluginConfigurationObjectType.CHAT_TEMPLATE))
|
||||
return;
|
||||
|
||||
var addedChatTemplate = (ChatTemplate)dialogResult.Data!;
|
||||
addedChatTemplate = addedChatTemplate with { Num = this.SettingsManager.ConfigurationData.NextChatTemplateNum++ };
|
||||
|
||||
@@ -58,22 +83,7 @@ public partial class SettingsDialogChatTemplate : SettingsDialogBase
|
||||
if (chatTemplate == ChatTemplate.NO_CHAT_TEMPLATE || chatTemplate.IsEnterpriseConfiguration)
|
||||
return;
|
||||
|
||||
var dialogParameters = new DialogParameters<ChatTemplateDialog>
|
||||
{
|
||||
{ x => x.DataNum, chatTemplate.Num },
|
||||
{ x => x.DataId, chatTemplate.Id },
|
||||
{ x => x.DataName, chatTemplate.Name },
|
||||
{ x => x.DataSystemPrompt, chatTemplate.SystemPrompt },
|
||||
{ x => x.PredefinedUserPrompt, chatTemplate.PredefinedUserPrompt },
|
||||
{ x => x.IsEditing, true },
|
||||
{ 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);
|
||||
var dialogReference = await this.DialogService.ShowAsync<ChatTemplateDialog>(T("Edit Chat Template"), CreateDialogParameters(chatTemplate, isEditing: true), DialogOptions.FULLSCREEN);
|
||||
var dialogResult = await dialogReference.Result;
|
||||
if (dialogResult is null || dialogResult.Canceled)
|
||||
return;
|
||||
@@ -87,25 +97,25 @@ public partial class SettingsDialogChatTemplate : SettingsDialogBase
|
||||
|
||||
private async Task ViewChatTemplate(ChatTemplate chatTemplate)
|
||||
{
|
||||
var dialogParameters = new DialogParameters<ChatTemplateDialog>
|
||||
{
|
||||
{ x => x.DataNum, chatTemplate.Num },
|
||||
{ x => x.DataId, chatTemplate.Id },
|
||||
{ x => x.DataName, chatTemplate.Name },
|
||||
{ x => x.DataSystemPrompt, chatTemplate.SystemPrompt },
|
||||
{ x => x.PredefinedUserPrompt, chatTemplate.PredefinedUserPrompt },
|
||||
{ x => x.IsEditing, true },
|
||||
{ x => x.IsReadOnly, true },
|
||||
{ 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);
|
||||
await this.DialogService.ShowAsync<ChatTemplateDialog>(T("View Chat Template"), CreateDialogParameters(chatTemplate, isEditing: true, isReadOnly: true), DialogOptions.FULLSCREEN);
|
||||
}
|
||||
|
||||
private static DialogParameters<ChatTemplateDialog> CreateDialogParameters(ChatTemplate chatTemplate, bool isEditing, bool isReadOnly = false) => new()
|
||||
{
|
||||
{ x => x.DataNum, chatTemplate.Num },
|
||||
{ x => x.DataId, chatTemplate.Id },
|
||||
{ x => x.DataName, chatTemplate.Name },
|
||||
{ x => x.DataSystemPrompt, chatTemplate.SystemPrompt },
|
||||
{ x => x.PredefinedUserPrompt, chatTemplate.PredefinedUserPrompt },
|
||||
{ x => x.IsEditing, isEditing },
|
||||
{ x => x.IsReadOnly, isReadOnly },
|
||||
{ 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 },
|
||||
};
|
||||
|
||||
private async Task DeleteChatTemplate(ChatTemplate chatTemplate)
|
||||
{
|
||||
var dialogParameters = new DialogParameters<ConfirmDialog>
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
@using AIStudio.Tools.PluginSystem
|
||||
@inherits SettingsDialogBase
|
||||
|
||||
<MudDialog>
|
||||
@@ -64,9 +65,12 @@
|
||||
</MudText>
|
||||
}
|
||||
|
||||
<MudButton Variant="Variant.Filled" Color="@Color.Primary" StartIcon="@Icons.Material.Filled.AddRoad" Class="mt-3 mb-6" OnClick="@this.AddProfile">
|
||||
@T("Add Profile")
|
||||
</MudButton>
|
||||
<MudStack Row="true" Wrap="Wrap.Wrap" Class="mt-3 mb-6">
|
||||
<MudButton Variant="Variant.Filled" Color="@Color.Primary" StartIcon="@Icons.Material.Filled.AddRoad" OnClick="@this.AddProfile">
|
||||
@T("Add Profile")
|
||||
</MudButton>
|
||||
<LockableButton Text="@T("Import Profile")" IsLocked="@(() => !this.SettingsManager.ConfigurationData.App.CanImportConfigurationSnippet(PluginConfigurationObjectType.PROFILE))" Icon="@Icons.Material.Filled.FileDownload" OnClickAsync="@this.ImportProfile" ButtonVariant="Variant.Outlined" NoMargin="true" />
|
||||
</MudStack>
|
||||
</DialogContent>
|
||||
<DialogActions>
|
||||
<MudButton OnClick="@this.Close" Variant="Variant.Filled">
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using AIStudio.Settings;
|
||||
using AIStudio.Tools.PluginSystem;
|
||||
|
||||
namespace AIStudio.Dialogs.Settings;
|
||||
|
||||
@@ -11,11 +12,33 @@ public partial class SettingsDialogProfiles : SettingsDialogBase
|
||||
{ x => x.IsEditing, false },
|
||||
};
|
||||
|
||||
await this.AddProfile(dialogParameters, isImport: false);
|
||||
}
|
||||
|
||||
private async Task ImportProfile()
|
||||
{
|
||||
var import = await ConfigurationSnippetImportDialog.ShowAsync(this.DialogService, PluginConfigurationObjectType.PROFILE, T("Import Profile"));
|
||||
if (import?.ConfigurationObject is not Profile profile)
|
||||
return;
|
||||
|
||||
await this.AddProfile(CreateDialogParameters(profile, isEditing: false), isImport: true);
|
||||
}
|
||||
|
||||
private async Task AddProfile(DialogParameters<ProfileDialog> dialogParameters, bool isImport)
|
||||
{
|
||||
var dialogReference = await this.DialogService.ShowAsync<ProfileDialog>(T("Add Profile"), dialogParameters, DialogOptions.FULLSCREEN);
|
||||
var dialogResult = await dialogReference.Result;
|
||||
if (dialogResult is null || dialogResult.Canceled)
|
||||
return;
|
||||
|
||||
//
|
||||
// An organization can lock the import while the user is still filling in the form, e.g.,
|
||||
// with a new version of its configuration plugin. Hence, the permission is checked once
|
||||
// more before the imported profile is stored:
|
||||
//
|
||||
if (isImport && !this.SettingsManager.ConfigurationData.App.CanImportConfigurationSnippet(PluginConfigurationObjectType.PROFILE))
|
||||
return;
|
||||
|
||||
var addedProfile = (Profile)dialogResult.Data!;
|
||||
addedProfile = addedProfile with { Num = this.SettingsManager.ConfigurationData.NextProfileNum++ };
|
||||
|
||||
@@ -27,17 +50,7 @@ public partial class SettingsDialogProfiles : SettingsDialogBase
|
||||
|
||||
private async Task EditProfile(Profile profile)
|
||||
{
|
||||
var dialogParameters = new DialogParameters<ProfileDialog>
|
||||
{
|
||||
{ x => x.DataNum, profile.Num },
|
||||
{ x => x.DataId, profile.Id },
|
||||
{ x => x.DataName, profile.Name },
|
||||
{ x => x.DataNeedToKnow, profile.NeedToKnow },
|
||||
{ x => x.DataActions, profile.Actions },
|
||||
{ x => x.IsEditing, true },
|
||||
};
|
||||
|
||||
var dialogReference = await this.DialogService.ShowAsync<ProfileDialog>(T("Edit Profile"), dialogParameters, DialogOptions.FULLSCREEN);
|
||||
var dialogReference = await this.DialogService.ShowAsync<ProfileDialog>(T("Edit Profile"), CreateDialogParameters(profile, isEditing: true), DialogOptions.FULLSCREEN);
|
||||
var dialogResult = await dialogReference.Result;
|
||||
if (dialogResult is null || dialogResult.Canceled)
|
||||
return;
|
||||
@@ -51,20 +64,20 @@ public partial class SettingsDialogProfiles : SettingsDialogBase
|
||||
|
||||
private async Task ViewProfile(Profile profile)
|
||||
{
|
||||
var dialogParameters = new DialogParameters<ProfileDialog>
|
||||
{
|
||||
{ x => x.DataNum, profile.Num },
|
||||
{ x => x.DataId, profile.Id },
|
||||
{ x => x.DataName, profile.Name },
|
||||
{ x => x.DataNeedToKnow, profile.NeedToKnow },
|
||||
{ x => x.DataActions, profile.Actions },
|
||||
{ x => x.IsEditing, true },
|
||||
{ x => x.IsReadOnly, true },
|
||||
};
|
||||
|
||||
await this.DialogService.ShowAsync<ProfileDialog>(T("View Profile"), dialogParameters, DialogOptions.FULLSCREEN);
|
||||
await this.DialogService.ShowAsync<ProfileDialog>(T("View Profile"), CreateDialogParameters(profile, isEditing: true, isReadOnly: true), DialogOptions.FULLSCREEN);
|
||||
}
|
||||
|
||||
private static DialogParameters<ProfileDialog> CreateDialogParameters(Profile profile, bool isEditing, bool isReadOnly = false) => new()
|
||||
{
|
||||
{ x => x.DataNum, profile.Num },
|
||||
{ x => x.DataId, profile.Id },
|
||||
{ x => x.DataName, profile.Name },
|
||||
{ x => x.DataNeedToKnow, profile.NeedToKnow },
|
||||
{ x => x.DataActions, profile.Actions },
|
||||
{ x => x.IsEditing, isEditing },
|
||||
{ x => x.IsReadOnly, isReadOnly },
|
||||
};
|
||||
|
||||
private async Task ExportProfile(Profile profile)
|
||||
{
|
||||
if (!this.SettingsManager.ConfigurationData.App.ShowAdminSettings)
|
||||
|
||||
@@ -89,6 +89,12 @@ public partial class TranscriptionProviderDialog : MSGComponentBase, ISecretId
|
||||
[Parameter]
|
||||
public bool IsEnterpriseConfiguration { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The API key an imported transcription provider brought along. When editing, the dialog loads the stored key instead.
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public string ImportedAPIKey { get; set; } = string.Empty;
|
||||
|
||||
[Inject]
|
||||
private RustService RustService { get; init; } = null!;
|
||||
|
||||
@@ -197,6 +203,14 @@ public partial class TranscriptionProviderDialog : MSGComponentBase, ISecretId
|
||||
|
||||
await this.ReloadModels();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.dataAPIKey = this.ImportedAPIKey;
|
||||
|
||||
// An import does not contact the server, so its model is the only one to choose until the user loads the models:
|
||||
if (!string.IsNullOrWhiteSpace(this.DataModel.Id))
|
||||
this.availableModels.Add(this.DataModel);
|
||||
}
|
||||
}
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
@@ -346,4 +360,4 @@ public partial class TranscriptionProviderDialog : MSGComponentBase, ISecretId
|
||||
};
|
||||
|
||||
private bool IsNoneProvider => this.DataLLMProvider is LLMProviders.NONE;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user