|
@@ -107,14 +107,72 @@ public class AiService {
|
|
|
}
|
|
|
|
|
|
ChatResult result = llmApiClient.chatTemplate(baseUrl, signature, LlmAppType.AUTO_SCORE, request);
|
|
|
- String text = result.getChoices().stream().filter(choice -> choice.getMessage().getRole() == ChatRole.assistant)
|
|
|
+ String content = result.getChoices().stream().filter(choice -> choice.getMessage().getRole() == ChatRole.assistant)
|
|
|
.map(choice -> choice.getMessage().getContent()).findFirst().orElse("");
|
|
|
|
|
|
+ return parseScoreResult(request, content);
|
|
|
+ }
|
|
|
+
|
|
|
+ private AutoScoreResult parseScoreResult(AutoScoreRequest request, String content) {
|
|
|
+ try {
|
|
|
+ String[] values = StringUtils.split(content.replaceAll(",", ","), ",");
|
|
|
+ int stepCount = request.getStandardAnswer().size();
|
|
|
+ if (stepCount != values.length) {
|
|
|
+ log.warn("评分结果无效,要求给出{}个关键分值,实际响应:{}", stepCount, content);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ double totalScore = 0;
|
|
|
+ double[] scores = new double[stepCount];
|
|
|
+ for (int i = 0; i < stepCount; i++) {
|
|
|
+ // 得分率:必须 0 - 100 之间
|
|
|
+ double stepScoreRate = Double.parseDouble(values[i].trim());
|
|
|
+ stepScoreRate = Math.min(Math.max(stepScoreRate, 0), 100);
|
|
|
+
|
|
|
+ StandardAnswer step = request.getStandardAnswer().get(i);
|
|
|
+ if (AutoScoreModel.LEVEL == request.getScoreModel()) {
|
|
|
+ // 按档次给分模式:关键步骤得分应介于当前档次分值区间
|
|
|
+ double stepScore = stepScoreRate * step.getHighScore() / 100;
|
|
|
+ if (stepScore < step.getLowScore()) {
|
|
|
+ log.warn("评分结果-第{}步得分:{},低于档次分值区间{}-{}分的最低分", i + 1, stepScore, step.getLowScore(), step.getHighScore());
|
|
|
+ stepScore = 0;
|
|
|
+ } else {
|
|
|
+ // 修正分值-符合最小间隔分规则
|
|
|
+ stepScore = this.fixScore(stepScore, request.getIntervalScore());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 步骤分不能超过当前试题总分
|
|
|
+ scores[i] = Math.min(stepScore, request.getTotalScore());
|
|
|
+ totalScore = Math.max(totalScore, scores[i]);
|
|
|
+ } else {
|
|
|
+ // 按得分点给分模式:关键步骤得分应小于等于当前得分点的分值
|
|
|
+ double stepScore = stepScoreRate * step.getScore() / 100;
|
|
|
+
|
|
|
+ // 修正分值-符合最小间隔分规则
|
|
|
+ stepScore = this.fixScore(stepScore, request.getIntervalScore());
|
|
|
+
|
|
|
+ // 步骤分不能超过当前试题总分
|
|
|
+ scores[i] = Math.min(stepScore, request.getTotalScore());
|
|
|
+ totalScore += scores[i];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ AutoScoreResult scoreResult = new AutoScoreResult();
|
|
|
+ scoreResult.setStepScore(scores);
|
|
|
+ scoreResult.setTotalScore(Math.min(totalScore, request.getTotalScore()));
|
|
|
+ return scoreResult;
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.warn("评分结果无效,实际响应:{},错误:{}", content, e.getMessage());
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /*private AutoScoreResult parseScoreResult(AutoScoreRequest request, String content) {
|
|
|
try {
|
|
|
- String[] values = StringUtils.split(text.replaceAll(",", ","), ",");
|
|
|
+ String[] values = StringUtils.split(content.replaceAll(",", ","), ",");
|
|
|
int stepCount = request.getStandardAnswer().size();
|
|
|
if (stepCount != values.length) {
|
|
|
- log.warn("评分结果无效,要求给出{}个关键分值,实际响应:{}", stepCount, text);
|
|
|
+ log.warn("评分结果无效,要求给出{}个关键分值,实际响应:{}", stepCount, content);
|
|
|
return null;
|
|
|
}
|
|
|
|
|
@@ -131,25 +189,27 @@ public class AiService {
|
|
|
stepScore = 0;
|
|
|
} else if (stepScore > step.getHighScore()) {
|
|
|
log.warn("评分结果-第{}步得分:{},高于档次分值区间{}-{}分的最高分", i + 1, stepScore, step.getLowScore(), step.getHighScore());
|
|
|
+ stepScore = Math.min(stepScore, step.getHighScore());
|
|
|
} else {
|
|
|
// 修正分值-符合最小间隔分规则
|
|
|
stepScore = this.fixScore(stepScore, request.getIntervalScore());
|
|
|
}
|
|
|
|
|
|
- // 步骤分不能超过当前档次区间最高分和试题总分
|
|
|
- scores[i] = Math.min(Math.min(stepScore, step.getHighScore()), request.getTotalScore());
|
|
|
+ // 步骤分不能超过当前试题总分
|
|
|
+ scores[i] = Math.min(stepScore, request.getTotalScore());
|
|
|
totalScore = Math.max(totalScore, scores[i]);
|
|
|
} else {
|
|
|
// 按得分点给分模式:关键步骤得分应小于等于当前得分点的分值
|
|
|
if (stepScore > step.getScore()) {
|
|
|
log.warn("评分结果-第{}步得分:{},大于得分点分值{}分的最大分", i + 1, stepScore, step.getScore());
|
|
|
+ stepScore = Math.min(stepScore, step.getScore());
|
|
|
} else {
|
|
|
// 修正分值-符合最小间隔分规则
|
|
|
stepScore = this.fixScore(stepScore, request.getIntervalScore());
|
|
|
}
|
|
|
|
|
|
- // 步骤分不能超过当前得分点最高分和试题总分
|
|
|
- scores[i] = Math.min(Math.min(stepScore, step.getScore()), request.getTotalScore());
|
|
|
+ // 步骤分不能超过当前试题总分
|
|
|
+ scores[i] = Math.min(stepScore, request.getTotalScore());
|
|
|
totalScore += scores[i];
|
|
|
}
|
|
|
}
|
|
@@ -159,10 +219,10 @@ public class AiService {
|
|
|
scoreResult.setTotalScore(Math.min(totalScore, request.getTotalScore()));
|
|
|
return scoreResult;
|
|
|
} catch (Exception e) {
|
|
|
- log.warn("评分结果无效,实际响应:{},错误:{}", text, e.getMessage());
|
|
|
+ log.warn("评分结果无效,实际响应:{},错误:{}", content, e.getMessage());
|
|
|
return null;
|
|
|
}
|
|
|
- }
|
|
|
+ }*/
|
|
|
|
|
|
/**
|
|
|
* 将分数近似修正为指定“最小间隔分”的整数倍数
|