Skip to content

Commit

Permalink
Merge pull request #36 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 2a7d528 + 2225fd1 commit 715bb7c
Show file tree
Hide file tree
Showing 10 changed files with 473 additions and 59 deletions.
10 changes: 8 additions & 2 deletions vrcosc-magicchatbox/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -1012,9 +1012,15 @@
<Rectangle
x:Name="PART_Indicator"
HorizontalAlignment="Left"
Fill="#26A3FE"
RadiusX="5"
RadiusY="5" />
RadiusY="5" >
<Rectangle.Fill>
<LinearGradientBrush EndPoint="1.5,1" StartPoint="0.5,0">
<GradientStop Color="#FF26A3FE"/>
<GradientStop Color="#FFA326FE" Offset="1"/>
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>

</Border>
</Border>
Expand Down
104 changes: 90 additions & 14 deletions vrcosc-magicchatbox/Classes/Modules/IntelliChatModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,44 +13,108 @@ namespace vrcosc_magicchatbox.Classes.Modules
{
public class IntelliChatModule
{
public static async Task<string> PerformSpellingAndGrammarCheckAsync(string text, List<SupportedIntelliChatLanguage> languages = null)
public static async Task<string> PerformSpellingAndGrammarCheckAsync(
string text,
List<SupportedIntelliChatLanguage> languages = null)

Check warning on line 18 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)
if(!OpenAIModule.Instance.IsInitialized)
{
ViewModel.Instance.ActivateSetting("Settings_OpenAI");
return string.Empty;
}
if(string.IsNullOrWhiteSpace(text))
{
ViewModel.Instance.IntelliChatRequesting = false;
return string.Empty;
}


var promptBuilder = new StringBuilder();
var messages = new List<Message>
{
new Message(
Role.System,
"Please detect and correct any spelling and grammar errors in the following text:")
};

// 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())
if(languages != null && languages.Any())
{
promptBuilder.AppendLine($"Possible languages: {string.Join(", ", languages)}.");
messages.Add(new Message(Role.System, $"Consider these languages: {string.Join(", ", languages)}"));
}
promptBuilder.AppendLine($"Text: \"{text}\"");

string prompt = promptBuilder.ToString();
messages.Add(new Message(Role.User, text));

var response = await OpenAIModule.Instance.OpenAIClient.ChatEndpoint.GetCompletionAsync(
new ChatRequest(messages: new List<Message> { new Message(Role.System, prompt) }, maxTokens: 120));
var response = await OpenAIModule.Instance.OpenAIClient.ChatEndpoint
.GetCompletionAsync(new ChatRequest(messages: messages, maxTokens: 120));

// Check the type of response.Content and convert to string accordingly
if (response?.Choices?[0].Message.Content.ValueKind == JsonValueKind.String)
if(response?.Choices?[0].Message.Content.ValueKind == JsonValueKind.String)
{
return response.Choices[0].Message.Content.GetString();
}
else
} 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 static async Task<string> PerformBeautifySentenceAsync(
string text,
IntelliChatWritingStyle writingStyle = IntelliChatWritingStyle.Casual,
List<SupportedIntelliChatLanguage> languages = null)
{
if(!OpenAIModule.Instance.IsInitialized)
{
ViewModel.Instance.ActivateSetting("Settings_OpenAI");
return string.Empty;
}
if(string.IsNullOrWhiteSpace(text))
{
ViewModel.Instance.IntelliChatRequesting = false;
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())
{
messages.Add(new Message(Role.System, $"Consider these languages: {string.Join(", ", languages)}"));
}

messages.Add(new Message(Role.User, text));

var response = await OpenAIModule.Instance.OpenAIClient.ChatEndpoint
.GetCompletionAsync(new ChatRequest(messages: messages, maxTokens: 120));

if(response?.Choices?[0].Message.Content.ValueKind == JsonValueKind.String)
{
return response.Choices[0].Message.Content.GetString();
} else
{
return response?.Choices?[0].Message.Content.ToString() ?? string.Empty;
}
}

public static void AcceptIntelliChatSuggestion()
{
ViewModel.Instance.NewChattingTxt = ViewModel.Instance.IntelliChatTxt;
ViewModel.Instance.IntelliChatTxt = string.Empty;
ViewModel.Instance.IntelliChatWaitingToAccept = false;
}

public static void RejectIntelliChatSuggestion()
{
ViewModel.Instance.IntelliChatTxt = string.Empty;
ViewModel.Instance.IntelliChatWaitingToAccept = false;
}


}


