|
@@ -3,10 +3,16 @@ package com.yango.javaailangchain4j.controller;
|
|
|
|
|
|
|
|
import com.yango.javaailangchain4j.assistant.SeparateChatAssistant;
|
|
import com.yango.javaailangchain4j.assistant.SeparateChatAssistant;
|
|
|
import com.yango.javaailangchain4j.dto.EvaluationPsren;
|
|
import com.yango.javaailangchain4j.dto.EvaluationPsren;
|
|
|
|
|
+import com.yango.javaailangchain4j.service.TemplateProcessingService;
|
|
|
import com.yango.javaailangchain4j.utils.Result;
|
|
import com.yango.javaailangchain4j.utils.Result;
|
|
|
|
|
+import freemarker.template.TemplateException;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
|
|
+import java.io.IOException;
|
|
|
|
|
+import java.util.HashMap;
|
|
|
|
|
+import java.util.Map;
|
|
|
|
|
+
|
|
|
@RestController
|
|
@RestController
|
|
|
@RequestMapping("/api")
|
|
@RequestMapping("/api")
|
|
|
@CrossOrigin(origins = "*")
|
|
@CrossOrigin(origins = "*")
|
|
@@ -14,17 +20,48 @@ public class GpsresEvaluationController {
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private SeparateChatAssistant separateChatAssistant;
|
|
private SeparateChatAssistant separateChatAssistant;
|
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private TemplateProcessingService templateProcessingService;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ // // fixme:从数据库获取模板的方法(你需要根据实际情况实现)
|
|
|
|
|
+ private String getTemplateFromDatabase(String stepName) {
|
|
|
|
|
+ // 临时返回示例模板字符串
|
|
|
|
|
+ return "现在学生在${courseName}课程中的${stepName}环节,Goal是${goal}。\n"
|
|
|
|
|
+ + "学生的答案是${studentAnswer},\n"
|
|
|
|
|
+ + "标准答案是${standardAnswer}。\n"
|
|
|
|
|
+ + "答案不要再把学生答案和标准答案复述一遍了,以纯文本格式返回。\n"
|
|
|
|
|
+ + "根据标准答案和学生答案,给出该环节的评分和建议,总分${score}分。";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
@CrossOrigin(origins = "*")
|
|
@CrossOrigin(origins = "*")
|
|
|
@PostMapping( "/psrenEvalution")
|
|
@PostMapping( "/psrenEvalution")
|
|
|
- public Result Pevaluation(@RequestBody EvaluationPsren evaluationPsren) {
|
|
|
|
|
|
|
+ public Result Pevaluation(@RequestBody EvaluationPsren evaluationPsren) throws IOException, TemplateException {
|
|
|
String courseName = evaluationPsren.getCourseName();
|
|
String courseName = evaluationPsren.getCourseName();
|
|
|
String stepName = evaluationPsren.getStepName();
|
|
String stepName = evaluationPsren.getStepName();
|
|
|
String goal = evaluationPsren.getGoal();
|
|
String goal = evaluationPsren.getGoal();
|
|
|
String standardAnswer = evaluationPsren.getStandardAnswer();
|
|
String standardAnswer = evaluationPsren.getStandardAnswer();
|
|
|
String studentAnswer = evaluationPsren.getStudentAnswer();
|
|
String studentAnswer = evaluationPsren.getStudentAnswer();
|
|
|
int score = evaluationPsren.getScore();
|
|
int score = evaluationPsren.getScore();
|
|
|
- String userMessage = String.format("现在学生在%s课程中的%s环节,Goal是%s,学生的答案是%s,标准答案是%s,答案不要再把学生答案和标准答案复述一遍了,以纯文本格式返回" +
|
|
|
|
|
- "根据标准答案和学生答案,给出该环节的评分和建议,总分%d分",courseName,stepName,goal,studentAnswer,standardAnswer, score);
|
|
|
|
|
|
|
+ /*String userMessage = String.format("现在学生在%s课程中的%s环节,Goal是%s,学生的答案是%s,标准答案是%s,答案不要再把学生答案和标准答案复述一遍了,以纯文本格式返回" +
|
|
|
|
|
+ "根据标准答案和学生答案,给出该环节的评分和建议,总分%d分",courseName,stepName,goal,studentAnswer,standardAnswer, score);*/
|
|
|
|
|
+
|
|
|
|
|
+ // 准备模板数据
|
|
|
|
|
+ Map<String, Object> templateData = new HashMap<>();
|
|
|
|
|
+ templateData.put("courseName", courseName);
|
|
|
|
|
+ templateData.put("stepName", stepName);
|
|
|
|
|
+ templateData.put("goal", goal);
|
|
|
|
|
+ templateData.put("studentAnswer", studentAnswer);
|
|
|
|
|
+ templateData.put("standardAnswer", standardAnswer);
|
|
|
|
|
+ templateData.put("score", score);
|
|
|
|
|
+
|
|
|
|
|
+ // fixme:从数据库读取的模板字符串
|
|
|
|
|
+ String templateString = getTemplateFromDatabase(stepName); // 你的数据库读取方法
|
|
|
|
|
+
|
|
|
|
|
+ // 使用模板处理服务处理模板
|
|
|
|
|
+ String userMessage = templateProcessingService.processTemplate(
|
|
|
|
|
+ templateString, templateData, "evaluationTemplate-" + stepName);
|
|
|
|
|
+
|
|
|
String s = separateChatAssistant.chat5(
|
|
String s = separateChatAssistant.chat5(
|
|
|
evaluationPsren.getMemoryId(),
|
|
evaluationPsren.getMemoryId(),
|
|
|
evaluationPsren.getCourseName(),
|
|
evaluationPsren.getCourseName(),
|