mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2025-02-05 11:29:06 +00:00
Added button to edit last user message (#248)
This commit is contained in:
parent
b2ca49ab92
commit
8060fc01dd
@ -12,10 +12,22 @@
|
|||||||
<MudText Typo="Typo.body1">@this.Role.ToName() (@this.Time)</MudText>
|
<MudText Typo="Typo.body1">@this.Role.ToName() (@this.Time)</MudText>
|
||||||
</CardHeaderContent>
|
</CardHeaderContent>
|
||||||
<CardHeaderActions>
|
<CardHeaderActions>
|
||||||
|
@if (this.IsSecondToLastBlock && this.Role is ChatRole.USER && this.EditLastUserBlockFunc is not null)
|
||||||
|
{
|
||||||
|
<MudTooltip Text="Edit" Placement="Placement.Bottom">
|
||||||
|
<MudIconButton Icon="@Icons.Material.Filled.Edit" Color="Color.Default" OnClick="@this.EditLastUserBlock"/>
|
||||||
|
</MudTooltip>
|
||||||
|
}
|
||||||
|
@if (this.IsLastContentBlock && this.Role is ChatRole.USER && this.EditLastBlockFunc is not null)
|
||||||
|
{
|
||||||
|
<MudTooltip Text="Edit" Placement="Placement.Bottom">
|
||||||
|
<MudIconButton Icon="@Icons.Material.Filled.Edit" Color="Color.Default" OnClick="@this.EditLastBlock"/>
|
||||||
|
</MudTooltip>
|
||||||
|
}
|
||||||
@if (this.IsLastContentBlock && this.Role is ChatRole.AI && this.RegenerateFunc is not null)
|
@if (this.IsLastContentBlock && this.Role is ChatRole.AI && this.RegenerateFunc is not null)
|
||||||
{
|
{
|
||||||
<MudTooltip Text="Regenerate" Placement="Placement.Bottom">
|
<MudTooltip Text="Regenerate" Placement="Placement.Bottom">
|
||||||
<MudIconButton Icon="@Icons.Material.Filled.Recycling" Color="Color.Tertiary" OnClick="@this.RegenerateBlock"/>
|
<MudIconButton Icon="@Icons.Material.Filled.Recycling" Color="Color.Default" OnClick="@this.RegenerateBlock"/>
|
||||||
</MudTooltip>
|
</MudTooltip>
|
||||||
}
|
}
|
||||||
@if (this.RemoveBlockFunc is not null)
|
@if (this.RemoveBlockFunc is not null)
|
||||||
|
@ -43,6 +43,9 @@ public partial class ContentBlockComponent : ComponentBase
|
|||||||
|
|
||||||
[Parameter]
|
[Parameter]
|
||||||
public bool IsLastContentBlock { get; set; } = false;
|
public bool IsLastContentBlock { get; set; } = false;
|
||||||
|
|
||||||
|
[Parameter]
|
||||||
|
public bool IsSecondToLastBlock { get; set; } = false;
|
||||||
|
|
||||||
[Parameter]
|
[Parameter]
|
||||||
public Func<IContent, Task>? RemoveBlockFunc { get; set; }
|
public Func<IContent, Task>? RemoveBlockFunc { get; set; }
|
||||||
@ -50,6 +53,12 @@ public partial class ContentBlockComponent : ComponentBase
|
|||||||
[Parameter]
|
[Parameter]
|
||||||
public Func<IContent, Task>? RegenerateFunc { get; set; }
|
public Func<IContent, Task>? RegenerateFunc { get; set; }
|
||||||
|
|
||||||
|
[Parameter]
|
||||||
|
public Func<IContent, Task>? EditLastBlockFunc { get; set; }
|
||||||
|
|
||||||
|
[Parameter]
|
||||||
|
public Func<IContent, Task>? EditLastUserBlockFunc { get; set; }
|
||||||
|
|
||||||
[Parameter]
|
[Parameter]
|
||||||
public Func<bool> RegenerateEnabled { get; set; } = () => false;
|
public Func<bool> RegenerateEnabled { get; set; } = () => false;
|
||||||
|
|
||||||
@ -170,4 +179,33 @@ public partial class ContentBlockComponent : ComponentBase
|
|||||||
if (regenerate.HasValue && regenerate.Value)
|
if (regenerate.HasValue && regenerate.Value)
|
||||||
await this.RegenerateFunc(this.Content);
|
await this.RegenerateFunc(this.Content);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task EditLastBlock()
|
||||||
|
{
|
||||||
|
if (this.EditLastBlockFunc is null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if(this.Role is not ChatRole.USER)
|
||||||
|
return;
|
||||||
|
|
||||||
|
await this.EditLastBlockFunc(this.Content);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task EditLastUserBlock()
|
||||||
|
{
|
||||||
|
if (this.EditLastUserBlockFunc is null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if(this.Role is not ChatRole.USER)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var edit = await this.DialogService.ShowMessageBox(
|
||||||
|
"Edit Message",
|
||||||
|
"Do you really want to edit this message? In order to edit this message, the AI response will be deleted.",
|
||||||
|
"Yes, remove the AI response and edit it",
|
||||||
|
"No, keep it");
|
||||||
|
|
||||||
|
if (edit.HasValue && edit.Value)
|
||||||
|
await this.EditLastUserBlockFunc(this.Content);
|
||||||
|
}
|
||||||
}
|
}
|
@ -12,9 +12,21 @@
|
|||||||
{
|
{
|
||||||
var block = blocks[i];
|
var block = blocks[i];
|
||||||
var isLastBlock = i == blocks.Count - 1;
|
var isLastBlock = i == blocks.Count - 1;
|
||||||
|
var isSecondLastBlock = i == blocks.Count - 2;
|
||||||
@if (!block.HideFromUser)
|
@if (!block.HideFromUser)
|
||||||
{
|
{
|
||||||
<ContentBlockComponent Role="@block.Role" Type="@block.ContentType" Time="@block.Time" Content="@block.Content" RemoveBlockFunc="@this.RemoveBlock" IsLastContentBlock="@isLastBlock" RegenerateFunc="@this.RegenerateBlock" RegenerateEnabled="@(() => this.IsProviderSelected)"/>
|
<ContentBlockComponent
|
||||||
|
Role="@block.Role"
|
||||||
|
Type="@block.ContentType"
|
||||||
|
Time="@block.Time"
|
||||||
|
Content="@block.Content"
|
||||||
|
RemoveBlockFunc="@this.RemoveBlock"
|
||||||
|
IsLastContentBlock="@isLastBlock"
|
||||||
|
IsSecondToLastBlock="@isSecondLastBlock"
|
||||||
|
RegenerateFunc="@this.RegenerateBlock"
|
||||||
|
RegenerateEnabled="@(() => this.IsProviderSelected)"
|
||||||
|
EditLastBlockFunc="@this.EditLastBlock"
|
||||||
|
EditLastUserBlockFunc="@this.EditLastUserBlock"/>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -595,6 +595,44 @@ public partial class ChatComponent : MSGComponentBase, IAsyncDisposable
|
|||||||
await this.SendMessage(reuseLastUserPrompt: true);
|
await this.SendMessage(reuseLastUserPrompt: true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Task EditLastUserBlock(IContent block)
|
||||||
|
{
|
||||||
|
if(this.ChatThread is null)
|
||||||
|
return Task.CompletedTask;
|
||||||
|
|
||||||
|
if (block is not ContentText textBlock)
|
||||||
|
return Task.CompletedTask;
|
||||||
|
|
||||||
|
var lastBlock = this.ChatThread.Blocks.Last();
|
||||||
|
var lastBlockContent = lastBlock.Content;
|
||||||
|
if(lastBlockContent is null)
|
||||||
|
return Task.CompletedTask;
|
||||||
|
|
||||||
|
this.userInput = textBlock.Text;
|
||||||
|
this.ChatThread.Remove(block);
|
||||||
|
this.ChatThread.Remove(lastBlockContent);
|
||||||
|
this.hasUnsavedChanges = true;
|
||||||
|
this.StateHasChanged();
|
||||||
|
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Task EditLastBlock(IContent block)
|
||||||
|
{
|
||||||
|
if(this.ChatThread is null)
|
||||||
|
return Task.CompletedTask;
|
||||||
|
|
||||||
|
if (block is not ContentText textBlock)
|
||||||
|
return Task.CompletedTask;
|
||||||
|
|
||||||
|
this.userInput = textBlock.Text;
|
||||||
|
this.ChatThread.Remove(block);
|
||||||
|
this.hasUnsavedChanges = true;
|
||||||
|
this.StateHasChanged();
|
||||||
|
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
#region Overrides of MSGComponentBase
|
#region Overrides of MSGComponentBase
|
||||||
|
|
||||||
public override async Task ProcessIncomingMessage<T>(ComponentBase? sendingComponent, Event triggeredEvent, T? data) where T : default
|
public override async Task ProcessIncomingMessage<T>(ComponentBase? sendingComponent, Event triggeredEvent, T? data) where T : default
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
# v0.9.24, build 199 (2025-01-xx xx:xx UTC)
|
# v0.9.24, build 199 (2025-01-xx xx:xx UTC)
|
||||||
- Added a button to remove a message from the chat thread.
|
- Added a button to remove a message from the chat thread.
|
||||||
- Added a button to regenerate the last AI response.
|
- Added a button to regenerate the last AI response.
|
||||||
|
- Added a button to edit the last user message.
|
Loading…
Reference in New Issue
Block a user