Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@
}

<EnumSelection T="CommonLanguages" NameFunc="@(language => language.NameSelecting())" @bind-Value="@this.selectedTargetLanguage" ValidateSelection="@this.ValidateTargetLanguage" Icon="@Icons.Material.Filled.Translate" Label="@T("Target language")" AllowOther="@true" OtherValue="CommonLanguages.OTHER" @bind-OtherInput="@this.customTargetLanguage" ValidateOther="@this.ValidateCustomLanguage" LabelOther="@T("Custom target language")" />
<ProviderSelection @bind-ProviderSettings="@this.providerSettings" ValidateProvider="@this.ValidatingProvider"/>
<ProviderSelection @bind-ProviderSettings="@this.ProviderSettings" ValidateProvider="@this.ValidatingProvider"/>
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,8 @@ private void OnContentChanged(string content)

private async Task CreateAgenda()
{
await this.form!.Validate();
if (!this.inputIsValid)
await this.Form!.Validate();
if (!this.InputIsValid)
return;

this.CreateChatThread();
Expand Down
12 changes: 6 additions & 6 deletions app/MindWork AI Studio/Assistants/AssistantBase.razor
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

<InnerScrolling>
<ChildContent>
<MudForm @ref="@(this.form)" @bind-IsValid="@(this.inputIsValid)" @bind-Errors="@(this.inputIssues)" FieldChanged="@this.TriggerFormChange" Class="pr-2">
<MudForm @ref="@(this.Form)" @bind-IsValid="@(this.InputIsValid)" @bind-Errors="@(this.inputIssues)" FieldChanged="@this.TriggerFormChange" Class="pr-2">
<MudText Typo="Typo.body1" Align="Align.Justify" Class="mb-2">
@this.Description
</MudText>
Expand All @@ -41,7 +41,7 @@
<MudButton Disabled="@(this.SubmitDisabled || this.isProcessing)" Variant="Variant.Filled" OnClick="@(async () => await this.Start())" Style="@this.SubmitButtonStyle">
@this.SubmitText
</MudButton>
@if (this.isProcessing && this.cancellationTokenSource is not null)
@if (this.isProcessing && this.CancellationTokenSource is not null)
{
<MudTooltip Text="@TB("Stop generation")">
<MudIconButton Variant="Variant.Filled" Icon="@Icons.Material.Filled.Stop" Color="Color.Error" OnClick="@(async () => await this.CancelStreaming())"/>
Expand All @@ -68,9 +68,9 @@
<ContentBlockComponent Role="@(this.resultingContentBlock.Role)" Type="@(this.resultingContentBlock.ContentType)" Time="@(this.resultingContentBlock.Time)" Content="@this.resultingContentBlock.Content"/>
}

@if(this.ShowResult && this.ShowEntireChatThread && this.chatThread is not null)
@if(this.ShowResult && this.ShowEntireChatThread && this.ChatThread is not null)
{
foreach (var block in this.chatThread.Blocks.OrderBy(n => n.Time))
foreach (var block in this.ChatThread.Blocks.OrderBy(n => n.Time))
{
@if (block is { HideFromUser: false, Content: not null })
{
Expand Down Expand Up @@ -155,12 +155,12 @@

@if (this.SettingsManager.ConfigurationData.LLMProviders.ShowProviderConfidence)
{
<ConfidenceInfo Mode="PopoverTriggerMode.BUTTON" LLMProvider="@this.providerSettings.UsedLLMProvider"/>
<ConfidenceInfo Mode="PopoverTriggerMode.BUTTON" LLMProvider="@this.ProviderSettings.UsedLLMProvider"/>
}

@if (this.AllowProfiles && this.ShowProfileSelection)
{
<ProfileSelection MarginLeft="" @bind-CurrentProfile="@this.currentProfile"/>
<ProfileSelection MarginLeft="" @bind-CurrentProfile="@this.CurrentProfile"/>
}

<MudSpacer />
Expand Down
92 changes: 46 additions & 46 deletions app/MindWork AI Studio/Assistants/AssistantBase.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,14 @@ protected virtual string? SendToChatVisibleUserPromptText

protected virtual bool HasSettingsPanel => typeof(TSettings) != typeof(NoSettingsPanel);

protected AIStudio.Settings.Provider providerSettings = Settings.Provider.NONE;
protected MudForm? form;
protected bool inputIsValid;
protected Profile currentProfile = Profile.NO_PROFILE;
protected ChatTemplate currentChatTemplate = ChatTemplate.NO_CHAT_TEMPLATE;
protected ChatThread? chatThread;
protected IContent? lastUserPrompt;
protected CancellationTokenSource? cancellationTokenSource;
protected AIStudio.Settings.Provider ProviderSettings = Settings.Provider.NONE;
protected MudForm? Form;
protected bool InputIsValid;
protected Profile CurrentProfile = Profile.NO_PROFILE;
protected ChatTemplate CurrentChatTemplate = ChatTemplate.NO_CHAT_TEMPLATE;
protected ChatThread? ChatThread;
protected IContent? LastUserPrompt;
protected CancellationTokenSource? CancellationTokenSource;

private readonly Timer formChangeTimer = new(TimeSpan.FromSeconds(1.6));

Expand Down Expand Up @@ -147,9 +147,9 @@ protected override async Task OnInitializedAsync()
};

this.MightPreselectValues();
this.providerSettings = this.SettingsManager.GetPreselectedProvider(this.Component);
this.currentProfile = this.SettingsManager.GetPreselectedProfile(this.Component);
this.currentChatTemplate = this.SettingsManager.GetPreselectedChatTemplate(this.Component);
this.ProviderSettings = this.SettingsManager.GetPreselectedProvider(this.Component);
this.CurrentProfile = this.SettingsManager.GetPreselectedProfile(this.Component);
this.CurrentChatTemplate = this.SettingsManager.GetPreselectedChatTemplate(this.Component);
}

protected override async Task OnParametersSetAsync()
Expand All @@ -165,7 +165,7 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
// Reset the validation when not editing and on the first render.
// We don't want to show validation errors when the user opens the dialog.
if(firstRender)
this.form?.ResetValidation();
this.Form?.ResetValidation();

await base.OnAfterRenderAsync(firstRender);
}
Expand All @@ -174,7 +174,7 @@ protected override async Task OnAfterRenderAsync(bool firstRender)

private string TB(string fallbackEN) => this.T(fallbackEN, typeof(AssistantBase<TSettings>).Namespace, nameof(AssistantBase<TSettings>));

private string SubmitButtonStyle => this.SettingsManager.ConfigurationData.LLMProviders.ShowProviderConfidence ? this.providerSettings.UsedLLMProvider.GetConfidence(this.SettingsManager).StyleBorder(this.SettingsManager) : string.Empty;
private string SubmitButtonStyle => this.SettingsManager.ConfigurationData.LLMProviders.ShowProviderConfidence ? this.ProviderSettings.UsedLLMProvider.GetConfidence(this.SettingsManager).StyleBorder(this.SettingsManager) : string.Empty;

private IReadOnlyList<Tools.Components> VisibleSendToAssistants => Enum.GetValues<AIStudio.Tools.Components>()
.Where(this.CanSendToAssistant)
Expand All @@ -191,12 +191,12 @@ protected override async Task OnAfterRenderAsync(bool firstRender)

private async Task Start()
{
using (this.cancellationTokenSource = new())
using (this.CancellationTokenSource = new())
{
await this.SubmitAction();
}

this.cancellationTokenSource = null;
this.CancellationTokenSource = null;
}

private void TriggerFormChange(FormFieldChangedEventArgs _)
Expand All @@ -223,7 +223,7 @@ protected void AddInputIssue(string issue)
{
Array.Resize(ref this.inputIssues, this.inputIssues.Length + 1);
this.inputIssues[^1] = issue;
this.inputIsValid = false;
this.InputIsValid = false;
this.StateHasChanged();
}

Expand All @@ -233,17 +233,17 @@ protected void AddInputIssue(string issue)
protected void ClearInputIssues()
{
this.inputIssues = [];
this.inputIsValid = true;
this.InputIsValid = true;
this.StateHasChanged();
}

protected void CreateChatThread()
{
this.chatThread = new()
this.ChatThread = new()
{
IncludeDateTime = false,
SelectedProvider = this.providerSettings.Id,
SelectedProfile = this.AllowProfiles ? this.currentProfile.Id : Profile.NO_PROFILE.Id,
SelectedProvider = this.ProviderSettings.Id,
SelectedProfile = this.AllowProfiles ? this.CurrentProfile.Id : Profile.NO_PROFILE.Id,
SystemPrompt = this.SystemPrompt,
WorkspaceId = Guid.Empty,
ChatId = Guid.NewGuid(),
Expand All @@ -255,11 +255,11 @@ protected void CreateChatThread()
protected Guid CreateChatThread(Guid workspaceId, string name)
{
var chatId = Guid.NewGuid();
this.chatThread = new()
this.ChatThread = new()
{
IncludeDateTime = false,
SelectedProvider = this.providerSettings.Id,
SelectedProfile = this.AllowProfiles ? this.currentProfile.Id : Profile.NO_PROFILE.Id,
SelectedProvider = this.ProviderSettings.Id,
SelectedProfile = this.AllowProfiles ? this.CurrentProfile.Id : Profile.NO_PROFILE.Id,
SystemPrompt = this.SystemPrompt,
WorkspaceId = workspaceId,
ChatId = chatId,
Expand All @@ -272,36 +272,36 @@ protected Guid CreateChatThread(Guid workspaceId, string name)

protected virtual void ResetProviderAndProfileSelection()
{
this.providerSettings = this.SettingsManager.GetPreselectedProvider(this.Component);
this.currentProfile = this.SettingsManager.GetPreselectedProfile(this.Component);
this.currentChatTemplate = this.SettingsManager.GetPreselectedChatTemplate(this.Component);
this.ProviderSettings = this.SettingsManager.GetPreselectedProvider(this.Component);
this.CurrentProfile = this.SettingsManager.GetPreselectedProfile(this.Component);
this.CurrentChatTemplate = this.SettingsManager.GetPreselectedChatTemplate(this.Component);
}

protected DateTimeOffset AddUserRequest(string request, bool hideContentFromUser = false, params List<FileAttachment> attachments)
{
var time = DateTimeOffset.Now;
this.lastUserPrompt = new ContentText
this.LastUserPrompt = new ContentText
{
Text = request,
FileAttachments = attachments,
};

this.chatThread!.Blocks.Add(new ContentBlock
this.ChatThread!.Blocks.Add(new ContentBlock
{
Time = time,
ContentType = ContentType.TEXT,
HideFromUser = hideContentFromUser,
Role = ChatRole.USER,
Content = this.lastUserPrompt,
Content = this.LastUserPrompt,
});

return time;
}

protected async Task<string> AddAIResponseAsync(DateTimeOffset time, bool hideContentFromUser = false)
{
var manageCancellationLocally = this.cancellationTokenSource is null;
this.cancellationTokenSource ??= new CancellationTokenSource();
var manageCancellationLocally = this.CancellationTokenSource is null;
this.CancellationTokenSource ??= new CancellationTokenSource();

var aiText = new ContentText
{
Expand All @@ -319,10 +319,10 @@ protected async Task<string> AddAIResponseAsync(DateTimeOffset time, bool hideCo
HideFromUser = hideContentFromUser,
};

if (this.chatThread is not null)
if (this.ChatThread is not null)
{
this.chatThread.Blocks.Add(this.resultingContentBlock);
this.chatThread.SelectedProvider = this.providerSettings.Id;
this.ChatThread.Blocks.Add(this.resultingContentBlock);
this.ChatThread.SelectedProvider = this.ProviderSettings.Id;
}

this.isProcessing = true;
Expand All @@ -331,15 +331,15 @@ protected async Task<string> AddAIResponseAsync(DateTimeOffset time, bool hideCo
// 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.providerSettings.Model, this.lastUserPrompt, this.chatThread, this.cancellationTokenSource!.Token);
this.ChatThread = await aiText.CreateFromProviderAsync(this.ProviderSettings.CreateProvider(), this.ProviderSettings.Model, this.LastUserPrompt, this.ChatThread, this.CancellationTokenSource!.Token);

this.isProcessing = false;
this.StateHasChanged();

if(manageCancellationLocally)
{
this.cancellationTokenSource.Dispose();
this.cancellationTokenSource = null;
this.CancellationTokenSource.Dispose();
this.CancellationTokenSource = null;
}

// Return the AI response:
Expand All @@ -348,9 +348,9 @@ protected async Task<string> AddAIResponseAsync(DateTimeOffset time, bool hideCo

private async Task CancelStreaming()
{
if (this.cancellationTokenSource is not null)
if(!this.cancellationTokenSource.IsCancellationRequested)
await this.cancellationTokenSource.CancelAsync();
if (this.CancellationTokenSource is not null)
if(!this.CancellationTokenSource.IsCancellationRequested)
await this.CancellationTokenSource.CancelAsync();
}

protected async Task CopyToClipboard()
Expand All @@ -360,7 +360,7 @@ protected async Task CopyToClipboard()

private ChatThread CreateSendToChatThread()
{
var originalChatThread = this.chatThread ?? new ChatThread();
var originalChatThread = this.ChatThread ?? new ChatThread();
if (string.IsNullOrWhiteSpace(this.SendToChatVisibleUserPromptText))
return originalChatThread with
{
Expand Down Expand Up @@ -440,7 +440,7 @@ protected Task SendToAssistant(Tools.Components destination, SendToButton sendTo
else
{
var convertedChatThread = this.ConvertToChatThread;
convertedChatThread = convertedChatThread with { SelectedProvider = this.providerSettings.Id };
convertedChatThread = convertedChatThread with { SelectedProvider = this.ProviderSettings.Id };
MessageBus.INSTANCE.DeferMessage(this, sendToData.Event, convertedChatThread);
}
break;
Expand All @@ -465,20 +465,20 @@ private bool CanSendToAssistant(Tools.Components component)
private async Task InnerResetForm()
{
this.resultingContentBlock = null;
this.providerSettings = Settings.Provider.NONE;
this.ProviderSettings = Settings.Provider.NONE;

await this.JsRuntime.ClearDiv(RESULT_DIV_ID);
await this.JsRuntime.ClearDiv(AFTER_RESULT_DIV_ID);

this.ResetForm();
this.ResetProviderAndProfileSelection();

this.inputIsValid = false;
this.InputIsValid = false;
this.inputIssues = [];

this.form?.ResetValidation();
this.Form?.ResetValidation();
this.StateHasChanged();
this.form?.ResetValidation();
this.Form?.ResetValidation();
}

private string GetResetColor() => this.SettingsManager.IsDarkMode switch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
</MudList>

<EnumSelection T="CommonLanguages" NameFunc="@(language => language.NameSelecting())" @bind-Value="@this.selectedTargetLanguage" ValidateSelection="@this.ValidateTargetLanguage" Icon="@Icons.Material.Filled.Translate" Label="@T("Target language")" AllowOther="@true" OtherValue="CommonLanguages.OTHER" @bind-OtherInput="@this.customTargetLanguage" ValidateOther="@this.ValidateCustomLanguage" LabelOther="@T("Custom target language")" />
<ProviderSelection @bind-ProviderSettings="@this.providerSettings" ValidateProvider="@this.ValidatingProvider"/>
<ProviderSelection @bind-ProviderSettings="@this.ProviderSettings" ValidateProvider="@this.ValidatingProvider"/>
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ private async Task TellBias()
}
}

await this.form!.Validate();
if (!this.inputIsValid)
await this.Form!.Validate();
if (!this.InputIsValid)
return;

this.biasOfTheDay = useDrawnBias ?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@
</MudStack>

<MudTextField T="string" @bind-Text="@this.questions" Validation="@this.ValidateQuestions" AdornmentIcon="@Icons.Material.Filled.QuestionMark" Adornment="Adornment.Start" Label="@T("Your question(s)")" Variant="Variant.Outlined" Lines="6" AutoGrow="@true" MaxLines="12" Class="mb-3" UserAttributes="@USER_INPUT_ATTRIBUTES"/>
<ProviderSelection @bind-ProviderSettings="@this.providerSettings" ValidateProvider="@this.ValidatingProvider"/>
<ProviderSelection @bind-ProviderSettings="@this.ProviderSettings" ValidateProvider="@this.ValidatingProvider"/>
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,16 @@ private ValueTask DeleteContext(int index)
return ValueTask.CompletedTask;

this.codingContexts.RemoveAt(index);
this.form?.ResetValidation();
this.Form?.ResetValidation();

this.StateHasChanged();
return ValueTask.CompletedTask;
}

private async Task GetSupport()
{
await this.form!.Validate();
if (!this.inputIsValid)
await this.Form!.Validate();
if (!this.InputIsValid)
return;

var sbContext = new StringBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ else
@T("Documents for the analysis")
</MudText>

<AttachDocuments Name="Document Analysis Files" Layer="@DropLayers.ASSISTANTS" @bind-DocumentPaths="@this.loadedDocumentPaths" CatchAllDocuments="true" UseSmallForm="false" Provider="@this.providerSettings"/>
<AttachDocuments Name="Document Analysis Files" Layer="@DropLayers.ASSISTANTS" @bind-DocumentPaths="@this.loadedDocumentPaths" CatchAllDocuments="true" UseSmallForm="false" Provider="@this.ProviderSettings"/>
</div>
}
else
Expand Down Expand Up @@ -164,10 +164,10 @@ else
@T("Documents for the analysis")
</MudText>

<AttachDocuments Name="Document Analysis Files" Layer="@DropLayers.ASSISTANTS" @bind-DocumentPaths="@this.loadedDocumentPaths" CatchAllDocuments="true" UseSmallForm="false" Provider="@this.providerSettings"/>
<AttachDocuments Name="Document Analysis Files" Layer="@DropLayers.ASSISTANTS" @bind-DocumentPaths="@this.loadedDocumentPaths" CatchAllDocuments="true" UseSmallForm="false" Provider="@this.ProviderSettings"/>

</ExpansionPanel>
</MudExpansionPanels>
}

<ProviderSelection @bind-ProviderSettings="@this.providerSettings" ValidateProvider="@this.ValidatingProvider" ExplicitMinimumConfidence="@this.GetPolicyMinimumConfidenceLevel()"/>
<ProviderSelection @bind-ProviderSettings="@this.ProviderSettings" ValidateProvider="@this.ValidatingProvider" ExplicitMinimumConfidence="@this.GetPolicyMinimumConfidenceLevel()"/>
Loading