Skip to content

Commit

Permalink
Merge pull request #35 from BoiHanny/Dev-Master
Browse files Browse the repository at this point in the history
Dev master
  • Loading branch information
BoiHanny authored Jan 26, 2024
2 parents abc1817 + f147f61 commit 2a7d528
Show file tree
Hide file tree
Showing 10 changed files with 353 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,6 @@ public static void LoadStatusList()
return;
}
ViewModel.Instance.StatusList = JsonConvert.DeserializeObject<ObservableCollection<StatusItem>>(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;
Expand Down
72 changes: 72 additions & 0 deletions vrcosc-magicchatbox/Classes/Modules/IntelliChatModule.cs
Original file line number Diff line number Diff line change
@@ -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<string> PerformSpellingAndGrammarCheckAsync(string text, List<SupportedIntelliChatLanguage> languages = null)

Check warning on line 16 in vrcosc-magicchatbox/Classes/Modules/IntelliChatModule.cs

View workflow job for this annotation

GitHub Actions / build-and-release

Cannot convert null literal to non-nullable reference type.
{
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<Message> { 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,
}
}
2 changes: 1 addition & 1 deletion vrcosc-magicchatbox/Classes/Modules/OpenAIModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class OpenAIModule


private static readonly Lazy<OpenAIModule> instance = new Lazy<OpenAIModule>(() => 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;
Expand Down
Binary file added vrcosc-magicchatbox/Img/Icons/SpellingCheck.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 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.740</Version>
<Version>0.8.745</Version>
<TargetFramework>net6.0-windows10.0.22000.0</TargetFramework>
<RootNamespace>vrcosc_magicchatbox</RootNamespace>
<Nullable>enable</Nullable>
Expand Down Expand Up @@ -66,6 +66,7 @@
<None Remove="Img\Icons\SaveLight.png" />
<None Remove="Img\Icons\Settings_ico.png" />
<None Remove="Img\Icons\Soundpad.png" />
<None Remove="Img\Icons\SpellingCheck.png" />
<None Remove="Img\Icons\spotify_ico.png" />
<None Remove="Img\Icons\subtract_ico.png" />
<None Remove="Img\Icons\SystemTime_ico.png" />
Expand Down Expand Up @@ -119,6 +120,7 @@
<Resource Include="Img\Icons\SaveDark.png" />
<Resource Include="Img\Icons\SaveLight.png" />
<Resource Include="Img\Icons\Soundpad.png" />
<Resource Include="Img\Icons\SpellingCheck.png" />
<Resource Include="Img\Icons\spotify_ico.png">
<CopyToOutputDirectory></CopyToOutputDirectory>
</Resource>
Expand Down
104 changes: 89 additions & 15 deletions vrcosc-magicchatbox/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
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}"
Expand Down Expand Up @@ -4002,6 +4004,55 @@
<RowDefinition Height="40" />
<RowDefinition Height="60" />
</Grid.RowDefinitions>
<Border
Margin="3"
BorderThickness="0"
CornerRadius="5">
<Border.Background>
<LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
<LinearGradientBrush.RelativeTransform>
<TransformGroup>
<ScaleTransform CenterX="0.5" CenterY="0.5" />
<SkewTransform CenterX="0.5" CenterY="0.5" />
<RotateTransform Angle="90" CenterX="0.5" CenterY="0.5" />
<TranslateTransform />
</TransformGroup>
</LinearGradientBrush.RelativeTransform>
<GradientStop Color="#FFC950EF" />
<GradientStop Offset="1" Color="#FFA550EF" />
</LinearGradientBrush>
</Border.Background>

<Border.Style>
<Style TargetType="Border">
<Style.Triggers>
<DataTrigger Binding="{Binding ChatTopBarTxt.Length}" Value="0">
<Setter Property="Visibility" Value="Collapsed" />
</DataTrigger>
</Style.Triggers>
</Style>
</Border.Style>
<TextBlock
Grid.Column="0"
Margin="4"
Padding="4,0,50,0"
HorizontalAlignment="Left"
VerticalAlignment="Center"
d:Text="You're soaring past the 140 char limit by {overmax}."
FontFamily="Albert Sans Thin"
FontSize="14"
Foreground="#FFF3E8FF"
Text="{Binding ChatTopBarTxt}">
<TextBlock.Effect>
<DropShadowEffect
BlurRadius="5"
Direction="-23"
RenderingBias="Performance"
ShadowDepth="0"
Color="DarkBlue" />
</TextBlock.Effect>
</TextBlock>
</Border>

<Grid
Grid.Row="4"
Expand Down Expand Up @@ -4100,6 +4151,14 @@
ShadowDepth="5"
Color="#FF7F759A" />
</Grid.Effect>
<TextBlock
Margin="8,0,0,0"
VerticalAlignment="Center"
d:Text="Chat feedback"
FontFamily="Albert Sans Thin"
FontSize="16"
Foreground="#FF9983AD"
Text="{Binding ChatFeedbackTxt}" />
<StackPanel
HorizontalAlignment="Stretch"
Orientation="Horizontal"
Expand Down Expand Up @@ -4355,30 +4414,45 @@
ShadowDepth="5"
Color="#FF7F759A" />
</Grid.Effect>
<StackPanel Orientation="Horizontal">
<TextBlock
Grid.Column="0"
Margin="10,0,0,0"
Padding="0,0,50,0"
HorizontalAlignment="Left"
VerticalAlignment="Center"
FontFamily="Albert Sans Thin"
FontSize="16"
Foreground="#FF9983AD"
Text="{Binding ChatTopBarTxt}" />
<StackPanel
Margin="17,0,0,0"
HorizontalAlignment="Left"
VerticalAlignment="Center">
<Button
x:Name="SpellingCheck"
Width="35"
ToolTip="Spelling check by AI"
Height="35"
Click="SpellingCheck_Click"
RenderOptions.BitmapScalingMode="NearestNeighbor"
Style="{DynamicResource LINK_Button_style}"
WindowChrome.IsHitTestVisibleInChrome="True">
<StackPanel Orientation="Horizontal">
<Image Width="20" Source="/Img/Icons/SpellingCheck.png" />
</StackPanel>
<Button.Effect>
<DropShadowEffect
BlurRadius="15"
Direction="0"
Opacity="0.3"
RenderingBias="Performance"
ShadowDepth="0"
Color="LightGray" />
</Button.Effect>
</Button>
</StackPanel>
<TextBlock
Grid.Column="0"
Margin="0,0,16,0"
HorizontalAlignment="Right"
VerticalAlignment="Center"
FontFamily="Albert Sans Thin"
FontSize="16"
Padding="0,0,15,0"
Foreground="#FF9983AD"
Text="{Binding ChatFeedbackTxt}" />

Text="Requesting..."
Visibility="{Binding IntelliChatRequesting, Converter={StaticResource InverseBoolToHiddenConverter}, UpdateSourceTrigger=PropertyChanged}" />
</Grid>
</Grid>

<Grid Margin="-10,0,0,0" Visibility="{Binding Char_Limit}">
<Grid.Background>
<LinearGradientBrush StartPoint="0,0" EndPoint="1,1">
Expand Down
46 changes: 43 additions & 3 deletions vrcosc-magicchatbox/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;

}

Expand Down Expand Up @@ -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;
});
}
}



}
}
Loading

0 comments on commit 2a7d528

Please sign in to comment.