Skip to content

Commit

Permalink
Improve provider selection (#112)
Browse files Browse the repository at this point in the history
  • Loading branch information
SommerEngineering authored Sep 4, 2024
1 parent 09c1b77 commit c47d389
Show file tree
Hide file tree
Showing 21 changed files with 160 additions and 149 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ namespace AIStudio.Assistants.Agenda;

public partial class AssistantAgenda : AssistantBaseCore
{
protected override Tools.Components Component => Tools.Components.AGENDA_ASSISTANT;

protected override string Title => "Agenda Planner";

protected override string Description =>
Expand Down Expand Up @@ -93,13 +95,7 @@ the logistical challenges that come with an increasing number of participants.
- Mary Jane: Work package 3
""";

protected override IReadOnlyList<IButtonData> FooterButtons =>
[
new SendToButton
{
Self = SendTo.AGENDA_ASSISTANT,
},
];
protected override IReadOnlyList<IButtonData> FooterButtons => [];

protected override ChatThread ConvertToChatThread => (this.chatThread ?? new()) with
{
Expand Down Expand Up @@ -158,7 +154,6 @@ protected override bool MightPreselectValues()
this.durationBreaks = this.SettingsManager.ConfigurationData.Agenda.PreselectBreakTime;
this.activeParticipation = this.SettingsManager.ConfigurationData.Agenda.PreselectActiveParticipation;
this.numberParticipants = this.SettingsManager.ConfigurationData.Agenda.PreselectNumberParticipants;
this.providerSettings = this.SettingsManager.ConfigurationData.Providers.FirstOrDefault(x => x.Id == this.SettingsManager.ConfigurationData.Agenda.PreselectedProvider);
return true;
}

Expand Down Expand Up @@ -194,7 +189,6 @@ protected override bool MightPreselectValues()

protected override async Task OnInitializedAsync()
{
this.MightPreselectValues();
var deferredContent = MessageBus.INSTANCE.CheckDeferredMessages<string>(Event.SEND_TO_AGENDA_ASSISTANT).FirstOrDefault();
if (deferredContent is not null)
this.inputContent = deferredContent;
Expand Down
87 changes: 51 additions & 36 deletions app/MindWork AI Studio/Assistants/AssistantBase.razor
Original file line number Diff line number Diff line change
Expand Up @@ -35,49 +35,64 @@
</div>
</ChildContent>
<FooterContent>
@if (this.FooterButtons.Count > 0)
{
<MudStack Row="@true" Wrap="Wrap.Wrap" Class="ma-1">
@foreach (var button in this.FooterButtons)
{
switch (button)
<MudStack Row="@true" Wrap="Wrap.Wrap" Class="ma-1">
@if (!this.FooterButtons.Any(x => x.Type is ButtonTypes.SEND_TO))
{
<MudMenu StartIcon="@Icons.Material.Filled.Apps" EndIcon="@Icons.Material.Filled.KeyboardArrowDown" Label="Send to ..." Variant="Variant.Filled" Color="Color.Info">
@foreach (var assistant in Enum.GetValues<Components>().OrderBy(n => n.Name().Length))
{
case ButtonData buttonData when !string.IsNullOrWhiteSpace(buttonData.Tooltip):
<MudTooltip Text="@buttonData.Tooltip">
<MudButton Variant="Variant.Filled" Color="@buttonData.Color" StartIcon="@GetButtonIcon(buttonData.Icon)" OnClick="async () => await buttonData.AsyncAction()">
@buttonData.Text
</MudButton>
</MudTooltip>
break;
if (assistant is Components.NONE || this.Component == assistant)
continue;

<MudMenuItem OnClick="() => this.SendToAssistant(assistant, new())">
@assistant.Name()
</MudMenuItem>
}
</MudMenu>
}

case ButtonData buttonData:
@foreach (var button in this.FooterButtons)
{
switch (button)
{
case ButtonData buttonData when !string.IsNullOrWhiteSpace(buttonData.Tooltip):
<MudTooltip Text="@buttonData.Tooltip">
<MudButton Variant="Variant.Filled" Color="@buttonData.Color" StartIcon="@GetButtonIcon(buttonData.Icon)" OnClick="async () => await buttonData.AsyncAction()">
@buttonData.Text
</MudButton>
break;
</MudTooltip>
break;

case SendToButton sendToButton:
<MudMenu StartIcon="@Icons.Material.Filled.Apps" EndIcon="@Icons.Material.Filled.KeyboardArrowDown" Label="Send to ..." Variant="Variant.Filled" Color="Color.Info">
@foreach (var assistant in Enum.GetValues<SendTo>().OrderBy(n => n.Name().Length))
{
if(assistant is SendTo.NONE || sendToButton.Self == assistant)
continue;
case ButtonData buttonData:
<MudButton Variant="Variant.Filled" Color="@buttonData.Color" StartIcon="@GetButtonIcon(buttonData.Icon)" OnClick="async () => await buttonData.AsyncAction()">
@buttonData.Text
</MudButton>
break;

<MudMenuItem OnClick="() => this.SendToAssistant(assistant, sendToButton)">
@assistant.Name()
</MudMenuItem>
}
</MudMenu>
break;
}
case SendToButton sendToButton:
<MudMenu StartIcon="@Icons.Material.Filled.Apps" EndIcon="@Icons.Material.Filled.KeyboardArrowDown" Label="Send to ..." Variant="Variant.Filled" Color="Color.Info">
@foreach (var assistant in Enum.GetValues<Components>().OrderBy(n => n.Name().Length))
{
if(assistant is Components.NONE || sendToButton.Self == assistant)
continue;

<MudMenuItem OnClick="() => this.SendToAssistant(assistant, sendToButton)">
@assistant.Name()
</MudMenuItem>
}
</MudMenu>
break;
}
<MudButton Variant="Variant.Filled" StartIcon="@Icons.Material.Filled.ContentCopy" OnClick="() => this.CopyToClipboard()">
Copy result
</MudButton>
<MudButton Variant="Variant.Filled" Color="Color.Warning" StartIcon="@Icons.Material.Filled.Refresh" OnClick="() => this.InnerResetForm()">
Reset
</MudButton>
</MudStack>
}
}

<MudButton Variant="Variant.Filled" StartIcon="@Icons.Material.Filled.ContentCopy" OnClick="() => this.CopyToClipboard()">
Copy result
</MudButton>

<MudButton Variant="Variant.Filled" Color="Color.Warning" StartIcon="@Icons.Material.Filled.Refresh" OnClick="() => this.InnerResetForm()">
Reset
</MudButton>
</MudStack>
</FooterContent>
</InnerScrolling>
14 changes: 12 additions & 2 deletions app/MindWork AI Studio/Assistants/AssistantBase.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public abstract partial class AssistantBase : ComponentBase

protected abstract string SystemPrompt { get; }

protected abstract Tools.Components Component { get; }

protected virtual Func<string> Result2Copy => () => this.resultingContentBlock is null ? string.Empty : this.resultingContentBlock.Content switch
{
ContentText textBlock => textBlock.Text,
Expand Down Expand Up @@ -73,6 +75,13 @@ public abstract partial class AssistantBase : ComponentBase

#region Overrides of ComponentBase

protected override async Task OnInitializedAsync()
{
this.MightPreselectValues();
this.providerSettings = this.SettingsManager.GetPreselectedProvider(this.Component);
await base.OnInitializedAsync();
}

protected override async Task OnParametersSetAsync()
{
// Configure the spellchecking for the user input:
Expand Down Expand Up @@ -177,7 +186,7 @@ protected async Task CopyToClipboard()
return icon;
}

private Task SendToAssistant(SendTo destination, SendToButton sendToButton)
private Task SendToAssistant(Tools.Components destination, SendToButton sendToButton)
{
var contentToSend = sendToButton.UseResultingContentBlockData switch
{
Expand All @@ -192,7 +201,7 @@ private Task SendToAssistant(SendTo destination, SendToButton sendToButton)
var sendToData = destination.GetData();
switch (destination)
{
case SendTo.CHAT:
case Tools.Components.CHAT:
MessageBus.INSTANCE.DeferMessage(this, sendToData.Event, this.ConvertToChatThread);
break;

Expand All @@ -214,6 +223,7 @@ private async Task InnerResetForm()
await this.JsRuntime.ClearDiv(AFTER_RESULT_DIV_ID);

this.ResetFrom();
this.providerSettings = this.SettingsManager.GetPreselectedProvider(this.Component);

this.inputIsValid = false;
this.inputIssues = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ namespace AIStudio.Assistants.Coding;

public partial class AssistantCoding : AssistantBaseCore
{
protected override Tools.Components Component => Tools.Components.CODING_ASSISTANT;

protected override string Title => "Coding Assistant";

protected override string Description =>
Expand All @@ -24,13 +26,7 @@ messages. You can also help with code refactoring and optimization.
When the user asks in a different language than English, you answer in the same language!
""";

protected override IReadOnlyList<IButtonData> FooterButtons =>
[
new SendToButton
{
Self = SendTo.CODING_ASSISTANT,
},
];
protected override IReadOnlyList<IButtonData> FooterButtons => [];

protected override void ResetFrom()
{
Expand All @@ -48,7 +44,6 @@ protected override bool MightPreselectValues()
if (this.SettingsManager.ConfigurationData.Coding.PreselectOptions)
{
this.provideCompilerMessages = this.SettingsManager.ConfigurationData.Coding.PreselectCompilerMessages;
this.providerSettings = this.SettingsManager.ConfigurationData.Providers.FirstOrDefault(x => x.Id == this.SettingsManager.ConfigurationData.Coding.PreselectedProvider);
return true;
}

Expand All @@ -64,7 +59,6 @@ protected override bool MightPreselectValues()

protected override async Task OnInitializedAsync()
{
this.MightPreselectValues();
var deferredContent = MessageBus.INSTANCE.CheckDeferredMessages<string>(Event.SEND_TO_CODING_ASSISTANT).FirstOrDefault();
if (deferredContent is not null)
this.questions = deferredContent;
Expand Down
12 changes: 3 additions & 9 deletions app/MindWork AI Studio/Assistants/EMail/AssistantEMail.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ namespace AIStudio.Assistants.EMail;

public partial class AssistantEMail : AssistantBaseCore
{
protected override Tools.Components Component => Tools.Components.EMAIL_ASSISTANT;

protected override string Title => "E-Mail";

protected override string Description =>
Expand All @@ -20,13 +22,7 @@ public partial class AssistantEMail : AssistantBaseCore
{this.SystemPromptGreeting()} {this.SystemPromptName()} You write the email in the following language: {this.SystemPromptLanguage()}.
""";

protected override IReadOnlyList<IButtonData> FooterButtons =>
[
new SendToButton
{
Self = SendTo.EMAIL_ASSISTANT,
},
];
protected override IReadOnlyList<IButtonData> FooterButtons => [];

protected override ChatThread ConvertToChatThread => (this.chatThread ?? new()) with
{
Expand Down Expand Up @@ -59,7 +55,6 @@ protected override bool MightPreselectValues()
this.selectedWritingStyle = this.SettingsManager.ConfigurationData.EMail.PreselectedWritingStyle;
this.selectedTargetLanguage = this.SettingsManager.ConfigurationData.EMail.PreselectedTargetLanguage;
this.customTargetLanguage = this.SettingsManager.ConfigurationData.EMail.PreselectOtherLanguage;
this.providerSettings = this.SettingsManager.ConfigurationData.Providers.FirstOrDefault(x => x.Id == this.SettingsManager.ConfigurationData.EMail.PreselectedProvider);
return true;
}

Expand Down Expand Up @@ -88,7 +83,6 @@ protected override bool MightPreselectValues()

protected override async Task OnInitializedAsync()
{
this.MightPreselectValues();
var deferredContent = MessageBus.INSTANCE.CheckDeferredMessages<string>(Event.SEND_TO_EMAIL_ASSISTANT).FirstOrDefault();
if (deferredContent is not null)
this.inputBulletPoints = deferredContent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ namespace AIStudio.Assistants.GrammarSpelling;

public partial class AssistantGrammarSpelling : AssistantBaseCore
{
protected override Tools.Components Component => Tools.Components.GRAMMAR_SPELLING_ASSISTANT;

protected override string Title => "Grammar & Spelling Checker";

protected override string Description =>
Expand Down Expand Up @@ -31,7 +33,7 @@ Germany and German in Austria differ. You receive text as input. You check the s
[
new SendToButton
{
Self = SendTo.GRAMMAR_SPELLING_ASSISTANT,
Self = Tools.Components.GRAMMAR_SPELLING_ASSISTANT,
UseResultingContentBlockData = false,
GetText = () => string.IsNullOrWhiteSpace(this.correctedText) ? this.inputText : this.correctedText
},
Expand Down Expand Up @@ -59,7 +61,6 @@ protected override bool MightPreselectValues()
{
this.selectedTargetLanguage = this.SettingsManager.ConfigurationData.GrammarSpelling.PreselectedTargetLanguage;
this.customTargetLanguage = this.SettingsManager.ConfigurationData.GrammarSpelling.PreselectedOtherLanguage;
this.providerSettings = this.SettingsManager.ConfigurationData.Providers.FirstOrDefault(x => x.Id == this.SettingsManager.ConfigurationData.GrammarSpelling.PreselectedProvider);
return true;
}

Expand All @@ -70,7 +71,6 @@ protected override bool MightPreselectValues()

protected override async Task OnInitializedAsync()
{
this.MightPreselectValues();
var deferredContent = MessageBus.INSTANCE.CheckDeferredMessages<string>(Event.SEND_TO_GRAMMAR_SPELLING_ASSISTANT).FirstOrDefault();
if (deferredContent is not null)
this.inputText = deferredContent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ namespace AIStudio.Assistants.IconFinder;

public partial class AssistantIconFinder : AssistantBaseCore
{
private string inputContext = string.Empty;
private IconSources selectedIconSource;
protected override Tools.Components Component => Tools.Components.ICON_FINDER_ASSISTANT;

protected override string Title => "Icon Finder";

Expand All @@ -26,13 +25,7 @@ related to the keyword "buildings" might be the best match. Provide your keyword
quotation marks.
""";

protected override IReadOnlyList<IButtonData> FooterButtons =>
[
new SendToButton
{
Self = SendTo.ICON_FINDER_ASSISTANT,
},
];
protected override IReadOnlyList<IButtonData> FooterButtons => [];

protected override void ResetFrom()
{
Expand All @@ -48,18 +41,19 @@ protected override bool MightPreselectValues()
if (this.SettingsManager.ConfigurationData.IconFinder.PreselectOptions)
{
this.selectedIconSource = this.SettingsManager.ConfigurationData.IconFinder.PreselectedSource;
this.providerSettings = this.SettingsManager.ConfigurationData.Providers.FirstOrDefault(x => x.Id == this.SettingsManager.ConfigurationData.IconFinder.PreselectedProvider);
return true;
}

return false;
}

private string inputContext = string.Empty;
private IconSources selectedIconSource;

#region Overrides of ComponentBase

protected override async Task OnInitializedAsync()
{
this.MightPreselectValues();
var deferredContent = MessageBus.INSTANCE.CheckDeferredMessages<string>(Event.SEND_TO_ICON_FINDER_ASSISTANT).FirstOrDefault();
if (deferredContent is not null)
this.inputContext = deferredContent;
Expand Down
Loading

0 comments on commit c47d389

Please sign in to comment.