diff --git a/app/MindWork AI Studio/Assistants/AssistantBase.razor b/app/MindWork AI Studio/Assistants/AssistantBase.razor index 1451da41..c27704c4 100644 --- a/app/MindWork AI Studio/Assistants/AssistantBase.razor +++ b/app/MindWork AI Studio/Assistants/AssistantBase.razor @@ -29,7 +29,7 @@ - + @this.SubmitText @if (this.isProcessing && this.cancellationTokenSource is not null) diff --git a/app/MindWork AI Studio/Assistants/AssistantBase.razor.cs b/app/MindWork AI Studio/Assistants/AssistantBase.razor.cs index 1f0c7364..1a9ff997 100644 --- a/app/MindWork AI Studio/Assistants/AssistantBase.razor.cs +++ b/app/MindWork AI Studio/Assistants/AssistantBase.razor.cs @@ -97,10 +97,10 @@ public abstract partial class AssistantBase : AssistantLowerBase, IMe protected Profile currentProfile = Profile.NO_PROFILE; protected ChatThread? chatThread; protected IContent? lastUserPrompt; + protected CancellationTokenSource? cancellationTokenSource; private readonly Timer formChangeTimer = new(TimeSpan.FromSeconds(1.6)); - - private CancellationTokenSource? cancellationTokenSource; + private ContentBlock? resultingContentBlock; private string[] inputIssues = []; private bool isProcessing; @@ -179,6 +179,16 @@ public abstract partial class AssistantBase : AssistantLowerBase, IMe return null; } + private async Task Start() + { + using (this.cancellationTokenSource = new()) + { + await this.SubmitAction(); + } + + this.cancellationTokenSource = null; + } + private void TriggerFormChange(FormFieldChangedEventArgs _) { this.formChangeTimer.Stop(); @@ -286,16 +296,12 @@ public abstract partial class AssistantBase : 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.cancellationTokenSource.Token); - } - - this.cancellationTokenSource = null; + + // 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.cancellationTokenSource!.Token); + this.isProcessing = false; this.StateHasChanged();