|
|
@@ -16,6 +16,7 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Propagation;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
+import java.io.IOException;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.CompletableFuture;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
@@ -31,7 +32,11 @@ public class AIEvaluationService {
|
|
|
|
|
|
private static final int RETRY_COUNT = 3;
|
|
|
|
|
|
- private final AIRequestService aiRequestService;
|
|
|
+ @Autowired
|
|
|
+ DeepSeekService deepSeekService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ AIRequestService aiRequestService;
|
|
|
|
|
|
private final StudentAssignmentMapper studentAssignmentMapper;
|
|
|
|
|
|
@@ -56,8 +61,7 @@ public class AIEvaluationService {
|
|
|
private SentenceEvaluationMapperServiceImpl sentenceEvaluationMapperServiceImpl;
|
|
|
|
|
|
@Autowired
|
|
|
- public AIEvaluationService(AIRequestService aiRequestService, StudentAssignmentMapper studentAssignmentMapper, AssignmentMapper assignmentMapper, OverallEvaluationMapper overallEvaluationMapper, SentenceEvaluationMapper sentenceEvaluationMapper, EvaluationMapper evaluationMapper, EvaluationMapperServiceImpl evaluationMapperServiceImpl) {
|
|
|
- this.aiRequestService = aiRequestService;
|
|
|
+ public AIEvaluationService(StudentAssignmentMapper studentAssignmentMapper, AssignmentMapper assignmentMapper, OverallEvaluationMapper overallEvaluationMapper, SentenceEvaluationMapper sentenceEvaluationMapper, EvaluationMapper evaluationMapper, EvaluationMapperServiceImpl evaluationMapperServiceImpl) {
|
|
|
this.studentAssignmentMapper = studentAssignmentMapper;
|
|
|
this.assignmentMapper = assignmentMapper;
|
|
|
this.overallEvaluationMapper = overallEvaluationMapper;
|
|
|
@@ -92,9 +96,8 @@ public class AIEvaluationService {
|
|
|
|
|
|
// 发起LLM请求
|
|
|
String prompt = String.format(PromptConstant.REWRITE_PROMPT_TEMPLATE, assignment.getDescription(), engagement.getTextContent());
|
|
|
- AIRequestService.AIResponse response = requestAIWithRetry(prompt, 0);
|
|
|
- String retContent = response.getChoices().get(0).getMessage().getContent();
|
|
|
- String role = response.getChoices().get(0).getMessage().getRole();
|
|
|
+ String retContent = requestAIWithRetry(prompt, 0);
|
|
|
+ String role = "assistant";
|
|
|
|
|
|
OverallEvaluation overallEvaluation = new OverallEvaluation()
|
|
|
.setStudentId(studentId)
|
|
|
@@ -132,10 +135,15 @@ public class AIEvaluationService {
|
|
|
log.info("evaluation record: {}", evaluation);
|
|
|
}
|
|
|
|
|
|
- private AIRequestService.AIResponse requestAIWithRetry(String prompt, int retryTime) {
|
|
|
+ private String requestAIWithRetry(String prompt, int retryTime) {
|
|
|
List<AIEntry> entry = new ArrayList<>();
|
|
|
entry.add(new AIEntry("user", prompt));
|
|
|
- AIRequestService.AIResponse response = aiRequestService.requestChatGLM4(entry);
|
|
|
+ String response = null;
|
|
|
+ try {
|
|
|
+ response = deepSeekService.chatCompletion(entry);
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
if(response == null && retryTime < 3) {
|
|
|
log.info("requestAI failed, retryTime: {}", retryTime + 1);
|
|
|
return requestAIWithRetry(prompt, retryTime + 1);
|