-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from BoiHanny/Dev-Master
Dev master
- Loading branch information
Showing
10 changed files
with
353 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
{ | ||
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, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.