Skip to content

Commit

Permalink
Merge pull request #39 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 c5a5059 + c469969 commit af4ae2f
Show file tree
Hide file tree
Showing 9 changed files with 372 additions and 6 deletions.
8 changes: 4 additions & 4 deletions vrcosc-magicchatbox/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -1013,11 +1013,11 @@
x:Name="PART_Indicator"
HorizontalAlignment="Left"
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 StartPoint="0.5,0" EndPoint="1.5,1">
<GradientStop Color="#FF26A3FE" />
<GradientStop Offset="1" Color="#FFA326FE" />
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
Expand Down
109 changes: 108 additions & 1 deletion vrcosc-magicchatbox/Classes/Modules/IntelliChatModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static async Task<string> PerformSpellingAndGrammarCheckAsync(
{
new Message(
Role.System,
"Please detect and correct any spelling and grammar errors in the following text:")
"Please detect and correct and return any spelling and grammar errors in the following text:")
};

if(languages != null && languages.Any() && !ViewModel.Instance.IntelliChatAutoLang)
Expand Down Expand Up @@ -113,6 +113,113 @@ public static async Task<string> PerformBeautifySentenceAsync(
}
}

public static async Task<string> GenerateConversationStarterAsync()
{
if (!OpenAIModule.Instance.IsInitialized)
{
ViewModel.Instance.ActivateSetting("Settings_OpenAI");
return "OpenAI not initialized.";
}

var prompt = "Please generate a short a creative and engaging conversation starter of max 140 characters (this includes spaces), avoid AI. no '";

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

return response?.Choices?[0].Message.Content.ValueKind == JsonValueKind.String
? response.Choices[0].Message.Content.GetString()
: "Unable to generate conversation starter.";
}

public static async Task<string> ShortenTextAsync(string text, int retryCount = 0)
{
if (!OpenAIModule.Instance.IsInitialized)
{
ViewModel.Instance.ActivateSetting("Settings_OpenAI");
return "OpenAI not initialized.";
}

if (string.IsNullOrWhiteSpace(text))
{
ViewModel.Instance.IntelliChatRequesting = false;
return string.Empty;
}

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

string prompt = retryCount == 0
? $"Shorten the following text to 140 characters or less, including spaces: {text}"
: $"Please be more concise. Shorten this text to 140 characters or less, including spaces: {text}";

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

var shortenedText = response?.Choices?[0].Message.Content.ValueKind == JsonValueKind.String
? response.Choices[0].Message.Content.GetString()
: string.Empty;

// Check if the response is still over 140 characters and retry if necessary
if (shortenedText.Length > 140 && retryCount < 1) // Limiting to one retry
{
return await ShortenTextAsync(shortenedText, retryCount + 1);
}
else
{
return shortenedText.Length <= 140 ? shortenedText : string.Empty;
}
}



public static async Task<string> PerformLanguageTranslationAutoDetectAsync(
string text,
SupportedIntelliChatLanguage targetLanguage = SupportedIntelliChatLanguage.English)
{
if (!OpenAIModule.Instance.IsInitialized)
{
ViewModel.Instance.ActivateSetting("Settings_OpenAI");
return string.Empty;
}

if (string.IsNullOrWhiteSpace(text))
{
ViewModel.Instance.IntelliChatRequesting = false;
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, $"Translate this to {targetLanguage}:"),
new Message(Role.User, text)
};

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

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


