mirror of
https://gitee.com/270580156/weiyu.git
synced 2025-12-30 10:52:26 +00:00
update
This commit is contained in:
@@ -108,8 +108,8 @@ public class RobotConsts {
|
||||
3. 提升客户满意度;
|
||||
4. 严禁回答政治、暴力、色情等违法违规问题;
|
||||
5. 仅根据上下文内容回答问题,不要添加其他内容;
|
||||
6. 如果上下文内容不完整,无法回答问题,直接回答“未查找到相关问题答案”,不要猜测;
|
||||
""";
|
||||
// 6. 如果上下文内容不完整,无法回答问题,直接回答“未查找到相关问题答案”,不要猜测;
|
||||
|
||||
// 默认知识库对话提示词
|
||||
public static final String ROBOT_LLM_CHAT_PROMPT = """
|
||||
|
||||
@@ -183,6 +183,20 @@ public class RobotRestController extends BaseRestController<RobotRequest, RobotR
|
||||
return ResponseEntity.ok(JsonResult.success(robotResponse));
|
||||
}
|
||||
|
||||
@Operation(summary = "更新机器人提示词", description = "仅根据UID更新机器人提示词内容")
|
||||
@ApiResponse(responseCode = "200", description = "更新成功",
|
||||
content = @Content(mediaType = "application/json",
|
||||
schema = @Schema(implementation = RobotResponse.class)))
|
||||
@PreAuthorize("hasAuthority('ROBOT_UPDATE')")
|
||||
@ActionAnnotation(title = "机器人", action = "更新", description = "update robot prompt text")
|
||||
@PostMapping("/update/prompt/text")
|
||||
public ResponseEntity<?> updatePromptText(@RequestBody RobotRequest request) {
|
||||
|
||||
RobotResponse robotResponse = robotRestService.updatePromptText(request);
|
||||
|
||||
return ResponseEntity.ok(JsonResult.success(robotResponse));
|
||||
}
|
||||
|
||||
@Operation(summary = "更新机器人知识库", description = "更新机器人的知识库UID")
|
||||
@ApiResponse(responseCode = "200", description = "更新成功",
|
||||
content = @Content(mediaType = "application/json",
|
||||
|
||||
@@ -567,6 +567,33 @@ public class RobotRestService extends BaseRestServiceWithExport<RobotEntity, Rob
|
||||
return convertToResponse(savedRobot);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public RobotResponse updatePromptText(RobotRequest request) {
|
||||
if (!StringUtils.hasText(request.getUid())) {
|
||||
throw new IllegalArgumentException("robot uid is required");
|
||||
}
|
||||
Optional<RobotEntity> robotOptional = findByUid(request.getUid());
|
||||
if (!robotOptional.isPresent()) {
|
||||
throw new NotFoundException("Robot not found with UID: " + request.getUid());
|
||||
}
|
||||
String newPrompt = resolvePromptValue(request);
|
||||
if (!StringUtils.hasText(newPrompt)) {
|
||||
throw new IllegalArgumentException("prompt is required");
|
||||
}
|
||||
RobotEntity robot = robotOptional.get();
|
||||
RobotLlm robotLlm = robot.getLlm();
|
||||
if (robotLlm == null) {
|
||||
robotLlm = new RobotLlm();
|
||||
}
|
||||
robotLlm.setPrompt(newPrompt);
|
||||
robot.setLlm(robotLlm);
|
||||
RobotEntity savedRobot = save(robot);
|
||||
if (savedRobot == null) {
|
||||
throw new RuntimeException("update robot prompt " + request.getUid() + " failed");
|
||||
}
|
||||
return convertToResponse(savedRobot);
|
||||
}
|
||||
|
||||
// 知识库更新请通过 RobotSettings 接口更新 kbEnabled/kbUid
|
||||
@Transactional
|
||||
public RobotResponse updateKbUid(RobotRequest request) {
|
||||
@@ -612,6 +639,16 @@ public class RobotRestService extends BaseRestServiceWithExport<RobotEntity, Rob
|
||||
return robot;
|
||||
}
|
||||
|
||||
private String resolvePromptValue(RobotRequest request) {
|
||||
if (StringUtils.hasText(request.getPrompt())) {
|
||||
return request.getPrompt();
|
||||
}
|
||||
if (request.getLlm() != null && StringUtils.hasText(request.getLlm().getPrompt())) {
|
||||
return request.getLlm().getPrompt();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
// 初始化
|
||||
// public void initDefaultRobot(String orgUid, String uid) {
|
||||
|
||||
@@ -178,7 +178,7 @@ public abstract class BaseSpringAIService implements SpringAIService {
|
||||
? aggregated.getSourceReferences()
|
||||
: new ArrayList<>();
|
||||
log.info("LLM 模式,KB 结果数 {}, 来源数 {}", kbResults.size(), sourceReferences.size());
|
||||
|
||||
|
||||
if (kbResults.isEmpty()) {
|
||||
// 未命中 KB:根据配置选择 默认回复 或 继续使用 LLM
|
||||
boolean useLlmWhenKbEmpty = robot.getLlm() != null
|
||||
|
||||
Reference in New Issue
Block a user