mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-02-12 11:41:38 +00:00
Create a new Assistant
This commit is contained in:
parent
9fc5c809b0
commit
edacfb196b
@ -0,0 +1,8 @@
|
|||||||
|
@attribute [Route(Routes.ASSISTANT_SYNONYMS)]
|
||||||
|
@inherits AssistantBaseCore<AIStudio.Dialogs.Settings.SettingsDialogPowerPoint>
|
||||||
|
|
||||||
|
<MudTextField T="string" @bind-Text="@this.inputText" Validation="@this.ValidatingText" AdornmentIcon="@Icons.Material.Filled.Spellcheck" Adornment="Adornment.Start" Label="@T("Your word or phrase")" Variant="Variant.Outlined" Class="mb-3" UserAttributes="@USER_INPUT_ATTRIBUTES"/>
|
||||||
|
<MudTextField T="string" @bind-Text="@this.inputContext" AdornmentIcon="@Icons.Material.Filled.Description" Adornment="Adornment.Start" Lines="2" AutoGrow="@false" Label="@T("(Optional) The context for the given word or phrase")" Variant="Variant.Outlined" Class="mb-3" UserAttributes="@USER_INPUT_ATTRIBUTES"/>
|
||||||
|
|
||||||
|
<EnumSelection T="CommonLanguages" NameFunc="@(language => language.NameSelectingOptional())" @bind-Value="@this.selectedLanguage" Icon="@Icons.Material.Filled.Translate" Label="@T("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"/>
|
||||||
169
app/MindWork AI Studio/Assistants/PowerPoint/PowerPoint.razor.cs
Normal file
169
app/MindWork AI Studio/Assistants/PowerPoint/PowerPoint.razor.cs
Normal file
@ -0,0 +1,169 @@
|
|||||||
|
using Microsoft.AspNetCore.Components;
|
||||||
|
using AIStudio.Chat;
|
||||||
|
using AIStudio.Dialogs.Settings;
|
||||||
|
|
||||||
|
namespace AIStudio.Assistants.PowerPoint;
|
||||||
|
|
||||||
|
public partial class PowerPoint : AssistantBaseCore<SettingsDialogPowerPoint>
|
||||||
|
{
|
||||||
|
public override Tools.Components Component => Tools.Components.SYNONYMS_ASSISTANT;
|
||||||
|
|
||||||
|
protected override string Title => T("Synonyms");
|
||||||
|
|
||||||
|
protected override string Description => T("Find synonyms for words or phrases.");
|
||||||
|
|
||||||
|
protected override string SystemPrompt =>
|
||||||
|
$"""
|
||||||
|
You have a PhD in linguistics. Therefore, you are an expert in the {this.SystemPromptLanguage()} language.
|
||||||
|
You receive a word or phrase as input. You might also receive some context. You then provide
|
||||||
|
a list of synonyms as a Markdown list.
|
||||||
|
|
||||||
|
First, derive possible meanings from the word, phrase, and context, when available. Then, provide
|
||||||
|
possible synonyms for each meaning.
|
||||||
|
|
||||||
|
Example for the word "learn" and the language English (US):
|
||||||
|
|
||||||
|
Derive possible meanings (*this list is not part of the output*):
|
||||||
|
- Meaning "to learn"
|
||||||
|
- Meaning "to retain"
|
||||||
|
|
||||||
|
Next, provide possible synonyms for each meaning, which is your output:
|
||||||
|
|
||||||
|
# Meaning "to learn"
|
||||||
|
- absorb
|
||||||
|
- study
|
||||||
|
- acquire
|
||||||
|
- advance
|
||||||
|
- practice
|
||||||
|
|
||||||
|
# Meaning "to retain"
|
||||||
|
- remember
|
||||||
|
- note
|
||||||
|
- realize
|
||||||
|
|
||||||
|
You do not ask follow-up questions and never repeat the task instructions. When you do not know
|
||||||
|
any synonyms for the given word or phrase, you state this. Your output is always in
|
||||||
|
the {this.SystemPromptLanguage()} language.
|
||||||
|
""";
|
||||||
|
|
||||||
|
protected override bool AllowProfiles => false;
|
||||||
|
|
||||||
|
protected override IReadOnlyList<IButtonData> FooterButtons => [];
|
||||||
|
|
||||||
|
protected override string SubmitText => T("Find synonyms");
|
||||||
|
|
||||||
|
protected override Func<Task> SubmitAction => this.FindSynonyms;
|
||||||
|
|
||||||
|
protected override ChatThread ConvertToChatThread => (this.chatThread ?? new()) with
|
||||||
|
{
|
||||||
|
SystemPrompt = SystemPrompts.DEFAULT,
|
||||||
|
};
|
||||||
|
|
||||||
|
protected override void ResetForm()
|
||||||
|
{
|
||||||
|
this.inputText = string.Empty;
|
||||||
|
this.inputContext = string.Empty;
|
||||||
|
if (!this.MightPreselectValues())
|
||||||
|
{
|
||||||
|
this.selectedLanguage = CommonLanguages.AS_IS;
|
||||||
|
this.customTargetLanguage = string.Empty;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override bool MightPreselectValues()
|
||||||
|
{
|
||||||
|
if (this.SettingsManager.ConfigurationData.Synonyms.PreselectOptions)
|
||||||
|
{
|
||||||
|
this.selectedLanguage = this.SettingsManager.ConfigurationData.Synonyms.PreselectedLanguage;
|
||||||
|
this.customTargetLanguage = this.SettingsManager.ConfigurationData.Synonyms.PreselectedOtherLanguage;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private string inputText = string.Empty;
|
||||||
|
private string inputContext = string.Empty;
|
||||||
|
private CommonLanguages selectedLanguage;
|
||||||
|
private string customTargetLanguage = string.Empty;
|
||||||
|
|
||||||
|
#region Overrides of ComponentBase
|
||||||
|
|
||||||
|
protected override async Task OnInitializedAsync()
|
||||||
|
{
|
||||||
|
var deferredContent = MessageBus.INSTANCE.CheckDeferredMessages<string>(Event.SEND_TO_SYNONYMS_ASSISTANT).FirstOrDefault();
|
||||||
|
if (deferredContent is not null)
|
||||||
|
this.inputContext = deferredContent;
|
||||||
|
|
||||||
|
await base.OnInitializedAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private string? ValidatingText(string text)
|
||||||
|
{
|
||||||
|
if(string.IsNullOrWhiteSpace(text))
|
||||||
|
return T("Please provide a word or phrase as input.");
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private string? ValidateCustomLanguage(string language)
|
||||||
|
{
|
||||||
|
if(this.selectedLanguage == CommonLanguages.OTHER && string.IsNullOrWhiteSpace(language))
|
||||||
|
return T("Please provide a custom language.");
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private string SystemPromptLanguage()
|
||||||
|
{
|
||||||
|
var lang = this.selectedLanguage switch
|
||||||
|
{
|
||||||
|
CommonLanguages.AS_IS => "source",
|
||||||
|
CommonLanguages.OTHER => this.customTargetLanguage,
|
||||||
|
|
||||||
|
_ => $"{this.selectedLanguage.Name()}",
|
||||||
|
};
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(lang))
|
||||||
|
return "source";
|
||||||
|
|
||||||
|
return lang;
|
||||||
|
}
|
||||||
|
|
||||||
|
private string UserPromptContext()
|
||||||
|
{
|
||||||
|
if(string.IsNullOrWhiteSpace(this.inputContext))
|
||||||
|
return string.Empty;
|
||||||
|
|
||||||
|
return $"""
|
||||||
|
The given context is:
|
||||||
|
|
||||||
|
```
|
||||||
|
{this.inputContext}
|
||||||
|
```
|
||||||
|
|
||||||
|
""";
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task FindSynonyms()
|
||||||
|
{
|
||||||
|
await this.form!.Validate();
|
||||||
|
if (!this.inputIsValid)
|
||||||
|
return;
|
||||||
|
|
||||||
|
this.CreateChatThread();
|
||||||
|
var time = this.AddUserRequest(
|
||||||
|
$"""
|
||||||
|
{this.UserPromptContext()}
|
||||||
|
The given word or phrase is:
|
||||||
|
|
||||||
|
```
|
||||||
|
{this.inputText}
|
||||||
|
```
|
||||||
|
""");
|
||||||
|
|
||||||
|
await this.AddAIResponseAsync(time);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,28 @@
|
|||||||
|
@using AIStudio.Settings
|
||||||
|
@inherits SettingsDialogBase
|
||||||
|
|
||||||
|
<MudDialog>
|
||||||
|
<TitleContent>
|
||||||
|
<MudText Typo="Typo.h6" Class="d-flex align-center">
|
||||||
|
<MudIcon Icon="@Icons.Material.Filled.Spellcheck" Class="mr-2" />
|
||||||
|
@T("Assistant: Synonyms Options")
|
||||||
|
</MudText>
|
||||||
|
</TitleContent>
|
||||||
|
<DialogContent>
|
||||||
|
<MudPaper Class="pa-3 mb-8 border-dashed border rounded-lg">
|
||||||
|
<ConfigurationOption OptionDescription="@T("Preselect synonym options?")" LabelOn="@T("Synonym options are preselected")" LabelOff="@T("No synonym options are preselected")" State="@(() => this.SettingsManager.ConfigurationData.Synonyms.PreselectOptions)" StateUpdate="@(updatedState => this.SettingsManager.ConfigurationData.Synonyms.PreselectOptions = updatedState)" OptionHelp="@T("When enabled, you can preselect synonym options. This is might be useful when you prefer a specific language or LLM model.")"/>
|
||||||
|
<ConfigurationSelect OptionDescription="@T("Preselect the language")" Disabled="@(() => !this.SettingsManager.ConfigurationData.Synonyms.PreselectOptions)" SelectedValue="@(() => this.SettingsManager.ConfigurationData.Synonyms.PreselectedLanguage)" Data="@ConfigurationSelectDataFactory.GetCommonLanguagesOptionalData()" SelectionUpdate="@(selectedValue => this.SettingsManager.ConfigurationData.Synonyms.PreselectedLanguage = selectedValue)" OptionHelp="@T("Which language should be preselected?")"/>
|
||||||
|
@if (this.SettingsManager.ConfigurationData.Synonyms.PreselectedLanguage is CommonLanguages.OTHER)
|
||||||
|
{
|
||||||
|
<ConfigurationText OptionDescription="@T("Preselect another language")" Disabled="@(() => !this.SettingsManager.ConfigurationData.Synonyms.PreselectOptions)" Icon="@Icons.Material.Filled.Translate" Text="@(() => this.SettingsManager.ConfigurationData.Synonyms.PreselectedOtherLanguage)" TextUpdate="@(updatedText => this.SettingsManager.ConfigurationData.Synonyms.PreselectedOtherLanguage = updatedText)"/>
|
||||||
|
}
|
||||||
|
<ConfigurationMinConfidenceSelection Disabled="@(() => !this.SettingsManager.ConfigurationData.Synonyms.PreselectOptions)" RestrictToGlobalMinimumConfidence="@true" SelectedValue="@(() => this.SettingsManager.ConfigurationData.Synonyms.MinimumProviderConfidence)" SelectionUpdate="@(selectedValue => this.SettingsManager.ConfigurationData.Synonyms.MinimumProviderConfidence = selectedValue)"/>
|
||||||
|
<ConfigurationProviderSelection Component="Components.SYNONYMS_ASSISTANT" Data="@this.availableLLMProviders" Disabled="@(() => !this.SettingsManager.ConfigurationData.Synonyms.PreselectOptions)" SelectedValue="@(() => this.SettingsManager.ConfigurationData.Synonyms.PreselectedProvider)" SelectionUpdate="@(selectedValue => this.SettingsManager.ConfigurationData.Synonyms.PreselectedProvider = selectedValue)"/>
|
||||||
|
</MudPaper>
|
||||||
|
</DialogContent>
|
||||||
|
<DialogActions>
|
||||||
|
<MudButton OnClick="@this.Close" Variant="Variant.Filled">
|
||||||
|
@T("Close")
|
||||||
|
</MudButton>
|
||||||
|
</DialogActions>
|
||||||
|
</MudDialog>
|
||||||
@ -0,0 +1,7 @@
|
|||||||
|
using Microsoft.AspNetCore.Components;
|
||||||
|
|
||||||
|
namespace AIStudio.Dialogs.Settings;
|
||||||
|
|
||||||
|
public partial class SettingsDialogPowerPoint : SettingsDialogBase
|
||||||
|
{
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user