From aab012442b42f8f02b58751f2df6f2df99fe49b2 Mon Sep 17 00:00:00 2001 From: BoiHanny <114599052+BoiHanny@users.noreply.github.com> Date: Fri, 26 Jan 2024 01:53:16 +0100 Subject: [PATCH 1/4] The most significant changes were made in `MainWindow.xaml` and `ApplicationError.xaml`. In `MainWindow.xaml`, a `d:DataContext` attribute was added to the main window to set the design-time data context to an instance of `ViewModel`. This change facilitates design-time data binding and aids in UI design when using the MVVM pattern. In `ApplicationError.xaml`, several modifications were made to the `TextBlock` elements. New `TextBlock` elements `MainError` and `Version` were added with various properties set. The `CallStack` `TextBlock` element was also modified, with changes to the `BlurRadius` and `Color` in its `DropShadowEffect`. The `Run` elements named `MainError` and `CallStack` were removed and replaced by the new `TextBlock` elements. List of changes: 1. `MainWindow.xaml`: Added `d:DataContext` attribute to the main window, setting the design-time data context to an instance of `ViewModel` for design-time data binding. 2. `ApplicationError.xaml`: - Added `MainError` and `Version` `TextBlock` elements with various properties set. - Modified `CallStack` `TextBlock` element, changing the `BlurRadius` from `10` to `5` and the `Color` from `#251153` to `#FF10178C` in its `DropShadowEffect`. - Removed `Run` elements named `MainError` and `CallStack` and several `LineBreak` elements, replacing them with the new `TextBlock` elements. 3. `ApplicationError.xaml.cs`: Set `Version.Text` property to `ViewModel.Instance.AppVersion.VersionNumber` in the constructor to display the application version number in the `Version` `TextBlock` in the `ApplicationError` dialog. --- vrcosc-magicchatbox/MainWindow.xaml | 1 + .../UI/Dialogs/ApplicationError.xaml | 80 ++++++++++++------- .../UI/Dialogs/ApplicationError.xaml.cs | 1 + 3 files changed, 51 insertions(+), 31 deletions(-) diff --git a/vrcosc-magicchatbox/MainWindow.xaml b/vrcosc-magicchatbox/MainWindow.xaml index 05988bc9..ffe6904d 100644 --- a/vrcosc-magicchatbox/MainWindow.xaml +++ b/vrcosc-magicchatbox/MainWindow.xaml @@ -12,6 +12,7 @@ MinWidth="1000" MinHeight="500" VerticalAlignment="Bottom" + d:DataContext="{d:DesignInstance Type=vm:ViewModel, IsDesignTimeCreatable=True}" IsEnabled="{Binding AppIsEnabled, UpdateSourceTrigger=PropertyChanged}" Opacity="{Binding AppOpacity, UpdateSourceTrigger=PropertyChanged}" Topmost="{Binding Topmost, UpdateSourceTrigger=PropertyChanged}" diff --git a/vrcosc-magicchatbox/UI/Dialogs/ApplicationError.xaml b/vrcosc-magicchatbox/UI/Dialogs/ApplicationError.xaml index 7025dd66..1ebb8ef7 100644 --- a/vrcosc-magicchatbox/UI/Dialogs/ApplicationError.xaml +++ b/vrcosc-magicchatbox/UI/Dialogs/ApplicationError.xaml @@ -115,57 +115,75 @@ + + + + + + + + + - - - - - - - - - - + + Color="#FF10178C" /> + + + + + + + + + + + + + + + + updateApp.PrepareUpdate()); + } + else + { + Process.Start("explorer", "http://github.com/BoiHanny/vrcosc-magicchatbox/releases"); + } + } + + private async Task ManualUpdateCheckAsync() + { + var updateCheckTask = DataController.CheckForUpdateAndWait(true); + var delayTask = Task.Delay(TimeSpan.FromSeconds(8)); + + await Task.WhenAny(updateCheckTask, delayTask); + } + + private void CheckUpdateBtnn_Click(object sender, RoutedEventArgs e) { ManualUpdateCheckAsync(); } } } From a6b8a492f5c3a79ee33af48954481aceb1277076 Mon Sep 17 00:00:00 2001 From: BoiHanny <114599052+BoiHanny@users.noreply.github.com> Date: Fri, 26 Jan 2024 04:17:40 +0100 Subject: [PATCH 3/4] The most significant changes include the addition of a new file `IntelliChatModule.cs` which introduces a method for spelling and grammar checks using OpenAI and an enumeration of supported languages. The `OpenAIModule.cs` was also modified to allow public setting of the `OpenAIClient` property. The user interface of the application was updated in `MainWindow.xaml` with new elements for spelling check and adjustments were made in `ApplicationError.xaml`. A new property `IntelliChatRequesting` was added in `ViewModel.cs`. List of changes: 1. The `DataController.cs` file was modified to remove a check for a status with the message 'BoiHanny' or 'Gun'. 2. A new file `IntelliChatModule.cs` was added. This file contains a class `IntelliChatModule` that has a method `PerformSpellingAndGrammarCheckAsync` which uses OpenAI to perform spelling and grammar checks on a given text. It also contains an enum `SupportedIntelliChatLanguage` listing various languages. 3. The `OpenAIModule.cs` file was modified to change the `OpenAIClient` property from private set to public set. 4. A new image `SpellingCheck.png` was added to the project resources in `MagicChatbox.csproj`. 5. The `MainWindow.xaml` file was updated with several UI changes including adding a new border, a new text block, and a new button for spelling check. The DataContext was also updated. 6. The `MainWindow.xaml.cs` file was modified to remove the OpenAI import and add a new method `SpellingCheck_Click` to handle the click event of the new spelling check button. 7. The `ApplicationError.xaml` file was updated with several UI changes including adjusting margins and font sizes. 8. A new property `IntelliChatRequesting` was added in `ViewModel.cs`. --- .../Classes/DataAndSecurity/DataController.cs | 1 - .../Classes/Modules/IntelliChatModule.cs | 72 ++++++++++++ .../Classes/Modules/OpenAIModule.cs | 2 +- .../Img/Icons/SpellingCheck.png | Bin 0 -> 1178 bytes vrcosc-magicchatbox/MagicChatbox.csproj | 2 + vrcosc-magicchatbox/MainWindow.xaml | 105 +++++++++++++++--- vrcosc-magicchatbox/MainWindow.xaml.cs | 46 +++++++- .../UI/Dialogs/ApplicationError.xaml | 9 +- vrcosc-magicchatbox/ViewModels/ViewModel.cs | 12 ++ 9 files changed, 224 insertions(+), 25 deletions(-) create mode 100644 vrcosc-magicchatbox/Classes/Modules/IntelliChatModule.cs create mode 100644 vrcosc-magicchatbox/Img/Icons/SpellingCheck.png diff --git a/vrcosc-magicchatbox/Classes/DataAndSecurity/DataController.cs b/vrcosc-magicchatbox/Classes/DataAndSecurity/DataController.cs index 4f9137a9..c47fd80e 100644 --- a/vrcosc-magicchatbox/Classes/DataAndSecurity/DataController.cs +++ b/vrcosc-magicchatbox/Classes/DataAndSecurity/DataController.cs @@ -660,7 +660,6 @@ public static void LoadStatusList() return; } ViewModel.Instance.StatusList = JsonConvert.DeserializeObject>(json); - // check if we have a status with the msg 'BoiHanny' or 'Gun' if (ViewModel.Instance.StatusList.Any(x => x.msg == "boihanny" || x.msg == "sr4 series")) { ViewModel.Instance.Egg_Dev = true; diff --git a/vrcosc-magicchatbox/Classes/Modules/IntelliChatModule.cs b/vrcosc-magicchatbox/Classes/Modules/IntelliChatModule.cs new file mode 100644 index 00000000..333c8d7d --- /dev/null +++ b/vrcosc-magicchatbox/Classes/Modules/IntelliChatModule.cs @@ -0,0 +1,72 @@ +using OpenAI.Chat; +using OpenAI; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Text.Json; +using vrcosc_magicchatbox.ViewModels; +using System.Windows.Threading; + +namespace vrcosc_magicchatbox.Classes.Modules +{ + public class IntelliChatModule + { + public static async Task PerformSpellingAndGrammarCheckAsync(string text, List languages = null) + { + if (!OpenAIModule.Instance.IsInitialized) + { + ViewModel.Instance.ActivateSetting("Settings_OpenAI"); + return string.Empty; + } + + + var promptBuilder = new StringBuilder(); + + // Create a prompt indicating the possible languages + promptBuilder.AppendLine("Detect and correct any spelling and grammar errors in the following text, return only correct text"); + if (languages != null && languages.Any()) + { + promptBuilder.AppendLine($"Possible languages: {string.Join(", ", languages)}."); + } + promptBuilder.AppendLine($"Text: \"{text}\""); + + string prompt = promptBuilder.ToString(); + + var response = await OpenAIModule.Instance.OpenAIClient.ChatEndpoint.GetCompletionAsync( + new ChatRequest(messages: new List { new Message(Role.System, prompt) }, maxTokens: 120)); + + // Check the type of response.Content and convert to string accordingly + if (response?.Choices?[0].Message.Content.ValueKind == JsonValueKind.String) + { + return response.Choices[0].Message.Content.GetString(); + } + else + { + // If it's not a string, use ToString() to get the JSON-formatted text + return response?.Choices?[0].Message.Content.ToString() ?? string.Empty; + } + } + + } + + public enum SupportedIntelliChatLanguage + { + English, + Spanish, + French, + German, + Chinese, + Japanese, + Russian, + Portuguese, + Italian, + Dutch, + Arabic, + Turkish, + Korean, + Hindi, + Swedish, + } +} diff --git a/vrcosc-magicchatbox/Classes/Modules/OpenAIModule.cs b/vrcosc-magicchatbox/Classes/Modules/OpenAIModule.cs index 5133bf4a..3b27c6f0 100644 --- a/vrcosc-magicchatbox/Classes/Modules/OpenAIModule.cs +++ b/vrcosc-magicchatbox/Classes/Modules/OpenAIModule.cs @@ -16,7 +16,7 @@ public class OpenAIModule private static readonly Lazy instance = new Lazy(() => new OpenAIModule()); - public OpenAIClient OpenAIClient { get; private set; } = null; + public OpenAIClient OpenAIClient { get; set; } = null; public bool AuthChecked { get; private set; } = false; public bool IsInitialized => OpenAIClient != null; diff --git a/vrcosc-magicchatbox/Img/Icons/SpellingCheck.png b/vrcosc-magicchatbox/Img/Icons/SpellingCheck.png new file mode 100644 index 0000000000000000000000000000000000000000..536282c381e8570e6a1ab158e724c3ebb66010ab GIT binary patch literal 1178 zcmV;L1ZDe)P)500001b5ch_0Itp) z=>Px#1ZP1_K>z@;j|==^1poj532;bRa{vGizyJUazyWI3i3tDz1TRTMK~z{r?Uq|; z6KNF3b7_*fG)bGvdP87zdwzVrWPGWpN>zBy+c zpE1G7qis6ddKM(K=+OqZ_jOa?i*tWo?;hk+byJg>-5n?9P2@5!ydFs*4O5T&YG~t3 z8FKMx3oSLisceLRk?)G{iz`^xjcqfO6^GM#kYxoeHMUEfn*nOcOjwlz3plQT?0k&0@T<+6G1Q$MTV~RkWDAF;Aah@F_{mIb zhSFaw7Jg4$EH#EQS#2H5Phwg# zqp`u2911eoR2;SDAD7ehAekC_#nXa9A^%G~*|9W3Hx4wmbg>kqGl{cQap~|h_>S?k zfHGJp=5^+4!O{%UzTV^U`B(~?gR`G-h~<+1#^xSnDTt1}+r(kbn3|!iW?)3avMe^c8JUVF zM>{2-+Jg-)@w5&!+SgvM{431eGrEtV8M^W0PXz)c{~9XoEtX}(lhXBAq8q5v%X!|C zR62e}kpsu38ZtD~*>-3rvT&ZIDfoQYLa%r&M#^C0_o6nPnrx_Q1JhIHav9ymH6oFW zM#u;)O|3=<82Jf)3!S4qA}+E)DwBA_p#TrG zn?pg>GPSQha6A;8)6LS6%VjgDHH(Zk+>Z7mop^(;u(SmI?V!u$?#G*U8^5X4F5I`` zL6;d?B1H=9Whsbj(F;aKi1GOFHym2RM*h>%fUu$=cX{D3#_S!qURWREHbf8=RHgc-^Rjt?gzYlIMH^7)CX5A8B;x7+j!j!V1_JkU}yM45(>9xEfLHBk-)!pyAZ`8^}C!9S+F zzITSA12^*dT&uX!mNZ0+q^6h7YA1Qh63PgA+Gc7cJXN9YWhz7E0YjKdyuUHD ssx + @@ -119,6 +120,7 @@ + diff --git a/vrcosc-magicchatbox/MainWindow.xaml b/vrcosc-magicchatbox/MainWindow.xaml index ffe6904d..a6c94387 100644 --- a/vrcosc-magicchatbox/MainWindow.xaml +++ b/vrcosc-magicchatbox/MainWindow.xaml @@ -12,7 +12,8 @@ MinWidth="1000" MinHeight="500" VerticalAlignment="Bottom" - d:DataContext="{d:DesignInstance Type=vm:ViewModel, IsDesignTimeCreatable=True}" + d:DataContext="{d:DesignInstance Type=vm:ViewModel, + IsDesignTimeCreatable=True}" IsEnabled="{Binding AppIsEnabled, UpdateSourceTrigger=PropertyChanged}" Opacity="{Binding AppOpacity, UpdateSourceTrigger=PropertyChanged}" Topmost="{Binding Topmost, UpdateSourceTrigger=PropertyChanged}" @@ -4003,6 +4004,55 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + - + Text="Requesting..." + Visibility="{Binding IntelliChatRequesting, Converter={StaticResource InverseBoolToHiddenConverter}, UpdateSourceTrigger=PropertyChanged}" /> + diff --git a/vrcosc-magicchatbox/MainWindow.xaml.cs b/vrcosc-magicchatbox/MainWindow.xaml.cs index f91959fa..526e868d 100644 --- a/vrcosc-magicchatbox/MainWindow.xaml.cs +++ b/vrcosc-magicchatbox/MainWindow.xaml.cs @@ -1,11 +1,9 @@ -using OpenAI; -using System; +using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Diagnostics; using System.IO; using System.Linq; -using System.Reflection; using System.Security.Principal; using System.Threading; using System.Threading.Tasks; @@ -1388,6 +1386,7 @@ private void DisconnectOpenAI_Click(object sender, RoutedEventArgs e) ViewModel.Instance.OpenAIOrganizationIDEncrypted = string.Empty; ViewModel.Instance.OpenAIAccessTokenEncrypted = string.Empty; ViewModel.Instance.OpenAIConnected = false; + OpenAIModule.Instance.OpenAIClient = null; } @@ -1452,6 +1451,47 @@ private void UpdateByZipFile_Click(object sender, RoutedEventArgs e) updateApp.SelectCustomZip(); } + private async void SpellingCheck_Click(object sender, RoutedEventArgs e) + { + Dispatcher.Invoke(() => + { + ViewModel.Instance.IntelliChatRequesting = true; + }); + if (string.IsNullOrWhiteSpace(ViewModel.Instance.NewChattingTxt)) + { + ViewModel.Instance.IntelliChatRequesting = false; + return; + } + + + try + { + string checkedText = await IntelliChatModule.PerformSpellingAndGrammarCheckAsync(ViewModel.Instance.NewChattingTxt); + + Dispatcher.Invoke(() => + { + if (string.IsNullOrEmpty(checkedText)) + { + ViewModel.Instance.IntelliChatRequesting = false; + } + else + { + ViewModel.Instance.NewChattingTxt = checkedText; + ViewModel.Instance.IntelliChatRequesting = false; + } + }); + } + catch (Exception ex) + { + Dispatcher.Invoke(() => + { + Logging.WriteException(ex); + ViewModel.Instance.IntelliChatRequesting = false; + }); + } + } + + } } \ No newline at end of file diff --git a/vrcosc-magicchatbox/UI/Dialogs/ApplicationError.xaml b/vrcosc-magicchatbox/UI/Dialogs/ApplicationError.xaml index a5004e7e..26348018 100644 --- a/vrcosc-magicchatbox/UI/Dialogs/ApplicationError.xaml +++ b/vrcosc-magicchatbox/UI/Dialogs/ApplicationError.xaml @@ -137,7 +137,7 @@ Color="#FF10178C" /> - + @@ -154,7 +154,7 @@