|
...
|
...
|
@@ -18,6 +18,7 @@ import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.jeecg.common.system.base.controller.JeecgController;
|
|
|
|
import org.jeecg.modules.airag.app.entity.AiragButton;
|
|
|
|
import org.jeecg.modules.airag.app.service.IAiragButtonService;
|
|
|
|
import org.jeecg.modules.airag.app.service.RedisChatSetService;
|
|
|
|
import org.jeecg.modules.airag.llm.entity.AiragKnowledge;
|
|
|
|
import org.jeecg.modules.airag.llm.entity.AiragModel;
|
|
|
|
import org.jeecg.modules.airag.llm.service.IAiragKnowledgeService;
|
|
...
|
...
|
@@ -52,7 +53,8 @@ public class AiragChatsettingController extends JeecgController<AiragChatsetting |
|
|
|
|
|
|
|
@Autowired
|
|
|
|
private IAiragButtonService airagButtonService;
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
private RedisChatSetService redisChatSetService;
|
|
|
|
/**
|
|
|
|
* 获取字段数据
|
|
|
|
*
|
|
...
|
...
|
@@ -65,10 +67,18 @@ public class AiragChatsettingController extends JeecgController<AiragChatsetting |
|
|
|
public Result<Map<String, Object>> getConfigData(AiragChatsetting airagChatsetting) {
|
|
|
|
Map<String, Object> result = new HashMap<>();
|
|
|
|
|
|
|
|
// 获取配置数据(只取第一条)
|
|
|
|
AiragChatsetting airagChatsettingConfig = airagChatsettingService.getOne(new QueryWrapper<>());
|
|
|
|
// 先从Redis获取配置数据
|
|
|
|
AiragChatsetting airagChatsettingConfig = redisChatSetService.getChatSetting();
|
|
|
|
|
|
|
|
// 如果Redis中没有,则从数据库查询并存入Redis
|
|
|
|
if (airagChatsettingConfig == null) {
|
|
|
|
airagChatsettingConfig = new AiragChatsetting();
|
|
|
|
airagChatsettingConfig = airagChatsettingService.getOne(new QueryWrapper<>());
|
|
|
|
if (airagChatsettingConfig != null) {
|
|
|
|
// 存入Redis
|
|
|
|
redisChatSetService.saveChatSetting(airagChatsettingConfig);
|
|
|
|
} else {
|
|
|
|
airagChatsettingConfig = new AiragChatsetting();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 处理按钮ID为数组
|
|
...
|
...
|
@@ -76,7 +86,7 @@ public class AiragChatsettingController extends JeecgController<AiragChatsetting |
|
|
|
airagChatsettingConfig.setButtonIds(Arrays.asList(airagChatsettingConfig.getButtonId().split(",")));
|
|
|
|
}
|
|
|
|
|
|
|
|
// 直接查询选项数据
|
|
|
|
|
|
|
|
result.put("airagChatsettingConfig", airagChatsettingConfig);
|
|
|
|
result.put("embeddingOptions", getModelOptions("EMBED"));
|
|
|
|
result.put("llmOptions", getModelOptions("LLM"));
|
|
...
|
...
|
@@ -148,30 +158,30 @@ public class AiragChatsettingController extends JeecgController<AiragChatsetting |
|
|
|
* @param config
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
@AutoLog(value = "智能助手配置-编辑")
|
|
|
|
@Operation(summary="智能助手配置-编辑")
|
|
|
|
@RequiresPermissions("airagchatsetting:airag_chatsetting:saveConfig")
|
|
|
|
@RequestMapping(value = "/saveConfig", method = {RequestMethod.PUT,RequestMethod.POST})
|
|
|
|
public Result<String> saveConfig(@RequestBody AiragChatsetting config) {
|
|
|
|
// 处理多选按钮ID
|
|
|
|
if (config.getButtonIds() != null && !config.getButtonIds().isEmpty()) {
|
|
|
|
config.setButtonId(String.join(",", config.getButtonIds()));
|
|
|
|
} else {
|
|
|
|
config.setButtonId(null);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(StringUtils.isNotBlank(config.getId())){
|
|
|
|
airagChatsettingService.updateById(config);
|
|
|
|
return Result.OK("更新成功!");
|
|
|
|
}else{
|
|
|
|
if(airagChatsettingService.list().isEmpty()){
|
|
|
|
return Result.OK("只需要一条配置信息");
|
|
|
|
}
|
|
|
|
config.setId(UUID.randomUUID().toString());
|
|
|
|
airagChatsettingService.save(config);
|
|
|
|
return Result.OK("创建成功!");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
@AutoLog(value = "智能助手配置-编辑")
|
|
|
|
@Operation(summary="智能助手配置-编辑")
|
|
|
|
@RequiresPermissions("airagchatsetting:airag_chatsetting:saveConfig")
|
|
|
|
@RequestMapping(value = "/saveConfig", method = {RequestMethod.PUT,RequestMethod.POST})
|
|
|
|
public Result<String> saveConfig(@RequestBody AiragChatsetting config) {
|
|
|
|
// 处理多选按钮ID
|
|
|
|
if (config.getButtonIds() != null && !config.getButtonIds().isEmpty()) {
|
|
|
|
config.setButtonId(String.join(",", config.getButtonIds()));
|
|
|
|
} else {
|
|
|
|
config.setButtonId(null);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 数据库操作
|
|
|
|
if(StringUtils.isNotBlank(config.getId())) {
|
|
|
|
airagChatsettingService.updateById(config);
|
|
|
|
} else {
|
|
|
|
config.setId(UUID.randomUUID().toString());
|
|
|
|
airagChatsettingService.save(config);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 更新Redis缓存(无论新增还是修改都同步)
|
|
|
|
redisChatSetService.saveChatSetting(config);
|
|
|
|
|
|
|
|
return Result.OK(StringUtils.isNotBlank(config.getId()) ? "更新成功!" : "创建成功!");
|
|
|
|
}
|
|
|
|
|
|
|
|
} |
...
|
...
|
|