mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2025-02-05 13:49:07 +00:00
Added the option to stop the current generation (#249)
This commit is contained in:
parent
8060fc01dd
commit
187663bbf2
@ -100,6 +100,13 @@
|
|||||||
<ConfidenceInfo Mode="ConfidenceInfoMode.ICON" LLMProvider="@this.Provider.UsedLLMProvider"/>
|
<ConfidenceInfo Mode="ConfidenceInfoMode.ICON" LLMProvider="@this.Provider.UsedLLMProvider"/>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@if (this.isStreaming && this.cancellationTokenSource is not null)
|
||||||
|
{
|
||||||
|
<MudTooltip Text="Stop generation" Placement="@TOOLBAR_TOOLTIP_PLACEMENT">
|
||||||
|
<MudIconButton Icon="@Icons.Material.Filled.Stop" Color="Color.Error" OnClick="() => this.CancelStreaming()"/>
|
||||||
|
</MudTooltip>
|
||||||
|
}
|
||||||
|
|
||||||
<ProfileSelection CurrentProfile="@this.currentProfile" CurrentProfileChanged="@this.ProfileWasChanged"/>
|
<ProfileSelection CurrentProfile="@this.currentProfile" CurrentProfileChanged="@this.ProfileWasChanged"/>
|
||||||
</MudToolBar>
|
</MudToolBar>
|
||||||
</FooterContent>
|
</FooterContent>
|
||||||
|
@ -56,6 +56,7 @@ public partial class ChatComponent : MSGComponentBase, IAsyncDisposable
|
|||||||
private bool autoSaveEnabled;
|
private bool autoSaveEnabled;
|
||||||
private string currentWorkspaceName = string.Empty;
|
private string currentWorkspaceName = string.Empty;
|
||||||
private Guid currentWorkspaceId = Guid.Empty;
|
private Guid currentWorkspaceId = Guid.Empty;
|
||||||
|
private CancellationTokenSource? cancellationTokenSource;
|
||||||
|
|
||||||
// Unfortunately, we need the input field reference to blur the focus away. Without
|
// Unfortunately, we need the input field reference to blur the focus away. Without
|
||||||
// this, we cannot clear the input field.
|
// this, we cannot clear the input field.
|
||||||
@ -336,14 +337,19 @@ public partial class ChatComponent : MSGComponentBase, IAsyncDisposable
|
|||||||
this.scrollRenderCountdown = 2;
|
this.scrollRenderCountdown = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.StateHasChanged();
|
|
||||||
|
|
||||||
this.Logger.LogDebug($"Start processing user input using provider '{this.Provider.InstanceName}' with model '{this.Provider.Model}'.");
|
this.Logger.LogDebug($"Start processing user input using provider '{this.Provider.InstanceName}' with model '{this.Provider.Model}'.");
|
||||||
|
|
||||||
|
using (this.cancellationTokenSource = new())
|
||||||
|
{
|
||||||
|
this.StateHasChanged();
|
||||||
|
|
||||||
// Use the selected provider to get the AI response.
|
// Use the selected provider to get the AI response.
|
||||||
// By awaiting this line, we wait for the entire
|
// By awaiting this line, we wait for the entire
|
||||||
// content to be streamed.
|
// content to be streamed.
|
||||||
await aiText.CreateFromProviderAsync(this.Provider.CreateProvider(this.Logger), this.SettingsManager, this.Provider.Model, this.ChatThread);
|
await aiText.CreateFromProviderAsync(this.Provider.CreateProvider(this.Logger), this.SettingsManager, this.Provider.Model, this.ChatThread, this.cancellationTokenSource.Token);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.cancellationTokenSource = null;
|
||||||
|
|
||||||
// Save the chat:
|
// Save the chat:
|
||||||
if (this.SettingsManager.ConfigurationData.Workspace.StorageBehavior is WorkspaceStorageBehavior.STORE_CHATS_AUTOMATICALLY)
|
if (this.SettingsManager.ConfigurationData.Workspace.StorageBehavior is WorkspaceStorageBehavior.STORE_CHATS_AUTOMATICALLY)
|
||||||
@ -357,6 +363,13 @@ public partial class ChatComponent : MSGComponentBase, IAsyncDisposable
|
|||||||
this.StateHasChanged();
|
this.StateHasChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task CancelStreaming()
|
||||||
|
{
|
||||||
|
if (this.cancellationTokenSource is not null)
|
||||||
|
if(!this.cancellationTokenSource.IsCancellationRequested)
|
||||||
|
await this.cancellationTokenSource.CancelAsync();
|
||||||
|
}
|
||||||
|
|
||||||
private async Task SaveThread()
|
private async Task SaveThread()
|
||||||
{
|
{
|
||||||
if(this.ChatThread is null)
|
if(this.ChatThread is null)
|
||||||
@ -679,6 +692,14 @@ public partial class ChatComponent : MSGComponentBase, IAsyncDisposable
|
|||||||
await this.SaveThread();
|
await this.SaveThread();
|
||||||
this.hasUnsavedChanges = false;
|
this.hasUnsavedChanges = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.cancellationTokenSource is not null)
|
||||||
|
{
|
||||||
|
if(!this.cancellationTokenSource.IsCancellationRequested)
|
||||||
|
await this.cancellationTokenSource.CancelAsync();
|
||||||
|
|
||||||
|
this.cancellationTokenSource.Dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
@ -2,3 +2,4 @@
|
|||||||
- 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.
|
- Added a button to edit the last user message.
|
||||||
|
- Added a button to stop the AI from generating a response.
|
Loading…
Reference in New Issue
Block a user