public enum SupportedIntelliChatLanguage
{
English,
Expand All @@ -69,4 +133,16 @@ public enum SupportedIntelliChatLanguage
Hindi,
Swedish,
}

public enum IntelliChatWritingStyle
{
Casual,
Formal,
Friendly,
Professional,
Academic,
Creative,
Humorous,
British,
}
}
1 change: 1 addition & 0 deletions vrcosc-magicchatbox/Classes/Modules/OpenAIModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public async Task InitializeClient(string apiKey, string organizationID)
ViewModel.Instance.OpenAIConnected = AuthChecked;
}


private async Task TestConnection()
{
try
Expand Down
Binary file added vrcosc-magicchatbox/Img/Icons/Accept_ico.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vrcosc-magicchatbox/Img/Icons/NotAccept_ico.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vrcosc-magicchatbox/Img/Icons/RebuildChat.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 10 additions & 4 deletions 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.745</Version>
<Version>0.8.750</Version>
<TargetFramework>net6.0-windows10.0.22000.0</TargetFramework>
<RootNamespace>vrcosc_magicchatbox</RootNamespace>
<Nullable>enable</Nullable>
Expand Down Expand Up @@ -36,6 +36,7 @@
</PropertyGroup>

<ItemGroup>
<None Remove="Img\Icons\Accept_ico.png" />
<None Remove="Img\Icons\ActivatedStatus_ico.png" />
<None Remove="Img\Icons\ActivateStatus_ico.png" />
<None Remove="Img\Icons\admin.png" />
Expand All @@ -58,10 +59,12 @@
<None Remove="Img\Icons\Min_ico.png" />
<None Remove="Img\Icons\NetworkStats_ico.png" />
<None Remove="Img\Icons\Next_ico.png" />
<None Remove="Img\Icons\NotAccept_ico.png" />
<None Remove="Img\Icons\OpenAI.png" />
<None Remove="Img\Icons\PersonalMsg_ico.png" />
<None Remove="Img\Icons\Plus_ico.png" />
<None Remove="Img\Icons\Pulsoid.png" />
<None Remove="Img\Icons\RebuildChat.png" />
<None Remove="Img\Icons\SaveDark.png" />
<None Remove="Img\Icons\SaveLight.png" />
<None Remove="Img\Icons\Settings_ico.png" />
Expand All @@ -80,6 +83,7 @@
</ItemGroup>

<ItemGroup>
<Resource Include="Img\Icons\Accept_ico.png" />
<Resource Include="Img\Icons\ActivatedStatus_ico.png">
<CopyToOutputDirectory></CopyToOutputDirectory>
</Resource>
Expand Down Expand Up @@ -110,13 +114,15 @@
<Resource Include="Img\Icons\MediaLink_ico.png" />
<Resource Include="Img\Icons\Min_ico.png" />
<Resource Include="Img\Icons\Next_ico.png" />
<Resource Include="Img\Icons\NotAccept_ico.png" />
<Resource Include="Img\Icons\OpenAI.png" />
<Resource Include="Img\Icons\PersonalMsg_ico.png">
<CopyToOutputDirectory></CopyToOutputDirectory>
</Resource>
<Resource Include="Img\Icons\HeartRate_ico.png" />
<Resource Include="Img\Icons\Plus_ico.png" />
<Resource Include="Img\Icons\Pulsoid.png" />
<Resource Include="Img\Icons\RebuildChat.png" />
<Resource Include="Img\Icons\SaveDark.png" />
<Resource Include="Img\Icons\SaveLight.png" />
<Resource Include="Img\Icons\Soundpad.png" />
Expand Down Expand Up @@ -151,13 +157,13 @@

<ItemGroup>
<PackageReference Include="Dubya.WindowsMediaController" Version="2.5.3" />
<PackageReference Include="LibreHardwareMonitorLib" Version="0.9.4-pre267" />
<PackageReference Include="LibreHardwareMonitorLib" Version="0.9.4-pre268" />
<PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.77" />
<PackageReference Include="NAudio" Version="2.2.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="NHotkey.Wpf" Version="2.1.1" />
<PackageReference Include="NHotkey.Wpf" Version="3.0.0" />
<PackageReference Include="NLog" Version="5.2.8" />
<PackageReference Include="OpenAI-DotNet" Version="7.6.2" />
<PackageReference Include="OpenAI-DotNet" Version="7.6.4" />
</ItemGroup>

<ItemGroup>
Expand Down
Loading

0 comments on commit 715bb7c

Please sign in to comment.