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/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 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