Bläddra i källkod

feat:增加单句智评重试功能

baiqi 1 år sedan
förälder
incheckning
35d3b9e43b

+ 0 - 16
src/main/java/com/njuzr/eaibackend/controller/EvaluationController.java

@@ -21,22 +21,6 @@ public class EvaluationController {
         this.aiEvaluationService = aiEvaluationService;
     }
 
-    /**
-     * 一键双评
-     * @param assignmentId
-     * @param studentId
-     * @return
-     * @throws ExecutionException
-     * @throws InterruptedException
-     */
-    @PostMapping("/all")
-    public MyResponse evaluateAll(
-            @RequestParam Long assignmentId,
-            @RequestParam Long studentId
-    ) throws ExecutionException, InterruptedException {
-        return MyResponse.success(aiEvaluationService.evaluateAll(assignmentId, studentId));
-    }
-
     /**
      * 对作文整体进行评价
      * @param assignmentId 作业ID

+ 6 - 13
src/main/java/com/njuzr/eaibackend/service/AIEvaluationService.java

@@ -135,19 +135,12 @@ public class AIEvaluationService {
         this.evaluationMapperServiceImpl = evaluationMapperServiceImpl;
     }
 
-    /**
-     * 一键双评
-     * @param assignmentId
-     * @param studentId
-     * @return
-     */
-    public AIEntry evaluateAll(Long assignmentId, Long studentId) {
-
-    }
-
     public CompletableFuture<AIEntry> evaluationAsync(Long assignmentId, Long studentId) {
-        return CompletableFuture.supplyAsync(() -> evaluation(assignmentId, studentId), aiTaskExecutor);
+        return CompletableFuture.supplyAsync(() -> evaluation(assignmentId, studentId), aiTaskExecutor)
+                .exceptionally(ex -> { throw new MyException(HttpStatus.INTERNAL_SERVER_ERROR.value(), "AI请求失败:" + ex.getMessage());})
+                .orTimeout(40, TimeUnit.SECONDS);
     }
+    
     /**
      * AI作文整体智能批改
      * @param assignmentId
@@ -163,9 +156,9 @@ public class AIEvaluationService {
         if (assignment == null) throw MyException.create(HttpStatus.BAD_REQUEST, "作业不存在");
         Evaluation evaluationJudge = evaluationMapperServiceImpl.getByVersion(assignmentId, studentId, engagement.getVersion());
         if(evaluationJudge != null) throw MyException.create(HttpStatus.BAD_REQUEST, "作业已进行过AI分析");
-        log.info("evaluation start");
+
         initEvaluationRecord(assignmentId, studentId, engagement);
-        log.info("evaluation end");
+
         String prompt = String.format(REWRITE_PROMPT_TEMPLATE, assignment.getDescription(), engagement.getTextContent());
         AIRequestService.AIResponse response = requestAI(prompt, 0);
         String retContent;