|
|
|
package org.jeecg.modules.airag.airagchatsetting.controller;
|
|
|
|
|
|
|
|
import java.util.*;
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
import org.jeecg.common.api.vo.Result;
|
|
|
|
import org.jeecg.common.system.query.QueryGenerator;
|
|
|
|
import org.jeecg.modules.airag.airagchatsetting.entity.AiragChatsetting;
|
|
|
|
import org.jeecg.modules.airag.airagchatsetting.service.IAiragChatsettingService;
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
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.llm.entity.AiragKnowledge;
|
|
|
|
import org.jeecg.modules.airag.llm.entity.AiragModel;
|
|
|
|
import org.jeecg.modules.airag.llm.service.IAiragKnowledgeService;
|
|
|
|
import org.jeecg.modules.airag.llm.service.IAiragModelService;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import org.springframework.web.servlet.ModelAndView;
|
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
|
|
import org.jeecg.common.aspect.annotation.AutoLog;
|
|
|
|
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Description: 智能助手配置
|
|
|
|
* @Author: jeecg-boot
|
|
|
|
* @Date: 2025-06-27
|
|
|
|
* @Version: V1.0
|
|
|
|
*/
|
|
|
|
@Tag(name="智能助手配置")
|
|
|
|
@RestController
|
|
|
|
@RequestMapping("/airagchatsetting/airagChatsetting")
|
|
|
|
@Slf4j
|
|
|
|
public class AiragChatsettingController extends JeecgController<AiragChatsetting, IAiragChatsettingService> {
|
|
|
|
@Autowired
|
|
|
|
private IAiragChatsettingService airagChatsettingService;
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
private IAiragModelService airagModelService;
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
private IAiragKnowledgeService airagKnowledgeService;
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
private IAiragButtonService airagButtonService;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 获取字段数据
|
|
|
|
*
|
|
|
|
* @param airagChatsetting
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
//@AutoLog(value = "智能助手配置-分页列表查询")
|
|
|
|
@Operation(summary="智能助手配置-获取字段数据")
|
|
|
|
@GetMapping(value = "/getConfigData")
|
|
|
|
public Result<Map<String, Object>> getConfigData(AiragChatsetting airagChatsetting) {
|
|
|
|
Map<String, Object> result = new HashMap<>();
|
|
|
|
|
|
|
|
// 获取配置数据(只取第一条)
|
|
|
|
AiragChatsetting airagChatsettingConfig = airagChatsettingService.getOne(new QueryWrapper<>());
|
|
|
|
if (airagChatsettingConfig == null) {
|
|
|
|
airagChatsettingConfig = new AiragChatsetting();
|
|
|
|
}
|
|
|
|
|
|
|
|
// 处理按钮ID为数组
|
|
|
|
if (StringUtils.isNotBlank(airagChatsettingConfig.getButtonId())) {
|
|
|
|
airagChatsettingConfig.setButtonIds(Arrays.asList(airagChatsettingConfig.getButtonId().split(",")));
|
|
|
|
}
|
|
|
|
|
|
|
|
// 直接查询选项数据
|
|
|
|
result.put("airagChatsettingConfig", airagChatsettingConfig);
|
|
|
|
result.put("embeddingOptions", getModelOptions("EMBED"));
|
|
|
|
result.put("llmOptions", getModelOptions("LLM"));
|
|
|
|
result.put("knowledgeOptions", getKnowledgeOptions());
|
|
|
|
result.put("buttonOptions", getButtonOptions());
|
|
|
|
|
|
|
|
return Result.OK(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 获取模型名称
|
|
|
|
* @params modelType 根据对应的type来获取对应的模型名称
|
|
|
|
*/
|
|
|
|
private List<Map<String, Object>> getModelOptions (String modelType) {
|
|
|
|
List<AiragModel> modelList = airagModelService.list(
|
|
|
|
new QueryWrapper<AiragModel>().
|
|
|
|
eq("model_type", modelType));
|
|
|
|
|
|
|
|
List<Map<String, Object>> options = new ArrayList<>();
|
|
|
|
for(AiragModel airagModel : modelList) {
|
|
|
|
Map<String, Object> option = new HashMap<>();
|
|
|
|
option.put("value", airagModel.getId());
|
|
|
|
option.put("label", airagModel.getModelName());
|
|
|
|
options.add(option);
|
|
|
|
}
|
|
|
|
return options;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 获取知识库名称
|
|
|
|
*/
|
|
|
|
private List<Map<String, Object>> getKnowledgeOptions () {
|
|
|
|
List<AiragKnowledge> knowledgeList = airagKnowledgeService.list();
|
|
|
|
|
|
|
|
List<Map<String, Object>> options = new ArrayList<>();
|
|
|
|
for(AiragKnowledge airagKnowledge : knowledgeList) {
|
|
|
|
Map<String, Object> option = new HashMap<>();
|
|
|
|
option.put("value", airagKnowledge.getId());
|
|
|
|
option.put("label", airagKnowledge.getName());
|
|
|
|
options.add(option);
|
|
|
|
}
|
|
|
|
|
|
|
|
return options;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 获取按钮名称
|
|
|
|
*/
|
|
|
|
private List<Map<String, Object>> getButtonOptions () {
|
|
|
|
List<AiragButton> buttonList = airagButtonService.list();
|
|
|
|
|
|
|
|
List<Map<String, Object>> options = new ArrayList<>();
|
|
|
|
for(AiragButton airagButton : buttonList) {
|
|
|
|
Map<String, Object> option = new HashMap<>();
|
|
|
|
option.put("value", airagButton.getId());
|
|
|
|
option.put("label", airagButton.getButtonName());
|
|
|
|
options.add(option);
|
|
|
|
}
|
|
|
|
|
|
|
|
return options;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 编辑
|
|
|
|
*
|
|
|
|
* @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("创建成功!");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} |
...
|
...
|
|