Skip to content

Commit

Permalink
Merge pull request #37 from BoiHanny/Dev-Master
Browse files Browse the repository at this point in the history
Dev master
  • Loading branch information
BoiHanny authored Jan 29, 2024
2 parents 715bb7c + 7ad10c2 commit a4352c5
Show file tree
Hide file tree
Showing 6 changed files with 324 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ public static void LoadComponentStats()
{ "UnmuteSecOutput", (typeof(bool), "OSC") },
{ "UnmuteMainOutput", (typeof(bool), "OSC") },


{ "IntelliChatPerformModeration", (typeof(bool), "IntelliChat") },

{ "BlankEgg", (typeof(bool), "DEV") },

Expand Down
48 changes: 46 additions & 2 deletions vrcosc-magicchatbox/Classes/Modules/IntelliChatModule.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using OpenAI.Chat;
using OpenAI.Moderations;
using OpenAI;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -28,6 +29,13 @@ public static async Task<string> PerformSpellingAndGrammarCheckAsync(
return string.Empty;
}

if(ViewModel.Instance.IntelliChatPerformModeration)
{
bool moderationResponse = await PerformModerationCheckAsync(text);
if(moderationResponse)
return string.Empty;
}


var messages = new List<Message>
{
Expand All @@ -36,7 +44,7 @@ public static async Task<string> 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)}"));
}
Expand Down Expand Up @@ -74,12 +82,19 @@ public static async Task<string> PerformBeautifySentenceAsync(
return string.Empty;
}

if (ViewModel.Instance.IntelliChatPerformModeration)
{
bool moderationResponse = await PerformModerationCheckAsync(text);
if (moderationResponse)
return string.Empty;
}

var messages = new List<Message>
{
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)}"));
}
Expand Down Expand Up @@ -111,6 +126,35 @@ public static void RejectIntelliChatSuggestion()
ViewModel.Instance.IntelliChatWaitingToAccept = false;
}

public static async Task<bool> 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;
}



}

Expand Down
2 changes: 1 addition & 1 deletion vrcosc-magicchatbox/MagicChatbox.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>WinExe</OutputType>
<Version>0.8.750</Version>
<Version>0.8.755</Version>
<TargetFramework>net6.0-windows10.0.22000.0</TargetFramework>
<RootNamespace>vrcosc_magicchatbox</RootNamespace>
<Nullable>enable</Nullable>
Expand Down
243 changes: 213 additions & 30 deletions vrcosc-magicchatbox/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -1849,6 +1849,77 @@
Text="{Binding OpenAIAccessErrorTxt, UpdateSourceTrigger=PropertyChanged}"
TextWrapping="Wrap"
Visibility="{Binding OpenAIAccessError, Converter={StaticResource InverseBoolToHiddenConverter}, UpdateSourceTrigger=PropertyChanged}" />
</StackPanel>
</Border>
<Border
Margin="0,0,0,5"
Background="#FF3B3054"
CornerRadius="5,0,0,5">
<StackPanel Margin="5">
<CheckBox
x:Name="PerformModerationCheck"
Height="20"
BorderBrush="#FF2D1265"
Checked="Update_Click"
FontFamily="Comfortaa Light"
FontSize="18"
Foreground="#FFB9B5C1"
IsChecked="{Binding IntelliChatPerformModeration, Mode=TwoWay}"
Style="{DynamicResource SettingsCheckbox}">
Perform moderation check (will protect you from being banned)
</CheckBox>

</StackPanel>
</Border>
<Border
Margin="0,0,0,5"
Background="#FF3B3054"
CornerRadius="5,0,0,5">
<StackPanel Margin="5">
<TextBlock
Padding="0,0,9,0"
VerticalAlignment="Center"
FontFamily="Albert Sans Thin"
FontSize="15"
Foreground="#FF9983AD"
Text="Language" />

<CheckBox
x:Name="AutoDetectLang"
Height="20"
Margin="0,5"
BorderBrush="#FF2D1265"
Checked="Update_Click"
FontFamily="Comfortaa Light"
FontSize="18"
Foreground="#FFB9B5C1"
IsChecked="{Binding IntelliChatAutoLang, Mode=TwoWay}"
Style="{DynamicResource SettingsCheckbox}">
Automatically detect language (less tokens)
</CheckBox>



</StackPanel>
</Border>

<Border
Margin="0,0,0,5"
Background="#FF3B3054"
CornerRadius="5,0,0,5">
<StackPanel Margin="5">
<TextBlock
Padding="0,0,9,0"
VerticalAlignment="Center"
FontFamily="Albert Sans Thin"
FontSize="15"
Foreground="#FF9983AD"
Text="Magic improve" />





