Agregado timestamp en el log

This commit is contained in:
Miguel 2024-04-25 18:45:14 +02:00
parent ca93488be3
commit 52e59de230
2 changed files with 10 additions and 7 deletions

View File

@ -22,7 +22,9 @@ namespace GTPCorrgir
public void Log(string message) public void Log(string message)
{ {
Trace.WriteLine(message); // Formato de timestamp [AAAA-MM-DD HH:mm:ss]
string timestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
Trace.WriteLine($"[{timestamp}] {message}");
} }
} }

View File

@ -70,6 +70,7 @@ namespace GTPCorrgir
public async Task CorregirTexto() public async Task CorregirTexto()
{ {
Log.Log("");
Log.Log("Texto a corregir: " + TextoACorregir); Log.Log("Texto a corregir: " + TextoACorregir);
if (DetectarIdioma()) { if (DetectarIdioma()) {
if (IdiomaDetectado == "Desconocido" || this.TextoACorregir.Length == 0) if (IdiomaDetectado == "Desconocido" || this.TextoACorregir.Length == 0)
@ -84,10 +85,10 @@ namespace GTPCorrgir
TextoACorregir = md.MarkTechnicalTerms(TextoACorregir); TextoACorregir = md.MarkTechnicalTerms(TextoACorregir);
Log.Log("Texto a marcado: " + TextoACorregir); Log.Log("Texto marcado: " + TextoACorregir);
string RespuestaLLM = await CallOpenAiApi(TextoACorregir); //string RespuestaLLM = await CallOpenAiApi(TextoACorregir);
//string RespuestaLLM = await CallOllamaApi(TextoACorregir); string RespuestaLLM = await CallOllamaApi(TextoACorregir);
Log.Log("Respuesta: " + RespuestaLLM); Log.Log("Respuesta: " + RespuestaLLM);
@ -96,7 +97,7 @@ namespace GTPCorrgir
// Elimina comillas al principio y al final si existen // Elimina comillas al principio y al final si existen
TextoCorregido = TextoCorregido.Trim('\"'); TextoCorregido = TextoCorregido.Trim('\"');
Log.Log("Texto a corregido: " + TextoCorregido); Log.Log("Texto corregido: " + TextoCorregido);
} }
} }
@ -150,7 +151,7 @@ namespace GTPCorrgir
var content = new StringContent(JsonConvert.SerializeObject(requestData), Encoding.UTF8, "application/json"); var content = new StringContent(JsonConvert.SerializeObject(requestData), Encoding.UTF8, "application/json");
try try
{ {
Log.Log("Ask Ollama: " + content.ToString()); Log.Log("Ask Ollama: " + JsonConvert.SerializeObject(requestData));
var response = await httpClient.PostAsync("http://127.0.0.1:11434/api/chat", content); var response = await httpClient.PostAsync("http://127.0.0.1:11434/api/chat", content);
response.EnsureSuccessStatusCode(); response.EnsureSuccessStatusCode();
var jsonResponse = await response.Content.ReadAsStringAsync(); var jsonResponse = await response.Content.ReadAsStringAsync();
@ -198,7 +199,7 @@ namespace GTPCorrgir
var content = new StringContent(JsonConvert.SerializeObject(requestData), Encoding.UTF8, "application/json"); var content = new StringContent(JsonConvert.SerializeObject(requestData), Encoding.UTF8, "application/json");
try try
{ {
Log.Log("Ask OpenAI: " + content.ToString()); Log.Log("Ask OpenAI: " + JsonConvert.SerializeObject(requestData));
var response = await httpClient.PostAsync("https://api.openai.com/v1/chat/completions", content); var response = await httpClient.PostAsync("https://api.openai.com/v1/chat/completions", content);
response.EnsureSuccessStatusCode(); response.EnsureSuccessStatusCode();
var jsonResponse = await response.Content.ReadAsStringAsync(); var jsonResponse = await response.Content.ReadAsStringAsync();