mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2025-08-21 11:12:56 +00:00
Added a "stop generation" button to assistants
This commit is contained in:
parent
b948909afa
commit
46c9384b14
@ -28,10 +28,17 @@
|
||||
@this.Body
|
||||
</CascadingValue>
|
||||
|
||||
<MudButton Disabled="@this.SubmitDisabled" Variant="Variant.Filled" Class="mb-3" OnClick="() => this.SubmitAction()" Style="@this.SubmitButtonStyle">
|
||||
<MudStack Row="true" AlignItems="AlignItems.Center" StretchItems="StretchItems.Start" Class="mb-3">
|
||||
<MudButton Disabled="@this.SubmitDisabled" Variant="Variant.Filled" OnClick="() => this.SubmitAction()" Style="@this.SubmitButtonStyle">
|
||||
@this.SubmitText
|
||||
</MudButton>
|
||||
|
||||
@if (this.isProcessing && this.cancellationTokenSource is not null)
|
||||
{
|
||||
<MudTooltip Text="Stop generation">
|
||||
<MudIconButton Variant="Variant.Filled" Icon="@Icons.Material.Filled.Stop" Color="Color.Error" OnClick="() => this.CancelStreaming()"/>
|
||||
</MudTooltip>
|
||||
}
|
||||
</MudStack>
|
||||
}
|
||||
</MudForm>
|
||||
<Issues IssuesData="@(this.inputIssues)"/>
|
||||
|
@ -100,6 +100,7 @@ public abstract partial class AssistantBase<TSettings> : AssistantLowerBase, IMe
|
||||
|
||||
private readonly Timer formChangeTimer = new(TimeSpan.FromSeconds(1.6));
|
||||
|
||||
private CancellationTokenSource? cancellationTokenSource;
|
||||
private ContentBlock? resultingContentBlock;
|
||||
private string[] inputIssues = [];
|
||||
private bool isProcessing;
|
||||
@ -286,11 +287,15 @@ public abstract partial class AssistantBase<TSettings> : AssistantLowerBase, IMe
|
||||
this.isProcessing = true;
|
||||
this.StateHasChanged();
|
||||
|
||||
using (this.cancellationTokenSource = new())
|
||||
{
|
||||
// Use the selected provider to get the AI response.
|
||||
// By awaiting this line, we wait for the entire
|
||||
// content to be streamed.
|
||||
this.chatThread = await aiText.CreateFromProviderAsync(this.providerSettings.CreateProvider(this.Logger), this.providerSettings.Model, this.lastUserPrompt, this.chatThread);
|
||||
this.chatThread = await aiText.CreateFromProviderAsync(this.providerSettings.CreateProvider(this.Logger), this.providerSettings.Model, this.lastUserPrompt, this.chatThread, this.cancellationTokenSource.Token);
|
||||
}
|
||||
|
||||
this.cancellationTokenSource = null;
|
||||
this.isProcessing = false;
|
||||
this.StateHasChanged();
|
||||
|
||||
@ -298,6 +303,13 @@ public abstract partial class AssistantBase<TSettings> : AssistantLowerBase, IMe
|
||||
return aiText.Text;
|
||||
}
|
||||
|
||||
private async Task CancelStreaming()
|
||||
{
|
||||
if (this.cancellationTokenSource is not null)
|
||||
if(!this.cancellationTokenSource.IsCancellationRequested)
|
||||
await this.cancellationTokenSource.CancelAsync();
|
||||
}
|
||||
|
||||
protected async Task CopyToClipboard()
|
||||
{
|
||||
await this.RustService.CopyText2Clipboard(this.Snackbar, this.Result2Copy());
|
||||
|
@ -1,2 +1,3 @@
|
||||
# v0.9.38, build 213 (2025-03-xx xx:xx UTC)
|
||||
- Added the "stop generation" button to all assistants.
|
||||
- Updated the ERI v1 specification for the ERI server assistant & fixed spelling of the `UNKNOWN` role.
|
Loading…
Reference in New Issue
Block a user