Parcourir la source

修改core-ai,增加AutoScoreRequest非空校验注解

Signed-off-by: luoshi <luoshi@qmth.com.cn>
luoshi il y a 1 an
Parent
commit
23e09cd249

+ 4 - 0
core-ai/src/main/java/com/qmth/boot/core/ai/model/llm/AutoScoreRequest.java

@@ -2,16 +2,20 @@ package com.qmth.boot.core.ai.model.llm;
 
 import org.springframework.validation.annotation.Validated;
 
+import javax.validation.constraints.NotBlank;
+
 /**
  * 自动判分请求参数
  */
 @Validated
 public class AutoScoreRequest {
 
+    @NotBlank(message = "科目名称不能为空")
     private String subjectName;
 
     private String questionType;
 
+    @NotBlank(message = "试题内容不能为空")
     private String questionBody;
 
     private String standardAnswer;

+ 3 - 2
core-ai/src/main/java/com/qmth/boot/core/ai/service/AiService.java

@@ -7,6 +7,7 @@ import com.qmth.boot.core.ai.model.ocr.OcrType;
 import com.qmth.boot.core.retrofit.utils.SignatureInfo;
 import com.qmth.boot.core.retrofit.utils.UploadFile;
 import org.springframework.stereotype.Service;
+import org.springframework.validation.annotation.Validated;
 
 import javax.annotation.Resource;
 import javax.validation.constraints.NotNull;
@@ -75,7 +76,7 @@ public class AiService {
      * @param signature 使用当前机构AK作为鉴权信息
      * @return 得分率,保留最多三位小数;null表示无法获取判分结果
      */
-    public Double autoScore(@NotNull AutoScoreRequest request, @NotNull SignatureInfo signature) {
+    public Double autoScore(@NotNull @Validated AutoScoreRequest request, @NotNull SignatureInfo signature) {
         ChatResult result = llmApiClient.chatTemplate(signature, LlmAppType.AUTO_SCORE, request);
         String text = result.getChoices().stream().filter(choice -> choice.getMessage().getRole() == ChatRole.assistant)
                 .map(choice -> choice.getMessage().getContent()).findFirst().orElse("");
@@ -96,7 +97,7 @@ public class AiService {
      * @param signature 使用当前机构AK作为鉴权信息
      * @return 得分率,保留最多三位小数;null表示无法获取判分结果
      */
-    public Double autoScore(@NotNull AutoScoreRequest request, @NotNull byte[] image,
+    public Double autoScore(@NotNull @Validated AutoScoreRequest request, @NotNull byte[] image,
             @NotNull SignatureInfo signature) {
         request.setStudentAnswer(
                 ocrApiClient.forImage(signature, OcrType.HANDWRITING, UploadFile.build("image", "", image)));