diff --git a/App.xaml.cs b/App.xaml.cs index dd1323d..e7e69c9 100644 --- a/App.xaml.cs +++ b/App.xaml.cs @@ -39,7 +39,7 @@ namespace GTPCorrgir } // Muestra notificación inicial y comienza el cronómetro en el hilo de la UI - ShowCustomNotification("Espera", "Corrigiendo texto..."); + ShowCustomNotification("Espera", $"Corrigiendo texto con .{Opciones.Instance.nombreDeLLM()} .."); IniciarCronometro(); @@ -118,7 +118,7 @@ namespace GTPCorrgir if (!CorreccionFinalizada) { //notificacion.BalloonTipText = $"Texto en {GTP.IdiomaDetectado} pasados: {Math.Round(stopwatch.ElapsedMilliseconds/1000.0,1)} s"; //notificacion.ShowBalloonTip(1000); - ShowCustomNotification("Trabajando..", $"Texto en {GTP.IdiomaDetectado} pasados: {Math.Round(stopwatch.ElapsedMilliseconds / 1000.0, 1)} s"); + ShowCustomNotification($"{Opciones.Instance.nombreDeLLM()} Trabajando..", $"Texto en {GTP.IdiomaDetectado} pasados: {Math.Round(stopwatch.ElapsedMilliseconds / 1000.0, 1)} s"); } } diff --git a/GTPCorrgir.csproj b/GTPCorrgir.csproj index b3a4eae..0153b3d 100644 --- a/GTPCorrgir.csproj +++ b/GTPCorrgir.csproj @@ -7,6 +7,7 @@ enable true true + GTPCorrgir.Program diff --git a/Obsidean.cs b/Obsidean.cs index 5c9fafe..416c193 100644 --- a/Obsidean.cs +++ b/Obsidean.cs @@ -92,6 +92,22 @@ namespace GTPCorrgir return word; // Devolver la palabra sin modificar si no es técnica }); } + + public string MarkTechnicalTerms_IgnoreCase(string text) + { + // Utilizar Regex para identificar palabras individualmente, ignorando mayúsculas y minúsculas + return Regex.Replace(text, @"\b(\w+)\b", match => + { + string word = match.Groups[1].Value; + // Verificar si la palabra está en el conjunto de términos técnicos, ignorando mayúsculas y minúsculas + if (technicalTerms.Contains(word, StringComparer.OrdinalIgnoreCase)) + { + return $"[[{word}]]"; // Encerrar la palabra en corchetes si es técnica + } + return word; // Devolver la palabra sin modificar si no es técnica + }, RegexOptions.IgnoreCase); + } + } } diff --git a/Program.cs b/Program.cs new file mode 100644 index 0000000..8b744c3 --- /dev/null +++ b/Program.cs @@ -0,0 +1,79 @@ +using GTPCorrgir; +using System; +using System.Configuration; +using System.Windows; + + +namespace GTPCorrgir +{ + + public class Opciones + { + public enum LLM_a_Usar + { + OpenAI, + Ollama, + Groq + } + private Dictionary nombreLLM = new Dictionary + { + { Opciones.LLM_a_Usar.Ollama, "Ollama" }, + { Opciones.LLM_a_Usar.Groq, "Groq" }, + { Opciones.LLM_a_Usar.OpenAI, "OpenAI" }, + + }; + + private static Opciones _instance; + + public static Opciones Instance + { + get + { + if (_instance == null) + { + _instance = new Opciones(); + } + return _instance; + } + } + + public LLM_a_Usar LLM { get; set; } + + public string nombreDeLLM() { + return nombreLLM[LLM]; + } + + private Opciones() { } + } + + + public class Program + { + [STAThread] + public static void Main(string[] args) + { + var application = new App(); + + // Aquí puedes procesar los argumentos + foreach (var arg in args) + { + if (arg.StartsWith("--")) + { + // Procesa el argumento según tus necesidades + if (arg.StartsWith("--Ollama")) + Opciones.Instance.LLM = Opciones.LLM_a_Usar.Ollama; + else if (arg.StartsWith("--Groq")) + Opciones.Instance.LLM = Opciones.LLM_a_Usar.Groq; + else + Opciones.Instance.LLM = Opciones.LLM_a_Usar.OpenAI; + + } + } + + application.Run(); + } + } +} + + + diff --git a/gtpask.cs b/gtpask.cs index c8b9307..f05a3bb 100644 --- a/gtpask.cs +++ b/gtpask.cs @@ -12,12 +12,7 @@ using System.Diagnostics; namespace GTPCorrgir { - public enum LLM_a_Usar - { - OpenAI, - Ollama, - Groq - } + internal class gtpask { private readonly string openAiApiKey = "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"; @@ -36,13 +31,13 @@ namespace GTPCorrgir public string TextoACorregir; public string TextoCorregido; public string TextodeSistema; - private const bool Simulacion = true; - private const LLM_a_Usar LLM = LLM_a_Usar.Groq; + private const bool Simulacion = false; + private string CrearMensajeDeSistema() { - return "You are an engineer working in industrial automation. Your task is to review and rewrite texts in a simple and concise manner, making sure to preserve all important technical terms and maintain any Markdown formatting such as headers, lists, code blocks, and links. Please rewrite the following text in " + IdiomaDetectado + " and respond in the following JSON format: { 'Rewritten_text': 'Your text here' }."; + return "You are an engineer working in industrial automation. Your task is to review texts and rewrite them in a simple and concise manner, making sure to preserve important technical terms and markdown language if present. Please rewrite the following text in " + IdiomaDetectado + " and respond in the following JSON format: { 'Rewritten_text': 'Your text here' }."; } private string CrearMensajeDeUsuario(string texto) @@ -95,16 +90,17 @@ namespace GTPCorrgir var md = new Obsidean(); md.LeerPalabrasTecnicas(); - TextoACorregir = md.MarkTechnicalTerms(TextoACorregir); + TextoACorregir = md.MarkTechnicalTerms_IgnoreCase(TextoACorregir); Log.Log("Texto marcado: " + TextoACorregir); - string RespuestaLLM; + string RespuestaLLM = ""; + if (!Simulacion) { - if (LLM == LLM_a_Usar.OpenAI) RespuestaLLM = await CallOpenAiApi(TextoACorregir); - if (LLM == LLM_a_Usar.Ollama) RespuestaLLM = await CallOllamaApi(TextoACorregir); - if (LLM == LLM_a_Usar.Groq) RespuestaLLM = await CallGroqAiApi(TextoACorregir); + if (Opciones.Instance.LLM == Opciones.LLM_a_Usar.OpenAI) RespuestaLLM = await CallOpenAiApi(TextoACorregir); + if (Opciones.Instance.LLM == Opciones.LLM_a_Usar.Ollama) RespuestaLLM = await CallOllamaApi(TextoACorregir); + if (Opciones.Instance.LLM == Opciones.LLM_a_Usar.Groq) RespuestaLLM = await CallGroqAiApi(TextoACorregir); } else { await Task.Delay(1000); @@ -113,7 +109,7 @@ namespace GTPCorrgir Log.Log("Respuesta: " + RespuestaLLM); - TextoCorregido = ExtractCorrectedText(RespuestaLLM); + TextoCorregido = ExtractCorrectedText_UsingJObject(RespuestaLLM); // Elimina comillas al principio y al final si existen TextoCorregido = TextoCorregido.Trim('\"'); @@ -146,7 +142,7 @@ namespace GTPCorrgir catch (Exception ex) { Console.WriteLine("An error occurred: " + ex.Message); - return null; + return input; } } @@ -166,8 +162,15 @@ namespace GTPCorrgir // Extrae solo la parte JSON de la entrada string jsonString = input.Substring(startJson, endJson - startJson); - // Encuentra el índice del inicio y del final del texto a extraer - int startText = jsonString.IndexOf('\'') + 1; + // Busca el inicio del texto después de "Rewritten_text':" + int startKey = jsonString.IndexOf("'Rewritten_text':") + 17; // 17 es la longitud de "'Rewritten_text':" + if (startKey == -1) + { + throw new Exception("Key 'Rewritten_text' not found."); + } + + // Ajusta para encontrar el inicio del texto después de las comillas simples adicionales + int startText = jsonString.IndexOf('\'', startKey) + 1; int endText = jsonString.LastIndexOf('\''); if (startText == -1 || endText == -1 || endText <= startText) @@ -198,7 +201,7 @@ namespace GTPCorrgir var requestData = new { - model = "llama3", + model = "phi3", //"llama3", messages = new[] { new { role = "system", content = Mensaje_Sistema }, @@ -294,7 +297,9 @@ namespace GTPCorrgir { new { role = "system", content = Mensaje_Sistema }, new { role = "user", content = Mensaje_Usuario } - } + }, + max_tokens = 2048, + stream = false }; var content = new StringContent(JsonConvert.SerializeObject(requestData), Encoding.UTF8, "application/json");