|
|
@@ -0,0 +1,44 @@
|
|
|
+package es.uv.saic.llm;
|
|
|
+
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
+import lombok.SneakyThrows;
|
|
|
+import org.springframework.ai.chat.client.ChatClient;
|
|
|
+import org.springframework.ai.openai.OpenAiChatOptions;
|
|
|
+import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import static es.uv.saic.service.SystemPrompt.SCORE_AND_COMMENT_ANALYSIS_PROMPT;
|
|
|
+
|
|
|
+@Component
|
|
|
+public class GroqProxy {
|
|
|
+
|
|
|
+ private final ChatClient chatClient;
|
|
|
+ private final ObjectMapper objectMapper = new ObjectMapper();
|
|
|
+
|
|
|
+ public GroqProxy(
|
|
|
+ @Qualifier("groqChatClient") ChatClient groqChatClient
|
|
|
+ ) {
|
|
|
+ this.chatClient = groqChatClient;
|
|
|
+ }
|
|
|
+
|
|
|
+ @SneakyThrows
|
|
|
+ public String calculateScoreAndProduceComments(String asCsv) {
|
|
|
+ return calculateScoreAndProduceComments(asCsv, null);
|
|
|
+ }
|
|
|
+
|
|
|
+ @SneakyThrows
|
|
|
+ public String calculateScoreAndProduceComments(String asCsv, String model) {
|
|
|
+ ChatClient.ChatClientRequestSpec prompt = chatClient.prompt();
|
|
|
+
|
|
|
+ if (StringUtils.hasText(model)) {
|
|
|
+ prompt = prompt.options(OpenAiChatOptions.builder().model(model).build());
|
|
|
+ }
|
|
|
+
|
|
|
+ return prompt
|
|
|
+ .system(SCORE_AND_COMMENT_ANALYSIS_PROMPT)
|
|
|
+ .user("Aquí tienes las tablas: " + objectMapper.writeValueAsString(asCsv))
|
|
|
+ .call()
|
|
|
+ .content();
|
|
|
+ }
|
|
|
+}
|