Implemented renaming of chats

This commit is contained in:
Thorsten Sommer 2024-07-11 13:03:07 +02:00
parent 7afc017c63
commit 72fa028d47
Signed by: tsommer
GPG Key ID: 371BBA77A02C0108
5 changed files with 59 additions and 3 deletions

View File

@ -18,7 +18,7 @@ public sealed class ChatThread
/// <summary>
/// The name of the chat thread. Usually generated by an AI model or manually edited by the user.
/// </summary>
public string Name { get; init; } = string.Empty;
public string Name { get; set; } = string.Empty;
/// <summary>
/// The seed for the chat thread. Some providers use this to generate deterministic results.

View File

@ -16,8 +16,13 @@
<div style="display: grid; grid-template-columns: 1fr auto; align-items: center; width: 100%">
<MudText Style="justify-self: start;">@treeItem.Text</MudText>
<div style="justify-self: end;">
<MudIconButton Icon="@Icons.Material.Filled.Edit" Size="Size.Medium" Color="Color.Inherit"/>
<MudIconButton Icon="@Icons.Material.Filled.Delete" Size="Size.Medium" Color="Color.Inherit" OnClick="() => this.DeleteChat(treeItem.Path)"/>
<MudTooltip Text="Rename" Placement="Placement.Right">
<MudIconButton Icon="@Icons.Material.Filled.Edit" Size="Size.Medium" Color="Color.Inherit" OnClick="() => this.RenameChat(treeItem.Path)"/>
</MudTooltip>
<MudTooltip Text="Delete" Placement="Placement.Right">
<MudIconButton Icon="@Icons.Material.Filled.Delete" Size="Size.Medium" Color="Color.Inherit" OnClick="() => this.DeleteChat(treeItem.Path)"/>
</MudTooltip>
</div>
</div>
</BodyContent>

View File

@ -285,4 +285,26 @@ public partial class Workspaces : ComponentBase
await this.CurrentChatThreadChanged.InvokeAsync(this.CurrentChatThread);
}
}
private async Task RenameChat(string? chatPath)
{
var chat = await this.LoadChat(chatPath, false);
if (chat is null)
return;
var dialogParameters = new DialogParameters
{
{ "Message", $"Please enter a new or edit the name for your chat '{chat.Name}':" },
{ "UserInput", chat.Name },
};
var dialogReference = await this.DialogService.ShowAsync<RenameDialog>("Rename Chat", dialogParameters, DialogOptions.FULLSCREEN);
var dialogResult = await dialogReference.Result;
if (dialogResult.Canceled)
return;
chat.Name = (dialogResult.Data as string)!;
await this.StoreChat(chat);
await this.LoadTreeItems();
}
}

View File

@ -0,0 +1,10 @@
<MudDialog>
<DialogContent>
<MudText Typo="Typo.body1">@this.Message</MudText>
<MudTextField T="string" @bind-Text="@this.UserInput" Variant="Variant.Outlined" AutoGrow="@false" Lines="1" Label="Chat name"/>
</DialogContent>
<DialogActions>
<MudButton OnClick="@this.Cancel" Variant="Variant.Filled">Cancel</MudButton>
<MudButton OnClick="@this.Confirm" Variant="Variant.Filled" Color="Color.Error">Rename</MudButton>
</DialogActions>
</MudDialog>

View File

@ -0,0 +1,19 @@
using Microsoft.AspNetCore.Components;
namespace AIStudio.Components.CommonDialogs;
public partial class RenameDialog : ComponentBase
{
[CascadingParameter]
private MudDialogInstance MudDialog { get; set; } = null!;
[Parameter]
public string Message { get; set; } = string.Empty;
[Parameter]
public string UserInput { get; set; } = string.Empty;
private void Cancel() => this.MudDialog.Cancel();
private void Confirm() => this.MudDialog.Close(DialogResult.Ok(this.UserInput));
}