diff --git a/app/MindWork AI Studio/Assistants/Synonym/AssistantSynonyms.razor b/app/MindWork AI Studio/Assistants/Synonym/AssistantSynonyms.razor new file mode 100644 index 0000000..908972c --- /dev/null +++ b/app/MindWork AI Studio/Assistants/Synonym/AssistantSynonyms.razor @@ -0,0 +1,12 @@ +@attribute [Route(Routes.ASSISTANT_SYNONYMS)] +@inherits AssistantBaseCore + + + + + + + + + Get synonyms + diff --git a/app/MindWork AI Studio/Assistants/Synonym/AssistantSynonyms.razor.cs b/app/MindWork AI Studio/Assistants/Synonym/AssistantSynonyms.razor.cs new file mode 100644 index 0000000..032a50a --- /dev/null +++ b/app/MindWork AI Studio/Assistants/Synonym/AssistantSynonyms.razor.cs @@ -0,0 +1,164 @@ +using AIStudio.Chat; + +namespace AIStudio.Assistants.Synonym; + +public partial class AssistantSynonyms : AssistantBaseCore +{ + protected override Tools.Components Component => Tools.Components.SYNONYMS_ASSISTANT; + + protected override string Title => "Synonyms"; + + protected override string Description => + """ + 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 IReadOnlyList FooterButtons => []; + + protected override ChatThread ConvertToChatThread => (this.chatThread ?? new()) with + { + SystemPrompt = SystemPrompts.DEFAULT, + }; + + protected override void ResetFrom() + { + 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(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 "Please provide a word or phrase as input."; + + return null; + } + + private string? ValidateCustomLanguage(string language) + { + if(this.selectedLanguage == CommonLanguages.OTHER && string.IsNullOrWhiteSpace(language)) + return "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); + } +} \ No newline at end of file diff --git a/app/MindWork AI Studio/Pages/Assistants.razor b/app/MindWork AI Studio/Pages/Assistants.razor index 9627fcb..e90492e 100644 --- a/app/MindWork AI Studio/Pages/Assistants.razor +++ b/app/MindWork AI Studio/Pages/Assistants.razor @@ -14,6 +14,7 @@ + diff --git a/app/MindWork AI Studio/Pages/Settings.razor b/app/MindWork AI Studio/Pages/Settings.razor index 4bac33e..02586ce 100644 --- a/app/MindWork AI Studio/Pages/Settings.razor +++ b/app/MindWork AI Studio/Pages/Settings.razor @@ -122,7 +122,7 @@ @if (this.SettingsManager.ConfigurationData.Coding.PreselectedProgrammingLanguage is CommonCodingLanguages.OTHER) { - + } @@ -137,12 +137,12 @@ @if (this.SettingsManager.ConfigurationData.TextSummarizer.PreselectedTargetLanguage is CommonLanguages.OTHER) { - + } @if(this.SettingsManager.ConfigurationData.TextSummarizer.PreselectedComplexity is Complexity.SCIENTIFIC_LANGUAGE_OTHER_EXPERTS) { - + } @@ -180,7 +180,7 @@ - + @if (this.SettingsManager.ConfigurationData.GrammarSpelling.PreselectedTargetLanguage is CommonLanguages.OTHER) { @@ -192,7 +192,7 @@ - + @if (this.SettingsManager.ConfigurationData.RewriteImprove.PreselectedTargetLanguage is CommonLanguages.OTHER) { @@ -227,6 +227,18 @@ + + + + + + @if (this.SettingsManager.ConfigurationData.Synonyms.PreselectedLanguage is CommonLanguages.OTHER) + { + + } + + + diff --git a/app/MindWork AI Studio/Routes.razor.cs b/app/MindWork AI Studio/Routes.razor.cs index 584eef3..bb80908 100644 --- a/app/MindWork AI Studio/Routes.razor.cs +++ b/app/MindWork AI Studio/Routes.razor.cs @@ -19,5 +19,6 @@ public sealed partial class Routes public const string ASSISTANT_AGENDA = "/assistant/agenda"; public const string ASSISTANT_EMAIL = "/assistant/email"; public const string ASSISTANT_LEGAL_CHECK = "/assistant/legal-check"; + public const string ASSISTANT_SYNONYMS = "/assistant/synonyms"; // ReSharper restore InconsistentNaming } \ No newline at end of file diff --git a/app/MindWork AI Studio/Settings/ConfigurationSelectData.cs b/app/MindWork AI Studio/Settings/ConfigurationSelectData.cs index c7cdc88..2266b6a 100644 --- a/app/MindWork AI Studio/Settings/ConfigurationSelectData.cs +++ b/app/MindWork AI Studio/Settings/ConfigurationSelectData.cs @@ -86,6 +86,15 @@ public static class ConfigurationSelectDataFactory yield return new(language.Name(), language); } + public static IEnumerable> GetCommonLanguagesOptionalData() + { + foreach (var language in Enum.GetValues()) + if(language is CommonLanguages.AS_IS) + yield return new("Do not specify the language", language); + else + yield return new(language.Name(), language); + } + public static IEnumerable> GetCommonCodingLanguagesData() { foreach (var language in Enum.GetValues()) diff --git a/app/MindWork AI Studio/Settings/DataModel/Data.cs b/app/MindWork AI Studio/Settings/DataModel/Data.cs index ffc1f95..586c763 100644 --- a/app/MindWork AI Studio/Settings/DataModel/Data.cs +++ b/app/MindWork AI Studio/Settings/DataModel/Data.cs @@ -46,4 +46,6 @@ public sealed class Data public DataEMail EMail { get; set; } = new(); public DataLegalCheck LegalCheck { get; set; } = new(); + + public DataSynonyms Synonyms { get; set; } = new(); } \ No newline at end of file diff --git a/app/MindWork AI Studio/Settings/DataModel/DataSynonyms.cs b/app/MindWork AI Studio/Settings/DataModel/DataSynonyms.cs new file mode 100644 index 0000000..1d1fdb8 --- /dev/null +++ b/app/MindWork AI Studio/Settings/DataModel/DataSynonyms.cs @@ -0,0 +1,24 @@ +namespace AIStudio.Settings.DataModel; + +public sealed class DataSynonyms +{ + /// + /// Preselect any rewrite options? + /// + public bool PreselectOptions { get; set; } + + /// + /// Preselect the language? + /// + public CommonLanguages PreselectedLanguage { get; set; } + + /// + /// Preselect any other language? + /// + public string PreselectedOtherLanguage { get; set; } = string.Empty; + + /// + /// Preselect a provider? + /// + public string PreselectedProvider { get; set; } = string.Empty; +} \ No newline at end of file diff --git a/app/MindWork AI Studio/Settings/SettingsManager.cs b/app/MindWork AI Studio/Settings/SettingsManager.cs index a965b37..36441bc 100644 --- a/app/MindWork AI Studio/Settings/SettingsManager.cs +++ b/app/MindWork AI Studio/Settings/SettingsManager.cs @@ -128,6 +128,7 @@ public sealed class SettingsManager(ILogger logger) Tools.Components.TEXT_SUMMARIZER_ASSISTANT => this.ConfigurationData.TextSummarizer.PreselectOptions ? this.ConfigurationData.Providers.FirstOrDefault(x => x.Id == this.ConfigurationData.TextSummarizer.PreselectedProvider) : default, Tools.Components.EMAIL_ASSISTANT => this.ConfigurationData.EMail.PreselectOptions ? this.ConfigurationData.Providers.FirstOrDefault(x => x.Id == this.ConfigurationData.EMail.PreselectedProvider) : default, Tools.Components.LEGAL_CHECK_ASSISTANT => this.ConfigurationData.LegalCheck.PreselectOptions ? this.ConfigurationData.Providers.FirstOrDefault(x => x.Id == this.ConfigurationData.LegalCheck.PreselectedProvider) : default, + Tools.Components.SYNONYMS_ASSISTANT => this.ConfigurationData.Synonyms.PreselectOptions ? this.ConfigurationData.Providers.FirstOrDefault(x => x.Id == this.ConfigurationData.Synonyms.PreselectedProvider) : default, _ => default, }; diff --git a/app/MindWork AI Studio/Tools/Components.cs b/app/MindWork AI Studio/Tools/Components.cs index c2e2940..693905c 100644 --- a/app/MindWork AI Studio/Tools/Components.cs +++ b/app/MindWork AI Studio/Tools/Components.cs @@ -13,6 +13,7 @@ public enum Components TEXT_SUMMARIZER_ASSISTANT, EMAIL_ASSISTANT, LEGAL_CHECK_ASSISTANT, + SYNONYMS_ASSISTANT, CHAT, } \ No newline at end of file diff --git a/app/MindWork AI Studio/Tools/Event.cs b/app/MindWork AI Studio/Tools/Event.cs index a99bc1d..84beba5 100644 --- a/app/MindWork AI Studio/Tools/Event.cs +++ b/app/MindWork AI Studio/Tools/Event.cs @@ -27,4 +27,5 @@ public enum Event SEND_TO_CHAT, SEND_TO_EMAIL_ASSISTANT, SEND_TO_LEGAL_CHECK_ASSISTANT, + SEND_TO_SYNONYMS_ASSISTANT, } \ No newline at end of file diff --git a/app/MindWork AI Studio/packages.lock.json b/app/MindWork AI Studio/packages.lock.json index 907ef87..1eb6330 100644 --- a/app/MindWork AI Studio/packages.lock.json +++ b/app/MindWork AI Studio/packages.lock.json @@ -178,6 +178,6 @@ "contentHash": "FHNOatmUq0sqJOkTx+UF/9YK1f180cnW5FVqnQMvYUN0elp6wFzbtPSiqbo1/ru8ICp43JM1i7kKkk6GsNGHlA==" } }, - "net8.0/osx-x64": {} + "net8.0/osx-arm64": {} } } \ No newline at end of file diff --git a/app/MindWork AI Studio/wwwroot/changelog/v0.9.4.md b/app/MindWork AI Studio/wwwroot/changelog/v0.9.4.md new file mode 100644 index 0000000..c910315 --- /dev/null +++ b/app/MindWork AI Studio/wwwroot/changelog/v0.9.4.md @@ -0,0 +1,3 @@ +# v0.9.4, build 179 (2024-09-06 xx:xx UTC) +- Added a synonym assistant to find synonyms for words or a phrase. +- Added possibility to preselect some synonym options on the settings page. \ No newline at end of file