diff --git a/Logger.cs b/Logger.cs new file mode 100644 index 0000000..fc5e391 --- /dev/null +++ b/Logger.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Diagnostics; +using System.IO; + +namespace GTPCorrgir +{ + using System.Diagnostics; + + public class Logger + { + public Logger() + { + string logFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "logfile.log"); + Trace.Listeners.Add(new TextWriterTraceListener(logFilePath)); + Trace.AutoFlush = true; + } + + + public void Log(string message) + { + Trace.WriteLine(message); + } + } + +} diff --git a/gtpask.cs b/gtpask.cs index 8e2e3db..591236c 100644 --- a/gtpask.cs +++ b/gtpask.cs @@ -8,12 +8,14 @@ using System.Windows.Threading; using LanguageDetection; using Newtonsoft.Json; using Newtonsoft.Json.Linq; +using System.Diagnostics; namespace GTPCorrgir { internal class gtpask { private readonly string openAiApiKey = "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"; + public Logger Log = new Logger(); private Dictionary languageMap = new Dictionary { { "en", "English" }, @@ -58,6 +60,7 @@ namespace GTPCorrgir if (TextoACorregir.Length>0) { IdiomaDetectado = DetectarIdioma(TextoACorregir); + Log.Log("Idioma: " + IdiomaDetectado); if(IdiomaDetectado != "Desconocido") return true; else return false; @@ -66,8 +69,8 @@ namespace GTPCorrgir } public async Task CorregirTexto() - { - + { + Log.Log("Texto a corregir: " + TextoACorregir); if (DetectarIdioma()) { if (IdiomaDetectado == "Desconocido" || this.TextoACorregir.Length == 0) { @@ -81,13 +84,19 @@ namespace GTPCorrgir TextoACorregir = md.MarkTechnicalTerms(TextoACorregir); - //TextoCorregido = await CallOpenAiApi(TextoACorregir); - string RespuestaLLM = await CallOllamaApi(TextoACorregir); + Log.Log("Texto a marcado: " + TextoACorregir); + + string RespuestaLLM = await CallOpenAiApi(TextoACorregir); + //string RespuestaLLM = await CallOllamaApi(TextoACorregir); + + Log.Log("Respuesta: " + RespuestaLLM); TextoCorregido = ExtractCorrectedText(RespuestaLLM); // Elimina comillas al principio y al final si existen TextoCorregido = TextoCorregido.Trim('\"'); + + Log.Log("Texto a corregido: " + TextoCorregido); } } @@ -141,6 +150,7 @@ namespace GTPCorrgir var content = new StringContent(JsonConvert.SerializeObject(requestData), Encoding.UTF8, "application/json"); try { + Log.Log("Ask Ollama: " + content.ToString()); var response = await httpClient.PostAsync("http://127.0.0.1:11434/api/chat", content); response.EnsureSuccessStatusCode(); var jsonResponse = await response.Content.ReadAsStringAsync(); @@ -188,6 +198,7 @@ namespace GTPCorrgir var content = new StringContent(JsonConvert.SerializeObject(requestData), Encoding.UTF8, "application/json"); try { + Log.Log("Ask OpenAI: " + content.ToString()); var response = await httpClient.PostAsync("https://api.openai.com/v1/chat/completions", content); response.EnsureSuccessStatusCode(); var jsonResponse = await response.Content.ReadAsStringAsync();