atsachlaris 1 день назад
Родитель
Сommit
d7446503ed

+ 3 - 3
src/main/java/es/uv/saic/llm/AiProxy.java

@@ -1,8 +1,8 @@
 package es.uv.saic.llm;
 package es.uv.saic.llm;
 
 
-public interface AiProxy {
+import com.fasterxml.jackson.core.JsonProcessingException;
 
 
-    String calculateScoreAndProduceComments(String asCsv);
+public interface AiProxy {
 
 
-    String calculateScoreAndProduceComments(String asCsv, String model);
+    String calculateScoreAndProduceComments(String asCsv, String model) throws JsonProcessingException;
 }
 }

+ 7 - 8
src/main/java/es/uv/saic/llm/GroqProxy.java

@@ -1,5 +1,6 @@
 package es.uv.saic.llm;
 package es.uv.saic.llm;
 
 
+import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import lombok.SneakyThrows;
 import lombok.SneakyThrows;
 import lombok.extern.slf4j.Slf4j;
 import lombok.extern.slf4j.Slf4j;
@@ -24,13 +25,7 @@ public class GroqProxy implements AiProxy {
         this.chatClient = groqChatClient;
         this.chatClient = groqChatClient;
     }
     }
 
 
-    @SneakyThrows
-    public String calculateScoreAndProduceComments(String asCsv) {
-        return calculateScoreAndProduceComments(asCsv, null);
-    }
-
-    @SneakyThrows
-    public String calculateScoreAndProduceComments(String asCsv, String model) {
+    public String calculateScoreAndProduceComments(String asCsv, String model) throws JsonProcessingException {
         log.info("Calculating using Groq Proxy with model: {}", model);
         log.info("Calculating using Groq Proxy with model: {}", model);
 
 
         ChatClient.ChatClientRequestSpec prompt = chatClient.prompt();
         ChatClient.ChatClientRequestSpec prompt = chatClient.prompt();
@@ -39,10 +34,14 @@ public class GroqProxy implements AiProxy {
             prompt = prompt.options(OpenAiChatOptions.builder().model(model).build());
             prompt = prompt.options(OpenAiChatOptions.builder().model(model).build());
         }
         }
 
 
-        return prompt
+        String content = prompt
                 .system(SCORE_AND_COMMENT_ANALYSIS_PROMPT)
                 .system(SCORE_AND_COMMENT_ANALYSIS_PROMPT)
                 .user("Aquí tienes las tablas: " + objectMapper.writeValueAsString(asCsv))
                 .user("Aquí tienes las tablas: " + objectMapper.writeValueAsString(asCsv))
                 .call()
                 .call()
                 .content();
                 .content();
+
+        log.info("LLM Response: {}", content);
+
+        return content;
     }
     }
 }
 }

+ 0 - 5
src/main/java/es/uv/saic/llm/LocalLlmProxy.java

@@ -25,11 +25,6 @@ public class LocalLlmProxy implements AiProxy {
     }
     }
 
 
     @SneakyThrows
     @SneakyThrows
-    public String calculateScoreAndProduceComments(String asCsv) {
-        return calculateScoreAndProduceComments(asCsv, null);
-    }
-
-    @SneakyThrows
     public String calculateScoreAndProduceComments(String asCsv, String model) {
     public String calculateScoreAndProduceComments(String asCsv, String model) {
         log.info("Calculating using Local LLM Proxy with model: {}", model);
         log.info("Calculating using Local LLM Proxy with model: {}", model);
         ChatClient.ChatClientRequestSpec prompt = localChatClient.prompt();
         ChatClient.ChatClientRequestSpec prompt = localChatClient.prompt();

+ 3 - 2
src/main/java/es/uv/saic/service/EnhancementService.java

@@ -1,5 +1,6 @@
 package es.uv.saic.service;
 package es.uv.saic.service;
 
 
+import com.fasterxml.jackson.core.JsonProcessingException;
 import es.uv.saic.extractor.ExtractionRequest;
 import es.uv.saic.extractor.ExtractionRequest;
 import es.uv.saic.extractor.docling.DoclingTableExtractor;
 import es.uv.saic.extractor.docling.DoclingTableExtractor;
 import es.uv.saic.extractor.HtmlToCsvExtractor;
 import es.uv.saic.extractor.HtmlToCsvExtractor;
@@ -23,12 +24,12 @@ public class EnhancementService {
     private final GroqProxy groqProxy;
     private final GroqProxy groqProxy;
     private final ExtractionResponseMapper  extractionResponseMapper;
     private final ExtractionResponseMapper  extractionResponseMapper;
 
 
-    public ExtractionResponse calculateScoreAndProduceCommentsWithSingleCall(ExtractionRequest extractionRequest, String provider, String model) {
+    public ExtractionResponse calculateScoreAndProduceCommentsWithSingleCall(ExtractionRequest extractionRequest, String provider, String model) throws JsonProcessingException {
         String asCsv = extractCsv(extractionRequest);
         String asCsv = extractCsv(extractionRequest);
         return calculateScoreAndProduceCommentsFromCsv(asCsv, provider, model);
         return calculateScoreAndProduceCommentsFromCsv(asCsv, provider, model);
     }
     }
 
 
-    public ExtractionResponse calculateScoreAndProduceCommentsFromCsv(String asCsv, String provider, String model) {
+    public ExtractionResponse calculateScoreAndProduceCommentsFromCsv(String asCsv, String provider, String model) throws JsonProcessingException {
         if (StringUtils.isBlank(asCsv)) {
         if (StringUtils.isBlank(asCsv)) {
             throw new IllegalArgumentException("CSV content is empty");
             throw new IllegalArgumentException("CSV content is empty");
         }
         }

+ 2 - 1
src/main/java/es/uv/saic/web/EnhancementController.java

@@ -1,5 +1,6 @@
 package es.uv.saic.web;
 package es.uv.saic.web;
 
 
+import com.fasterxml.jackson.core.JsonProcessingException;
 import es.uv.saic.extractor.ExtractionRequest;
 import es.uv.saic.extractor.ExtractionRequest;
 import es.uv.saic.service.EnhancementService;
 import es.uv.saic.service.EnhancementService;
 import es.uv.saic.service.ExtractionResponse;
 import es.uv.saic.service.ExtractionResponse;
@@ -34,7 +35,7 @@ public class EnhancementController {
         log.info("====== EnhancementController.singleStepAnalysis start ======");
         log.info("====== EnhancementController.singleStepAnalysis start ======");
         try {
         try {
             return enhancementService.calculateScoreAndProduceCommentsWithSingleCall(ExtractionRequest.fromHtml(html), provider, model);
             return enhancementService.calculateScoreAndProduceCommentsWithSingleCall(ExtractionRequest.fromHtml(html), provider, model);
-        } catch (IllegalArgumentException e) {
+        } catch (IllegalArgumentException | JsonProcessingException e) {
             throw new ResponseStatusException(BAD_REQUEST, e.getMessage(), e);
             throw new ResponseStatusException(BAD_REQUEST, e.getMessage(), e);
         } finally {
         } finally {
             log.info("====== EnhancementController.singleStepAnalysis end ======");
             log.info("====== EnhancementController.singleStepAnalysis end ======");