|
|
@@ -4,7 +4,7 @@ import es.uv.saic.extractor.ExtractionRequest;
|
|
|
import es.uv.saic.extractor.docling.DoclingTableExtractor;
|
|
|
import es.uv.saic.extractor.HtmlToCsvExtractor;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
-import lombok.SneakyThrows;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
@@ -16,29 +16,24 @@ public class EnhancementService {
|
|
|
private final DoclingTableExtractor doclingTableExtractor;
|
|
|
private final LlmProxy llmProxy;
|
|
|
|
|
|
- @SneakyThrows
|
|
|
- public String askHtml(String html) {
|
|
|
- String asCsv = extractForChatEndpoint(ExtractionRequest.fromHtml(html));
|
|
|
+ public String calculateScoreAndProduceCommentsWithSingleCall(ExtractionRequest extractionRequest) {
|
|
|
+ String asCsv = extractCsv(extractionRequest);
|
|
|
|
|
|
- return llmProxy.askLlm(asCsv);
|
|
|
+ return llmProxy.calculateScoreAndProduceComments(asCsv);
|
|
|
}
|
|
|
|
|
|
- public String askFile(byte[] fileBytes, String fileName, String contentType) {
|
|
|
- String asCsv = extractForFileEndpoint(ExtractionRequest.fromFile(fileBytes, fileName, contentType));
|
|
|
+ private String extractCsv(ExtractionRequest request) {
|
|
|
+ String html = request.hasFile() ? new String(request.fileBytes(), StandardCharsets.UTF_8) : request.rawHtml();
|
|
|
|
|
|
- return llmProxy.askLlm(asCsv);
|
|
|
- }
|
|
|
+ if (StringUtils.isEmpty(html)) {
|
|
|
+ throw new RuntimeException("No HTML found!");
|
|
|
+ }
|
|
|
|
|
|
- private String extractForChatEndpoint(ExtractionRequest request) {
|
|
|
+ ExtractionRequest htmlRequest = ExtractionRequest.fromHtml(html);
|
|
|
if (doclingTableExtractor.supports(request)) {
|
|
|
- return doclingTableExtractor.extractTablesToCsv(request);
|
|
|
+ return doclingTableExtractor.extractTablesToCsv(htmlRequest);
|
|
|
}
|
|
|
- return htmlToCsvExtractor.extractTablesToCsv(request);
|
|
|
- }
|
|
|
-
|
|
|
- private String extractForFileEndpoint(ExtractionRequest request) {
|
|
|
- String htmlFallback = request.hasFile() ? new String(request.fileBytes(), StandardCharsets.UTF_8) : "";
|
|
|
- return extractForChatEndpoint(ExtractionRequest.fromHtml(htmlFallback));
|
|
|
+ return htmlToCsvExtractor.extractTablesToCsv(htmlRequest);
|
|
|
}
|
|
|
|
|
|
}
|