</StackPanel>
</Border>
</StackPanel>
Expand Down Expand Up @@ -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}">
<Border Margin="10,0" CornerRadius="5">
Expand Down Expand Up @@ -4438,42 +4510,14 @@
<RowDefinition Height="auto" />
<RowDefinition Height="Auto" MinHeight="40" />
</Grid.RowDefinitions>
<StackPanel
Grid.Row="1"
Grid.Column="1"
Margin="-8,5,0,5"
Orientation="Horizontal">
<Button
x:Name="NotAcceptIntelliChat"
Width="auto"
Margin="2"
Padding="2"
Click="NotAcceptIntelliChat_Click"
Style="{DynamicResource Status_Button_style}">
<Image
Width="18"
RenderOptions.BitmapScalingMode="HighQuality"
Source="/Img/Icons/NotAccept_ico.png" />
</Button>
<Button
x:Name="AcceptIntelliChat"
Width="auto"
Margin="2"
Padding="2"
Click="AcceptIntelliChat_Click"
Style="{DynamicResource Status_Button_style}">
<Image
Width="18"
RenderOptions.BitmapScalingMode="HighQuality"
Source="/Img/Icons/Accept_ico.png" />
</Button>
</StackPanel>


<TextBlock
Grid.Row="1"
Grid.Column="0"
Width="auto"
Height="Auto"
Margin="0,0,95,0"
Padding="15,0,0,15"
HorizontalAlignment="Stretch"
VerticalAlignment="Center"
Expand All @@ -4494,6 +4538,7 @@
</TextBlock>



<!-- Image -->
<Image
Grid.RowSpan="2"
Expand Down Expand Up @@ -4593,6 +4638,144 @@
Opacity="0.3"
Text="Powered by OpenAI" />

<StackPanel
Grid.Row="1"
Grid.Column="1"
Margin="-70,5,0,5"
Orientation="Horizontal">
<Button
x:Name="AcceptAndSentIntelliChat"
Width="auto"
Margin="2"
Padding="2"
Click="AcceptAndSentIntelliChat_Click"
Style="{DynamicResource Status_Button_style}">
<StackPanel Orientation="Horizontal">
<Image
Width="18"
Margin="2"
RenderOptions.BitmapScalingMode="HighQuality"
Source="/Img/Icons/Accept_ico.png" />
<TextBlock
Padding="3,0"
VerticalAlignment="Center"
FontFamily="Albert Sans Thin"
FontSize="13"
Foreground="#FF8D7DB9"
Text="Sent" />
</StackPanel>

</Button>
<Button
x:Name="NotAcceptIntelliChat"
Width="auto"
Margin="2"
Padding="2"
Click="NotAcceptIntelliChat_Click"
Style="{DynamicResource Status_Button_style}">
<Image
Width="18"
Margin="1"
RenderOptions.BitmapScalingMode="HighQuality"
Source="/Img/Icons/NotAccept_ico.png" />
</Button>
<Button
x:Name="AcceptIntelliChat"
Width="auto"
Margin="2"
Padding="2"
Click="AcceptIntelliChat_Click"
Style="{DynamicResource Status_Button_style}">
<Image
Width="18"
Margin="1"
RenderOptions.BitmapScalingMode="HighQuality"
Source="/Img/Icons/Accept_ico.png" />
</Button>
</StackPanel>

</Grid>

</Border>
</Grid>
<Grid
x:Name="AIErrorResponse"
Grid.Row="1"
Height="auto"
Margin="6,0,7,7"
HorizontalAlignment="Stretch"
VerticalAlignment="Bottom"
d:Visibility="Collapsed"
RenderOptions.BitmapScalingMode="NearestNeighbor"
Visibility="{Binding IntelliChatError, Converter={StaticResource InverseBoolToHiddenConverter}, UpdateSourceTrigger=PropertyChanged}">
<Border Margin="10,0" CornerRadius="5">
<Border.Background>
<LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
<GradientStop Color="MediumVioletRed" />
<GradientStop Offset="1" Color="#403670" />
</LinearGradientBrush>
</Border.Background>
<Border.Effect>
<DropShadowEffect
BlurRadius="35"
Direction="-90"
Opacity="0.9"
RenderingBias="Performance"
ShadowDepth="5"
Color="MediumVioletRed" />
</Border.Effect>
<Grid Margin="3">

<StackPanel
Grid.Row="1"
Grid.Column="1"
Orientation="Horizontal">
<TextBlock
Grid.Row="1"
Grid.Column="0"
Width="auto"
Height="Auto"
Padding="15,15,0,15"
HorizontalAlignment="Stretch"
VerticalAlignment="Center"
Background="Transparent"
FontFamily="Albert Sans Thin"
FontSize="16"
FontWeight="Bold"
Foreground="MediumVioletRed"
Text="{Binding IntelliChatErrorTxt, UpdateSourceTrigger=PropertyChanged}"
TextWrapping="Wrap">
<TextBlock.Effect>
<DropShadowEffect
BlurRadius="20"
Opacity="1"
RenderingBias="Performance"
ShadowDepth="0"
Color="Black" />
</TextBlock.Effect>
</TextBlock>


</StackPanel>

<Button
x:Name="CloseIntelliErrorPanel"
Width="auto"
Padding="6"
HorizontalAlignment="Right"
Click="CloseIntelliErrorPanel_Click"
Opacity="0.8"
Style="{DynamicResource Status_Button_style}">
<Image
Width="18"
RenderOptions.BitmapScalingMode="HighQuality"
Source="/Img/Icons/NotAccept_ico.png" />
</Button>





</Grid>

</Border>
Expand Down
Loading

0 comments on commit a4352c5

Please sign in to comment.