public static void AcceptIntelliChatSuggestion()
{
ViewModel.Instance.NewChattingTxt = ViewModel.Instance.IntelliChatTxt;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;

namespace vrcosc_magicchatbox.Classes
{
public class CharacterCountToBoolConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
int characterCount = (int)value;
return characterCount > 140;
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
Binary file added vrcosc-magicchatbox/Img/Icons/Cut_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/Translate_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/Wand_ico.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 7 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.756</Version>
<Version>0.8.757</Version>
<TargetFramework>net6.0-windows10.0.22000.0</TargetFramework>
<RootNamespace>vrcosc_magicchatbox</RootNamespace>
<Nullable>enable</Nullable>
Expand Down Expand Up @@ -45,6 +45,7 @@
<None Remove="Img\Icons\Copy_ico.png" />
<None Remove="Img\Icons\Cross_ico.png" />
<None Remove="Img\Icons\Cross_v1_ico.png" />
<None Remove="Img\Icons\Cut_ico.png" />
<None Remove="Img\Icons\Delete_ico.png" />
<None Remove="Img\Icons\Discord.png" />
<None Remove="Img\Icons\Edit_ico.png" />
Expand Down Expand Up @@ -73,8 +74,10 @@
<None Remove="Img\Icons\spotify_ico.png" />
<None Remove="Img\Icons\subtract_ico.png" />
<None Remove="Img\Icons\SystemTime_ico.png" />
<None Remove="Img\Icons\Translate_ico.png" />
<None Remove="Img\Icons\Unfavorite_ico.png" />
<None Remove="Img\Icons\Upload.png" />
<None Remove="Img\Icons\Wand_ico.png" />
<None Remove="Img\Icons\WindowActivity_ico.png" />
<None Remove="Img\Icons\yes.png" />
<None Remove="Img\MagicOSC_icon.png" />
Expand All @@ -98,6 +101,7 @@
<Resource Include="Img\Icons\Copy_ico.png" />
<Resource Include="Img\Icons\Cross_ico.png" />
<Resource Include="Img\Icons\Cross_v1_ico.png" />
<Resource Include="Img\Icons\Cut_ico.png" />
<Resource Include="Img\Icons\Delete_ico.png">
<CopyToOutputDirectory></CopyToOutputDirectory>
</Resource>
Expand Down Expand Up @@ -136,10 +140,12 @@
<Resource Include="Img\Icons\SystemTime_ico.png">
<CopyToOutputDirectory></CopyToOutputDirectory>
</Resource>
<Resource Include="Img\Icons\Translate_ico.png" />
<Resource Include="Img\Icons\Unfavorite_ico.png">
<CopyToOutputDirectory></CopyToOutputDirectory>
</Resource>
<Resource Include="Img\Icons\Upload.png" />
<Resource Include="Img\Icons\Wand_ico.png" />
<Resource Include="Img\Icons\WindowActivity_ico.png">
<CopyToOutputDirectory></CopyToOutputDirectory>
</Resource>
Expand Down
148 changes: 148 additions & 0 deletions vrcosc-magicchatbox/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<Window.Resources>
<ResourceDictionary>
<local:CountToVisibilityConverter x:Key="CountToVisibilityConverter" />
<local:CharacterCountToBoolConverter x:Key="CharacterCountToBoolConverter" />
<local:BoolToBlurEffectConverter x:Key="BoolToBlurEffectConverter" />
<local:InverseBoolToVisibilityConverter x:Key="InverseBoolToVisibilityConverter" />
<local:InverseBoolToHiddenConverter x:Key="InverseBoolToHiddenConverter" />
Expand All @@ -57,6 +58,17 @@
</Setter.Value>
</Setter>
</Style>
<Style x:Key="CharacterCountTextStyle" TargetType="TextBlock">
<Setter Property="Foreground" Value="#94CCBF" />
<Setter Property="Opacity" Value="0.3" />
<Style.Triggers>
<DataTrigger Binding="{Binding IntelliChatTxt.Length, Converter={StaticResource CharacterCountToBoolConverter}}" Value="True">
<Setter Property="Foreground" Value="PaleVioletRed" />
<Setter Property="Opacity" Value="1" />
</DataTrigger>
</Style.Triggers>
</Style>

<SolidColorBrush x:Key="Button.Static.Background" Color="#FFDDDDDD" />
<SolidColorBrush x:Key="Button.Static.Border" Color="#FF707070" />
<SolidColorBrush x:Key="Button.MouseOver.Background" Color="#FFBEE6FD" />
Expand Down Expand Up @@ -4623,6 +4635,37 @@
Foreground="#94CCBF"
Opacity="0.3"
Text="n/a" />
<TextBlock
Width="auto"
Height="Auto"
Padding="5,10,0,15"
HorizontalAlignment="Stretch"
VerticalAlignment="Center"
FontFamily="Albert Sans Thin"
FontSize="12"
Style="{StaticResource CharacterCountTextStyle}"
Text="Characters:" />
<TextBlock
Width="auto"
Height="Auto"
Padding="5,10,0,15"
HorizontalAlignment="Stretch"
VerticalAlignment="Center"
FontFamily="Albert Sans Thin"
FontSize="12"
Style="{StaticResource CharacterCountTextStyle}"
Text="{Binding IntelliChatTxt.Length, UpdateSourceTrigger=PropertyChanged}" />
<TextBlock
Width="auto"
Height="Auto"
Padding="0,10,0,15"
HorizontalAlignment="Stretch"
VerticalAlignment="Center"
FontFamily="Albert Sans Thin"
FontSize="12"
Style="{StaticResource CharacterCountTextStyle}"
Text="/144" />


</StackPanel>
<TextBlock
Expand Down Expand Up @@ -4876,6 +4919,111 @@
Color="LightGray" />
</Button.Effect>
</Button>
<Button
x:Name="TranslateChat"
Width="auto"
Height="34"
Margin="3,0"
Click="TranslateChat_click"
Style="{DynamicResource LINK_Button_style}"
ToolTip="Translate anything to English by AI"
WindowChrome.IsHitTestVisibleInChrome="True">
<StackPanel Orientation="Horizontal" RenderOptions.BitmapScalingMode="HighQuality">
<Image
Width="25"
Margin="3,0,0,0"
Opacity="0.5"
Source="/Img/Icons/Translate_ico.png" />
<TextBlock
Padding="3,0"
VerticalAlignment="Center"
FontFamily="Albert Sans Thin"
FontSize="13"
Foreground="#FF8D7DB9"
RenderOptions.BitmapScalingMode="NearestNeighbor"
Text="Translate" />

</StackPanel>
<Button.Effect>
<DropShadowEffect
BlurRadius="15"
Direction="0"
Opacity="0.3"
RenderingBias="Performance"
ShadowDepth="0"
Color="LightGray" />
</Button.Effect>
</Button>
<Button
x:Name="ShortenChat"
Width="auto"
Height="34"
Margin="3,0"
Click="ShortenChat_Click"
Style="{DynamicResource LINK_Button_style}"
ToolTip="Shorten chat by AI"
WindowChrome.IsHitTestVisibleInChrome="True">
<StackPanel Orientation="Horizontal" RenderOptions.BitmapScalingMode="HighQuality">
<Image
Width="25"
Margin="3,0,0,0"
Opacity="0.5"
Source="/Img/Icons/Cut_ico.png" />
<TextBlock
Padding="3,0"
VerticalAlignment="Center"
FontFamily="Albert Sans Thin"
FontSize="13"
Foreground="#FF8D7DB9"
RenderOptions.BitmapScalingMode="NearestNeighbor"
Text="Shorten" />

</StackPanel>
<Button.Effect>
<DropShadowEffect
BlurRadius="15"
Direction="0"
Opacity="0.3"
RenderingBias="Performance"
ShadowDepth="0"
Color="LightGray" />
</Button.Effect>
</Button>
<Button
x:Name="ConvoStarterChat"
Width="auto"
Height="34"
Margin="3,0"
Click="ConvoStarterChat_Click"
Style="{DynamicResource LINK_Button_style}"
ToolTip="Start a conversation by AI"
WindowChrome.IsHitTestVisibleInChrome="True">
<StackPanel Orientation="Horizontal" RenderOptions.BitmapScalingMode="HighQuality">
<Image
Width="22"
Margin="3,0,0,0"
Opacity="0.5"
Source="/Img/Icons/Wand_ico.png" />
<TextBlock
Padding="3,0"
VerticalAlignment="Center"
FontFamily="Albert Sans Thin"
FontSize="13"
Foreground="#FF8D7DB9"
RenderOptions.BitmapScalingMode="NearestNeighbor"
Text="Convo starter" />

</StackPanel>
<Button.Effect>
<DropShadowEffect
BlurRadius="15"
Direction="0"
Opacity="0.3"
RenderingBias="Performance"
ShadowDepth="0"
Color="LightGray" />
</Button.Effect>
</Button>
</StackPanel>
<TextBlock
Padding="0,0,15,0"
Expand Down
Loading

0 comments on commit af4ae2f

Please sign in to comment.