diff --git a/App.xaml.cs b/App.xaml.cs
index e7e69c9..2440eb5 100644
--- a/App.xaml.cs
+++ b/App.xaml.cs
@@ -31,53 +31,61 @@ namespace GTPCorrgir
{
base.OnStartup(e);
- stopwatch.Start();
-
if (System.Windows.Clipboard.ContainsText())
{
GTP.TextoACorregir = System.Windows.Clipboard.GetText();
}
- // Muestra notificación inicial y comienza el cronómetro en el hilo de la UI
- ShowCustomNotification("Espera", $"Corrigiendo texto con .{Opciones.Instance.nombreDeLLM()} ..");
- IniciarCronometro();
-
-
- // Ejecuta la tarea de corrección en un hilo secundario
- Task.Run(async () =>
+ if (Opciones.Instance.modo == Opciones.modoDeUso.Corregir)
{
- try
+
+ stopwatch.Start();
+
+ // Muestra notificación inicial y comienza el cronómetro en el hilo de la UI
+ ShowCustomNotification("Espera", $"Corrigiendo texto con .{Opciones.Instance.nombreDeLLM()} ..");
+ IniciarCronometro();
+
+
+ // Ejecuta la tarea de corrección en un hilo secundario
+ Task.Run(async () =>
{
- await GTP.CorregirTexto();
- }
- catch (Exception ex)
- {
- Console.WriteLine("Error durante la corrección de texto: " + ex.Message);
- }
- finally
- {
- Dispatcher.Invoke(async () => // Nota el 'async' aquí para permitir 'await'
+ try
{
- CorreccionFinalizada = true;
- DetenerCronometro();
- if (GTP.TextoCorregido != null)
+ await GTP.CorregirTexto();
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine("Error durante la corrección de texto: " + ex.Message);
+ }
+ finally
+ {
+ Dispatcher.Invoke(async () => // Nota el 'async' aquí para permitir 'await'
{
- System.Windows.Clipboard.SetText(GTP.TextoCorregido);
- ShowCustomNotification("Se puede pegar", $"Corrección en : {Math.Round(stopwatch.ElapsedMilliseconds / 1000.0, 1)} s");
+ CorreccionFinalizada = true;
+ DetenerCronometro();
+ if (GTP.TextoCorregido != null)
+ {
+ System.Windows.Clipboard.SetText(GTP.TextoCorregido);
+ ShowCustomNotification("Se puede pegar", $"Corrección en : {Math.Round(stopwatch.ElapsedMilliseconds / 1000.0, 1)} s");
- var resultadoWindow = new VentanaResultado(GTP.TextoCorregido);
- resultadoWindow.Show();
+ var resultadoWindow = new VentanaResultado(GTP.TextoCorregido);
+ resultadoWindow.Show();
- await Task.Delay(5000); // Asíncrono espera 5 segundos
- }
- else
- {
- MostrarNotificacion("Error", "No se pudo corregir el texto.");
- Application.Current.Shutdown();
- }
- });
- }
- });
+ await Task.Delay(5000); // Asíncrono espera 5 segundos
+ }
+ else
+ {
+ MostrarNotificacion("Error", "No se pudo corregir el texto.");
+ Application.Current.Shutdown();
+ }
+ });
+ }
+ });
+ } else if (Opciones.Instance.modo == Opciones.modoDeUso.Chat)
+ {
+ var chatWindows = new Chat(GTP);
+ chatWindows.Show();
+ }
}
diff --git a/Chat.xaml b/Chat.xaml
new file mode 100644
index 0000000..562f9cd
--- /dev/null
+++ b/Chat.xaml
@@ -0,0 +1,60 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Chat.xaml.cs b/Chat.xaml.cs
new file mode 100644
index 0000000..6dc16ed
--- /dev/null
+++ b/Chat.xaml.cs
@@ -0,0 +1,140 @@
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Shapes;
+using static GTPCorrgir.Opciones;
+using static System.Net.WebRequestMethods;
+using ComboBox = System.Windows.Controls.ComboBox;
+using Cursors = System.Windows.Input.Cursors;
+using KeyEventArgs = System.Windows.Input.KeyEventArgs;
+using MouseEventArgs = System.Windows.Input.MouseEventArgs;
+
+namespace GTPCorrgir
+{
+ ///
+ /// Interaction logic for Chat.xaml
+ ///
+ public partial class Chat : Window
+ {
+ gtpask AI_API;
+
+ public Chat(gtpask GTP)
+ {
+ InitializeComponent();
+ // Inicializar componentes de la UI, por ejemplo, llenar el ComboBox
+ AI_API = GTP;
+ questionArea.Text = ""; //GTP.TextoACorregir;
+ foreach (KeyValuePair kvp in Opciones.Instance.nombreLLM)
+ {
+ ComboBoxItem item = new ComboBoxItem();
+ item.Content = kvp.Value; // El texto que se mostrará
+ item.Tag = kvp.Key; // Guarda el valor enum en el Tag para acceso posterior
+ modelSelector.Items.Add(item);
+ // Verifica si este ítem debe ser el seleccionado
+ if (kvp.Key == Opciones.Instance.LLM)
+ {
+ modelSelector.SelectedItem = item;
+ }
+ }
+ }
+
+ private void Border_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
+ {
+ // Iniciar movimiento de la ventana si se presiona el botón izquierdo del ratón
+ if (e.LeftButton == MouseButtonState.Pressed)
+ {
+ this.DragMove();
+ }
+ }
+
+
+
+
+ private void Window_MouseEnter(object sender, MouseEventArgs e)
+ {
+ // Hacer la ventana opaca cuando el ratón esté sobre ella
+ this.Opacity = 1.0;
+ }
+
+ private void Window_KeyDown(object sender, KeyEventArgs e)
+ {
+ if (e.Key == Key.Escape)
+ {
+ this.Close();
+ }
+ }
+
+ private void QuestionArea_PreviewKeyDown(object sender, KeyEventArgs e)
+ {
+ if (e.Key == Key.Enter && !e.KeyboardDevice.Modifiers.HasFlag(ModifierKeys.Shift))
+ {
+ SendButton_Click(this, new RoutedEventArgs());
+ e.Handled = true; // Prevenir el salto de línea en el TextBox
+ }
+ }
+
+ private void Window_MouseLeave(object sender, MouseEventArgs e)
+ {
+ // Hacer la ventana transparente cuando el ratón no esté sobre ella
+ this.Opacity = 0.2; // Ajusta este valor a tu preferencia
+ }
+
+ private void SendButton_Click(object sender, RoutedEventArgs e)
+ {
+ // Aquí lógica para enviar pregunta y recibir respuesta de OpenAI
+
+ AI_API.TextoACorregir = questionArea.Text;
+ if (AI_API.TextoACorregir.Length > 3)
+ {
+ sendButton.IsEnabled = false; // Deshabilitar el botón de envío
+ Mouse.OverrideCursor = Cursors.Wait; // Cambiar el cursor a espera
+
+ Task.Run(async () =>
+ {
+ try
+ {
+ await AI_API.CorregirTexto();
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine("Error durante la corrección de texto: " + ex.Message);
+ }
+ finally
+ {
+ Dispatcher.Invoke(async () => // Nota el 'async' aquí para permitir 'await'
+ {
+ if (AI_API.TextoCorregido != null)
+ {
+ System.Windows.Clipboard.SetText(AI_API.TextoCorregido);
+ //responseArea. .Text += AI_API.TextoCorregido + "\r\n";
+ Mouse.OverrideCursor = null; // Restaurar el cursor normal
+ sendButton.IsEnabled = true; // Habilitar el botón de envío
+ }
+ });
+ }
+ });
+ }
+ }
+
+ private void CambiarModelo(object sender, SelectionChangedEventArgs e)
+ {
+ ComboBox comboBox = sender as ComboBox;
+ ComboBoxItem selectedItem = comboBox.SelectedItem as ComboBoxItem;
+ if (selectedItem != null)
+ {
+ LLM_a_Usar selectedEnum = (LLM_a_Usar)selectedItem.Tag;
+ Opciones.Instance.LLM = selectedEnum; // Suponiendo que hay una propiedad para establecerlo
+ }
+ }
+ }
+}
diff --git a/GTPCorrgir.csproj b/GTPCorrgir.csproj
index 0153b3d..74acb60 100644
--- a/GTPCorrgir.csproj
+++ b/GTPCorrgir.csproj
@@ -22,6 +22,7 @@
+
diff --git a/Program.cs b/Program.cs
index 8b744c3..c6c477d 100644
--- a/Program.cs
+++ b/Program.cs
@@ -15,7 +15,13 @@ namespace GTPCorrgir
Ollama,
Groq
}
- private Dictionary nombreLLM = new Dictionary
+ public enum modoDeUso
+ {
+ Corregir,
+ Chat,
+ }
+
+ public Dictionary nombreLLM = new Dictionary
{
{ Opciones.LLM_a_Usar.Ollama, "Ollama" },
{ Opciones.LLM_a_Usar.Groq, "Groq" },
@@ -32,13 +38,16 @@ namespace GTPCorrgir
if (_instance == null)
{
_instance = new Opciones();
+ _instance.LLM = LLM_a_Usar.OpenAI;
+ _instance.modo = modoDeUso.Chat;
}
return _instance;
}
}
public LLM_a_Usar LLM { get; set; }
-
+ public modoDeUso modo { get; set; }
+
public string nombreDeLLM() {
return nombreLLM[LLM];
}
@@ -55,17 +64,18 @@ namespace GTPCorrgir
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"))
+ 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;
+ else if (arg.StartsWith("--Chat"))
+ Opciones.Instance.modo = Opciones.modoDeUso.Chat;
}
}
diff --git a/gtpask.cs b/gtpask.cs
index f05a3bb..01f0d03 100644
--- a/gtpask.cs
+++ b/gtpask.cs
@@ -9,11 +9,12 @@ using LanguageDetection;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Diagnostics;
+using System.Windows.Interop;
namespace GTPCorrgir
{
- internal class gtpask
+ public class gtpask
{
private readonly string openAiApiKey = "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";
private readonly string groqApiKey = "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";
@@ -37,12 +38,18 @@ namespace GTPCorrgir
private string CrearMensajeDeSistema()
{
- 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' }.";
+ if (Opciones.Instance.modo == Opciones.modoDeUso.Corregir)
+ 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\" }.";
+ else
+ return "You are an engineer working specialiazed industrial automation. Please answer the following question in " + IdiomaDetectado + " and respond in the following JSON format: { \"Reply_text\": \"Your text here\" }.";
}
private string CrearMensajeDeUsuario(string texto)
{
- return "Please rewrite and improve the following text to make it clearer and more concise the words inside brackets are technical words: \"" + texto + "\"";
+ if (Opciones.Instance.modo == Opciones.modoDeUso.Corregir)
+ return "Please rewrite and improve the following text to make it clearer and more concise the words inside brackets are technical words: \"" + texto + "\"";
+ else
+ return texto;
}
@@ -109,7 +116,9 @@ namespace GTPCorrgir
Log.Log("Respuesta: " + RespuestaLLM);
- TextoCorregido = ExtractCorrectedText_UsingJObject(RespuestaLLM);
+ TextoCorregido = ExtraerValorUnicoJSON(RespuestaLLM);
+ if (TextoCorregido is null)
+ TextoCorregido = "Error en la respuesta.";
// Elimina comillas al principio y al final si existen
TextoCorregido = TextoCorregido.Trim('\"');
@@ -118,34 +127,45 @@ namespace GTPCorrgir
}
}
- static string ExtractCorrectedText_UsingJObject(string input)
+
+ public string ExtraerValorUnicoJSON(string input)
{
+ // Encuentra los índices del inicio y del final del JSON
+ int startJson = input.IndexOf('{');
+ int endJson = input.LastIndexOf('}') + 1;
+
+ if (startJson == -1 || endJson == -1 || endJson <= startJson)
+ {
+ return "No valid JSON found in the input string.";
+ }
+
+ // Extrae solo la parte JSON de la entrada
+ string jsonString = input.Substring(startJson, endJson - startJson);
+
try
{
- // Encuentra el índice del inicio y del final del JSON
- int startJson = input.IndexOf('{');
- int endJson = input.IndexOf('}') + 1;
-
- if (startJson == -1 || endJson == -1 || endJson <= startJson)
- {
- throw new Exception("No valid JSON found in the input string.");
- }
-
- // Extrae solo la parte JSON de la entrada
- string jsonString = input.Substring(startJson, endJson - startJson);
-
- // Parsea el JSON y extrae el campo "Rewritten_text"
+ // Parsea el JSON
JObject jsonObject = JObject.Parse(jsonString);
- string rewrittenText = (string)jsonObject["Rewritten_text"];
- return rewrittenText;
+
+ // Obtiene el primer campo independientemente del nombre de la clave
+ var firstField = jsonObject.Properties().FirstOrDefault();
+ if (firstField != null)
+ {
+ return firstField.Value.ToString(); // Devuelve el valor del primer campo
+ }
+ else
+ {
+ return "JSON does not contain any data.";
+ }
}
- catch (Exception ex)
+ catch (JsonException jsonEx)
{
- Console.WriteLine("An error occurred: " + ex.Message);
- return input;
+ // Maneja errores de parseo de JSON
+ return "Error parsing JSON: " + jsonEx.Message;
}
}
+
static string ExtractCorrectedText(string input)
{
try