From e54a319ff769974536eb61db2e1de6a4ff8af4f9 Mon Sep 17 00:00:00 2001 From: BoiHanny <114599052+BoiHanny@users.noreply.github.com> Date: Mon, 29 Jan 2024 16:23:12 +0100 Subject: [PATCH 1/2] The most significant changes involve the addition of a moderation feature to the IntelliChat module in the `vrcosc_magicchatbox` application. This includes updates to the `DataController.cs` and `IntelliChatModule.cs` files to handle the moderation logic, and updates to the `MainWindow.xaml` and `MainWindow.xaml.cs` files to handle the user interface for this feature. Additionally, the `ViewModel.cs` file has been updated to bind the new UI elements to the underlying business logic. 1. The `DataController.cs` file now includes a new key-value pair in the dictionary for `IntelliChatPerformModeration`, which is a boolean type and `IntelliChat` as the category. This change allows the application to determine whether or not to perform moderation on the chat. 2. The `IntelliChatModule.cs` file now includes an import statement for `OpenAI.Moderations`, a conditional block that checks if `IntelliChatPerformModeration` is true, and a new method `PerformModerationCheckAsync`. These changes enable the application to perform a moderation check on the chat text and return an empty string if the moderation response is true. 3. The `MainWindow.xaml` file now includes new UI elements for performing a moderation check and automatically detecting language, as well as a new error panel to display error messages. These changes provide the user with a way to interact with the new moderation feature. 4. The `MainWindow.xaml.cs` file now includes new methods for handling the click events of the new UI elements. This change allows the application to respond to user interactions with the new UI elements. 5. The `ViewModel.cs` file now includes new properties for `IntelliChatError`, `IntelliChatErrorTxt`, `IntelliChatPerformModeration`, and `IntelliChatAutoLang`. These changes allow the application to bind the new UI elements to the underlying business logic. --- .../Classes/DataAndSecurity/DataController.cs | 2 +- .../Classes/Modules/IntelliChatModule.cs | 48 +++- vrcosc-magicchatbox/MainWindow.xaml | 243 +++++++++++++++--- vrcosc-magicchatbox/MainWindow.xaml.cs | 15 ++ vrcosc-magicchatbox/ViewModels/ViewModel.cs | 48 ++++ 5 files changed, 323 insertions(+), 33 deletions(-) diff --git a/vrcosc-magicchatbox/Classes/DataAndSecurity/DataController.cs b/vrcosc-magicchatbox/Classes/DataAndSecurity/DataController.cs index c47fd80e..ccfbb30d 100644 --- a/vrcosc-magicchatbox/Classes/DataAndSecurity/DataController.cs +++ b/vrcosc-magicchatbox/Classes/DataAndSecurity/DataController.cs @@ -318,7 +318,7 @@ public static void LoadComponentStats() { "UnmuteSecOutput", (typeof(bool), "OSC") }, { "UnmuteMainOutput", (typeof(bool), "OSC") }, - + { "IntelliChatPerformModeration", (typeof(bool), "IntelliChat") }, { "BlankEgg", (typeof(bool), "DEV") }, diff --git a/vrcosc-magicchatbox/Classes/Modules/IntelliChatModule.cs b/vrcosc-magicchatbox/Classes/Modules/IntelliChatModule.cs index 179eb07c..f7b470a1 100644 --- a/vrcosc-magicchatbox/Classes/Modules/IntelliChatModule.cs +++ b/vrcosc-magicchatbox/Classes/Modules/IntelliChatModule.cs @@ -1,4 +1,5 @@ using OpenAI.Chat; +using OpenAI.Moderations; using OpenAI; using System; using System.Collections.Generic; @@ -28,6 +29,13 @@ public static async Task PerformSpellingAndGrammarCheckAsync( return string.Empty; } + if(ViewModel.Instance.IntelliChatPerformModeration) + { + bool moderationResponse = await PerformModerationCheckAsync(text); + if(moderationResponse) + return string.Empty; + } + var messages = new List { @@ -36,7 +44,7 @@ public static async Task PerformSpellingAndGrammarCheckAsync( "Please detect and correct any spelling and grammar errors in the following text:") }; - if(languages != null && languages.Any()) + if(languages != null && languages.Any() && !ViewModel.Instance.IntelliChatAutoLang) { messages.Add(new Message(Role.System, $"Consider these languages: {string.Join(", ", languages)}")); } @@ -74,12 +82,19 @@ public static async Task PerformBeautifySentenceAsync( return string.Empty; } + if (ViewModel.Instance.IntelliChatPerformModeration) + { + bool moderationResponse = await PerformModerationCheckAsync(text); + if (moderationResponse) + return string.Empty; + } + var messages = new List { new Message(Role.System, $"Please rewrite the following sentence in a {writingStyle} style:") }; - if(languages != null && languages.Any()) + if(languages != null && languages.Any() && !ViewModel.Instance.IntelliChatAutoLang) { messages.Add(new Message(Role.System, $"Consider these languages: {string.Join(", ", languages)}")); } @@ -111,6 +126,35 @@ public static void RejectIntelliChatSuggestion() ViewModel.Instance.IntelliChatWaitingToAccept = false; } + public static async Task PerformModerationCheckAsync(string checkString) + { + var moderationResponse = await OpenAIModule.Instance.OpenAIClient.ModerationsEndpoint.CreateModerationAsync(new ModerationsRequest(checkString)); + + // Check if the moderationResponse is null, indicating a failure in making the request + if (moderationResponse == null) + { + // Handle the error appropriately + // For example, you might log the error or set an error message in the ViewModel + ViewModel.Instance.IntelliChatError = true; + ViewModel.Instance.IntelliChatErrorTxt = "Error in moderation check."; + return false; + } + + // Check if there are any violations in the response + if (moderationResponse.Results.Any(result => result.Flagged)) + { + ViewModel.Instance.IntelliChatWaitingToAccept = false; + ViewModel.Instance.IntelliChatRequesting = false; + ViewModel.Instance.IntelliChatError = true; + ViewModel.Instance.IntelliChatErrorTxt = "Your message has been temporarily held back due to a moderation check.\nThis is to ensure compliance with OpenAI's guidelines and protect your account."; + return true; + } + + // If there are no violations, return false + return false; + } + + } diff --git a/vrcosc-magicchatbox/MainWindow.xaml b/vrcosc-magicchatbox/MainWindow.xaml index c7d7e3fb..32090ec1 100644 --- a/vrcosc-magicchatbox/MainWindow.xaml +++ b/vrcosc-magicchatbox/MainWindow.xaml @@ -1849,6 +1849,77 @@ Text="{Binding OpenAIAccessErrorTxt, UpdateSourceTrigger=PropertyChanged}" TextWrapping="Wrap" Visibility="{Binding OpenAIAccessError, Converter={StaticResource InverseBoolToHiddenConverter}, UpdateSourceTrigger=PropertyChanged}" /> + + + + + + Perform moderation check (will protect you from being banned) + + + + + + + + + + Automatically detect language (less tokens) + + + + + + + + + + + + + + + @@ -4411,6 +4482,7 @@ Margin="6,0,7,7" HorizontalAlignment="Stretch" VerticalAlignment="Bottom" + d:Visibility="Collapsed" RenderOptions.BitmapScalingMode="NearestNeighbor" Visibility="{Binding IntelliChatWaitingToAccept, Converter={StaticResource InverseBoolToHiddenConverter}, UpdateSourceTrigger=PropertyChanged}"> @@ -4438,42 +4510,14 @@ - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/vrcosc-magicchatbox/MainWindow.xaml.cs b/vrcosc-magicchatbox/MainWindow.xaml.cs index 911cb76a..c50f5c3c 100644 --- a/vrcosc-magicchatbox/MainWindow.xaml.cs +++ b/vrcosc-magicchatbox/MainWindow.xaml.cs @@ -1466,6 +1466,8 @@ private async void SpellingCheck_Click(object sender, RoutedEventArgs e) else { ViewModel.Instance.IntelliChatTxt = checkedText; + ViewModel.Instance.IntelliChatError = false; + ViewModel.Instance.IntelliChatErrorTxt = string.Empty; ViewModel.Instance.IntelliChatWaitingToAccept = true; ViewModel.Instance.IntelliChatRequesting = false; } @@ -1494,6 +1496,8 @@ private async void RebuildChat_Click(object sender, RoutedEventArgs e) ViewModel.Instance.IntelliChatTxt = fixedText; ViewModel.Instance.IntelliChatWaitingToAccept = true; ViewModel.Instance.IntelliChatRequesting = false; + ViewModel.Instance.IntelliChatError = false; + ViewModel.Instance.IntelliChatErrorTxt = string.Empty; } } catch (Exception ex) @@ -1512,7 +1516,18 @@ private void NotAcceptIntelliChat_Click(object sender, RoutedEventArgs e) private void AcceptIntelliChat_Click(object sender, RoutedEventArgs e) { IntelliChatModule.AcceptIntelliChatSuggestion(); + } + + private void CloseIntelliErrorPanel_Click(object sender, RoutedEventArgs e) + { + ViewModel.Instance.IntelliChatError = false; + ViewModel.Instance.IntelliChatErrorTxt = string.Empty; + } + private void AcceptAndSentIntelliChat_Click(object sender, RoutedEventArgs e) + { + IntelliChatModule.AcceptIntelliChatSuggestion(); + ButtonChattingTxt_Click(sender, e); } } diff --git a/vrcosc-magicchatbox/ViewModels/ViewModel.cs b/vrcosc-magicchatbox/ViewModels/ViewModel.cs index 99f5be65..96e7c602 100644 --- a/vrcosc-magicchatbox/ViewModels/ViewModel.cs +++ b/vrcosc-magicchatbox/ViewModels/ViewModel.cs @@ -4186,6 +4186,54 @@ public bool IntelliChatWaitingToAccept } } + + private bool _IntelliChatError = false; + public bool IntelliChatError + { + get { return _IntelliChatError; } + set + { + _IntelliChatError = value; + NotifyPropertyChanged(nameof(IntelliChatError)); + } + } + + + private string _IntelliChatErrorTxt = string.Empty; + public string IntelliChatErrorTxt + { + get { return _IntelliChatErrorTxt; } + set + { + _IntelliChatErrorTxt = value; + NotifyPropertyChanged(nameof(IntelliChatErrorTxt)); + } + } + + + private bool _IntelliChatPerformModeration = true; + public bool IntelliChatPerformModeration + { + get { return _IntelliChatPerformModeration; } + set + { + _IntelliChatPerformModeration = value; + NotifyPropertyChanged(nameof(IntelliChatPerformModeration)); + } + } + + + private bool _IntelliChatAutoLang = true; + public bool IntelliChatAutoLang + { + get { return _IntelliChatAutoLang; } + set + { + _IntelliChatAutoLang = value; + NotifyPropertyChanged(nameof(IntelliChatAutoLang)); + } + } + #endregion #region PropChangedEvent From 7ad10c2647e39537d62590e61e8e81284ce6c791 Mon Sep 17 00:00:00 2001 From: BoiHanny <114599052+BoiHanny@users.noreply.github.com> Date: Mon, 29 Jan 2024 16:24:03 +0100 Subject: [PATCH 2/2] The most significant change in the MagicChatbox project is the update of the project version from 0.8.750 to 0.8.755. This update may include bug fixes, performance improvements, or new features. Changes: 1. Project Version Update: The MagicChatbox project version has been updated from 0.8.750 to 0.8.755. This change indicates that there have been modifications in the project, which could range from minor bug fixes to significant feature additions or improvements. Unfortunately, without specific details about the changes made in the code, it's impossible to provide references to the code changes. Normally, these would be provided in the form of commit messages or change logs from the version control system used (like Git). --- vrcosc-magicchatbox/MagicChatbox.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vrcosc-magicchatbox/MagicChatbox.csproj b/vrcosc-magicchatbox/MagicChatbox.csproj index 286b5029..74f590f4 100644 --- a/vrcosc-magicchatbox/MagicChatbox.csproj +++ b/vrcosc-magicchatbox/MagicChatbox.csproj @@ -2,7 +2,7 @@ WinExe - 0.8.750 + 0.8.755 net6.0-windows10.0.22000.0 vrcosc_magicchatbox enable