From f33e3c2347f9da38ed67e708ad6e18b3a75f0418 Mon Sep 17 00:00:00 2001 From: BoiHanny <114599052+BoiHanny@users.noreply.github.com> Date: Mon, 29 Jan 2024 13:14:07 +0100 Subject: [PATCH 1/2] The most significant changes were made in `IntelliChatModule.cs` and `MainWindow.xaml.cs`. In `IntelliChatModule.cs`, the method `PerformSpellingAndGrammarCheckAsync` was refactored and new methods were added to handle IntelliChat suggestions and rewrite sentences in a specified style. In `MainWindow.xaml.cs`, methods were updated and added to handle new functionalities related to IntelliChat. 1. `App.xaml`: The fill color of the rectangle named `PART_Indicator` was changed from a solid color to a linear gradient color. 2. `IntelliChatModule.cs`: The method `PerformSpellingAndGrammarCheckAsync` was refactored to use a list of `Message` objects instead of a `StringBuilder`. New methods `PerformBeautifySentenceAsync`, `AcceptIntelliChatSuggestion`, and `RejectIntelliChatSuggestion` were added. Two new enums `SupportedIntelliChatLanguage` and `IntelliChatWritingStyle` were also added. 3. `MagicChatbox.csproj`: Several image files were added to the project as resources. 4. `MainWindow.xaml`: A new grid named `AIResponse` was added to display the IntelliChat response. The spelling check button was updated and a new button was added to rebuild the chat using AI. Several other UI elements were updated. 5. `MainWindow.xaml.cs`: The `SpellingCheck_Click` method was updated to use the new `PerformSpellingAndGrammarCheckAsync` method. New methods `RebuildChat_Click`, `NotAcceptIntelliChat_Click`, and `AcceptIntelliChat_Click` were added. 6. `ViewModel.cs`: New properties were added to represent the IntelliChat writing style, supported languages, IntelliChat text, and whether the user is waiting to accept an IntelliChat suggestion. --- vrcosc-magicchatbox/App.xaml | 10 +- .../Classes/Modules/IntelliChatModule.cs | 104 ++++++- .../Classes/Modules/OpenAIModule.cs | 1 + vrcosc-magicchatbox/Img/Icons/Accept_ico.png | Bin 0 -> 1398 bytes .../Img/Icons/NotAccept_ico.png | Bin 0 -> 1687 bytes vrcosc-magicchatbox/Img/Icons/RebuildChat.png | Bin 0 -> 1368 bytes vrcosc-magicchatbox/MagicChatbox.csproj | 6 + vrcosc-magicchatbox/MainWindow.xaml | 294 ++++++++++++++++-- vrcosc-magicchatbox/MainWindow.xaml.cs | 61 ++-- vrcosc-magicchatbox/ViewModels/ViewModel.cs | 48 +++ 10 files changed, 469 insertions(+), 55 deletions(-) create mode 100644 vrcosc-magicchatbox/Img/Icons/Accept_ico.png create mode 100644 vrcosc-magicchatbox/Img/Icons/NotAccept_ico.png create mode 100644 vrcosc-magicchatbox/Img/Icons/RebuildChat.png diff --git a/vrcosc-magicchatbox/App.xaml b/vrcosc-magicchatbox/App.xaml index 32f2fcd5..f6880ef9 100644 --- a/vrcosc-magicchatbox/App.xaml +++ b/vrcosc-magicchatbox/App.xaml @@ -1012,9 +1012,15 @@ + RadiusY="5" > + + + + + + + diff --git a/vrcosc-magicchatbox/Classes/Modules/IntelliChatModule.cs b/vrcosc-magicchatbox/Classes/Modules/IntelliChatModule.cs index 333c8d7d..179eb07c 100644 --- a/vrcosc-magicchatbox/Classes/Modules/IntelliChatModule.cs +++ b/vrcosc-magicchatbox/Classes/Modules/IntelliChatModule.cs @@ -13,44 +13,108 @@ namespace vrcosc_magicchatbox.Classes.Modules { public class IntelliChatModule { - public static async Task PerformSpellingAndGrammarCheckAsync(string text, List languages = null) + public static async Task PerformSpellingAndGrammarCheckAsync( + string text, + List languages = null) { - 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 + { + 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 { 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 PerformBeautifySentenceAsync( + string text, + IntelliChatWritingStyle writingStyle = IntelliChatWritingStyle.Casual, + List 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 + { + 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, @@ -69,4 +133,16 @@ public enum SupportedIntelliChatLanguage Hindi, Swedish, } + + public enum IntelliChatWritingStyle + { + Casual, + Formal, + Friendly, + Professional, + Academic, + Creative, + Humorous, + British, + } } diff --git a/vrcosc-magicchatbox/Classes/Modules/OpenAIModule.cs b/vrcosc-magicchatbox/Classes/Modules/OpenAIModule.cs index 3b27c6f0..6ce63256 100644 --- a/vrcosc-magicchatbox/Classes/Modules/OpenAIModule.cs +++ b/vrcosc-magicchatbox/Classes/Modules/OpenAIModule.cs @@ -43,6 +43,7 @@ public async Task InitializeClient(string apiKey, string organizationID) ViewModel.Instance.OpenAIConnected = AuthChecked; } + private async Task TestConnection() { try diff --git a/vrcosc-magicchatbox/Img/Icons/Accept_ico.png b/vrcosc-magicchatbox/Img/Icons/Accept_ico.png new file mode 100644 index 0000000000000000000000000000000000000000..4646cc54933171c412eebbbaa86cfccd17799cbc GIT binary patch literal 1398 zcmV-+1&R8JP)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGVU;qFCU;!Z66WRa(1q(?;K~!i%&6)3O zTU8jxlbfz-(&oq7PAU{dHn-uA;U6%hMI5>*=o?oCzOedAsjY6#t`i+Y#V{1-5Jjsm z^o1KDf-h8b*rC(cI#jf@FtupcHEn)0znUiT`#pJ5ZquZ_H#axw2f{tiIhW*{=brOC z&pFrWu)w)9mwR)$l>@2NQXsyxct^gF+ua%L+2`?e_~jM{#$pSR*(;jU^{206`)?SF zx?C;a3_Z7hMs6{UY0(tAyqvy28k^tcc6$f>zRsIu$S|?^!e5z8@-#D5RM#UQvO~LT&>+sAY(p7ihj0=8$*D)i) zHx*66c$^cM2D_xoHt;)B_?`aEgjW?UbN3*cZ(`ngioN!O-%Q~$ywO~*D4K%P>BN(5 zZS5zdtKnoasaM@@&pVZbYjRx!qeC+V69^tlXOa(yxrTL~mT58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ico.png new file mode 100644 index 0000000000000000000000000000000000000000..038977d3758617b0f12de791f3b727a91a630eb7 GIT binary patch literal 1687 zcmV;I259+-P)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGVU;qFCU;!Z66WRa(1}sTLK~!i%)tPHd zTV)u>pK}Vmca(S;Gb>sAK%6ng#0{J-aThkmOqS?2U1p4gSN-#fBM4OQlULCsK0Q^d)^D@-{-vV z^FBPUM0ujBDvdt4nZ6$^r<(15(&=5tU6$zhLCe%+l_43gny}t_U(9H?i|%tUO)1K% z@ZVo2FNew2}62xJDKI-6To*$yu8n3(C6M${(Jwx*f%h?98q1ui7nIwPR8!rCC`*;ep zuw~b19c}__`H_TN;^is!VZ%93fMg?C|ry2dA8B=kYO803 zYobFt9$>eo!u{;yMX+CMDH7lWpi5%O3JV7^b~=eK>~L^vT5XY0l9)c?t7~&f$)vV3 z%e1?S=SPy9lOs3P4=;w0rTh-367;B&fr49hu#sOTdaHZ@8^|y_cAMx|bg({!_1$ea z^KL*64^>l{5^U5X*q|mvsW9}6LoimRj5a=1{tZcQdIwy*gH zzfg-qrzJLVKt?<)>hdPR3xe5-w}b+V2nY-QCum1MaSPUqzf%w#5mw0v;KhBR;MLZq ziW)t9xy@M?H>K|Jh0v~nFN-N9ZVSSYn7&Io`C8W`Cb_69h_pG{Gh;;-)WE;e1;N68 z6vUgUF<)7G}^-w_pIh@E+;0h%PV%SV)G&vw@Y( zYV5bDWD+&{nT_%mgRoq-#b*(7cu53UC8izqFgZImFIM8Y1bTgDBg@NpjT>t<-O1Ua<1Df>heZx zEQlp$tf*O-cSK(_ZPDd&hcn(p&*Hr8`mX~ra%sBMXcuo|hG9K%b;RWO>Hii_2U%yegn!LDA9}HM++NWv z+VTdL(i2|l9moH<9Dj7+s7JQ0y+SPb1h2}FXv-Tt4+eV1!D}Eb+&*$IZ!W=m$lcW( zFvpZrqP-|FPlZl4u+BZJe__!VzSD9E4+JvovNggy)Tuk zo=x>4010iWAtd`m)^x>_kgQ{nbv*I(IZwcG>BgzRY?P-}@E!8O=*R=EY7Hv{o(~<+ zBeAaZM0!SOs-1Cg>*0&9Lik=D_=RX%R)mH3KL6(rpS1XGjZJaJKAqQBYHRu4rPiZ`Q1|fvIt0{ofT2+?F-aWry zke6tHT{HObPWm{qj-GUUOQ-8wT}TEZw}w>Jge|YL@vpSAaSksdrd93OmTh;k@BMu} h(fJ>=jbmYm{sl$o{6)3U?PCA{002ovPDHLkV1gsBI9>n% literal 0 HcmV?d00001 diff --git a/vrcosc-magicchatbox/Img/Icons/RebuildChat.png b/vrcosc-magicchatbox/Img/Icons/RebuildChat.png new file mode 100644 index 0000000000000000000000000000000000000000..0896b02054caccb0cf5c2f279df1c4eb3c0e4b06 GIT binary patch literal 1368 zcmV-e1*iInP)500001b5ch_0Itp) z=>Px#1ZP1_K>z@;j|==^1poj532;bRa{vGizW@LZzX3P}QzQTY1no&gK~z{r?Us9N zlT{dp+jZT#cK1c)5{w2fG5(?cq4Cmqi3%zb7p4<5nKx#X5D~#_5eaBeK?N@Zgm{aI zf}oN~jJGTcL88RFgcu|0Bp^fw-KFi;tzAE#-?!7IUE5LE_>U)fa=!O;UEl9L=e*zN zI7JSeX3U$0+GSIM;lMM6uA+|0^3ylIzP0I)`Dn}>S2B(Dt0oObBm0Wn912ekw`?4$Q5xbezgh5Oy0?;Dh{V}kqMK8`?}}apN#{@QyIUnqi@DCA%vUvsVa(OZE1CXCsK#98 zgvy;|E>D|(1suW5qF!=hQ8A@)}_j)GJc=8;%swmQ(WY2@p&s>HK9$3 zr?fgU5WdxfC&V$E-mDuJtgoq>^sosXk%7KmPqFs`U5EO*cb0l9r`jI?eW-)P{fQ<> zrL?>s;2vDcd{Fbb7_~AgdwFTi{U)^Oj|4a9$E3Tk_&GCeqY4hiW7nEc_^<-Y(5;El z7&RHnKGW?kE;gY}RmB-Um`j$cZ_Wb`Yf6~qj@n$`voq0=r^B}{G*;CZ7L^gE>4z7z0MQ`JJ5s6%7S=Lv4^b+d1b)NBN z+=5Ez7rY@g5s@<)%6+-Hv>6!e53?*^m@tWwYi(ZNDm|E&|Ixk|(R(1W} zOsvPW)*!Mjla?s;RY9->o4NB=6DHWDWcYhGeaE6pKh4}DsEs?4Av}nM=)$M??gqvr zS(9m~UH$-7c*BIb2=Mw)Ti`4RSXSKSbQWk&wBeM_?Sa{-Bdi*sRyFM?B2!#7|I_N$iPd@q28+X{cjjcdsQ% zBqF{;9q}~MlHmkR z6~TIX$pU-Uz;oyy25rWyw6?8HU82Pd`>+?aPt}0xwopTws z&_^y-oS?*0Hu=A!2ej$(K}~WqZpCfbg(K-e9S*gPU3eKLv6G3#1~Xo?6S!QieBa>a zu($3;J(qOURiTj_!2SHq?~JvmY9_Hyla}d7*P&&WH8k0tHLwN|D;{s&-o8HPQe}hx zrwV_JI^OT0_L4TTp74z%v!5}8tQ~l)kjy0vpW@4?oDJwd5RPq aj{gCl7P_CQ7)`PO0000 + @@ -58,10 +59,12 @@ + + @@ -80,6 +83,7 @@ + @@ -110,6 +114,7 @@ + @@ -117,6 +122,7 @@ + diff --git a/vrcosc-magicchatbox/MainWindow.xaml b/vrcosc-magicchatbox/MainWindow.xaml index a6c94387..c7d7e3fb 100644 --- a/vrcosc-magicchatbox/MainWindow.xaml +++ b/vrcosc-magicchatbox/MainWindow.xaml @@ -4220,9 +4220,13 @@ Style="{DynamicResource Status_Button_style}" /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + VerticalAlignment="Center" + Orientation="Horizontal" + RenderOptions.BitmapScalingMode="NearestNeighbor"> + + + +