正在显示
13 个修改的文件
包含
326 行增加
和
89 行删除
| 1 | +package org.jeecg.modules.airag.airagchatsetting.controller; | ||
| 2 | + | ||
| 3 | +import java.util.*; | ||
| 4 | +import javax.servlet.http.HttpServletRequest; | ||
| 5 | +import javax.servlet.http.HttpServletResponse; | ||
| 6 | + | ||
| 7 | +import org.apache.commons.lang3.StringUtils; | ||
| 8 | +import org.jeecg.common.api.vo.Result; | ||
| 9 | +import org.jeecg.common.system.query.QueryGenerator; | ||
| 10 | +import org.jeecg.modules.airag.airagchatsetting.entity.AiragChatsetting; | ||
| 11 | +import org.jeecg.modules.airag.airagchatsetting.service.IAiragChatsettingService; | ||
| 12 | + | ||
| 13 | +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | ||
| 14 | +import com.baomidou.mybatisplus.core.metadata.IPage; | ||
| 15 | +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | ||
| 16 | +import lombok.extern.slf4j.Slf4j; | ||
| 17 | + | ||
| 18 | +import org.jeecg.common.system.base.controller.JeecgController; | ||
| 19 | +import org.jeecg.modules.airag.app.entity.AiragButton; | ||
| 20 | +import org.jeecg.modules.airag.app.service.IAiragButtonService; | ||
| 21 | +import org.jeecg.modules.airag.llm.entity.AiragKnowledge; | ||
| 22 | +import org.jeecg.modules.airag.llm.entity.AiragModel; | ||
| 23 | +import org.jeecg.modules.airag.llm.service.IAiragKnowledgeService; | ||
| 24 | +import org.jeecg.modules.airag.llm.service.IAiragModelService; | ||
| 25 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 26 | +import org.springframework.web.bind.annotation.*; | ||
| 27 | +import org.springframework.web.servlet.ModelAndView; | ||
| 28 | +import io.swagger.v3.oas.annotations.tags.Tag; | ||
| 29 | +import io.swagger.v3.oas.annotations.Operation; | ||
| 30 | +import org.jeecg.common.aspect.annotation.AutoLog; | ||
| 31 | +import org.apache.shiro.authz.annotation.RequiresPermissions; | ||
| 32 | + | ||
| 33 | + /** | ||
| 34 | + * @Description: 智能助手配置 | ||
| 35 | + * @Author: jeecg-boot | ||
| 36 | + * @Date: 2025-06-27 | ||
| 37 | + * @Version: V1.0 | ||
| 38 | + */ | ||
| 39 | +@Tag(name="智能助手配置") | ||
| 40 | +@RestController | ||
| 41 | +@RequestMapping("/airagchatsetting/airagChatsetting") | ||
| 42 | +@Slf4j | ||
| 43 | +public class AiragChatsettingController extends JeecgController<AiragChatsetting, IAiragChatsettingService> { | ||
| 44 | + @Autowired | ||
| 45 | + private IAiragChatsettingService airagChatsettingService; | ||
| 46 | + | ||
| 47 | + @Autowired | ||
| 48 | + private IAiragModelService airagModelService; | ||
| 49 | + | ||
| 50 | + @Autowired | ||
| 51 | + private IAiragKnowledgeService airagKnowledgeService; | ||
| 52 | + | ||
| 53 | + @Autowired | ||
| 54 | + private IAiragButtonService airagButtonService; | ||
| 55 | + | ||
| 56 | + /** | ||
| 57 | + * 获取字段数据 | ||
| 58 | + * | ||
| 59 | + * @param airagChatsetting | ||
| 60 | + * @return | ||
| 61 | + */ | ||
| 62 | + //@AutoLog(value = "智能助手配置-分页列表查询") | ||
| 63 | + @Operation(summary="智能助手配置-获取字段数据") | ||
| 64 | + @GetMapping(value = "/getConfigData") | ||
| 65 | + public Result<Map<String, Object>> getConfigData(AiragChatsetting airagChatsetting) { | ||
| 66 | + Map<String, Object> result = new HashMap<>(); | ||
| 67 | + | ||
| 68 | + // 获取配置数据(只取第一条) | ||
| 69 | + AiragChatsetting airagChatsettingConfig = airagChatsettingService.getOne(new QueryWrapper<>()); | ||
| 70 | + if (airagChatsettingConfig == null) { | ||
| 71 | + airagChatsettingConfig = new AiragChatsetting(); | ||
| 72 | + } | ||
| 73 | + | ||
| 74 | + // 处理按钮ID为数组 | ||
| 75 | + if (StringUtils.isNotBlank(airagChatsettingConfig.getButtonId())) { | ||
| 76 | + airagChatsettingConfig.setButtonIds(Arrays.asList(airagChatsettingConfig.getButtonId().split(","))); | ||
| 77 | + } | ||
| 78 | + | ||
| 79 | + // 直接查询选项数据 | ||
| 80 | + result.put("airagChatsettingConfig", airagChatsettingConfig); | ||
| 81 | + result.put("embeddingOptions", getModelOptions("EMBED")); | ||
| 82 | + result.put("llmOptions", getModelOptions("LLM")); | ||
| 83 | + result.put("knowledgeOptions", getKnowledgeOptions()); | ||
| 84 | + result.put("buttonOptions", getButtonOptions()); | ||
| 85 | + | ||
| 86 | + return Result.OK(result); | ||
| 87 | + } | ||
| 88 | + | ||
| 89 | + | ||
| 90 | + /** | ||
| 91 | + * 获取模型名称 | ||
| 92 | + * @params modelType 根据对应的type来获取对应的模型名称 | ||
| 93 | + */ | ||
| 94 | + private List<Map<String, Object>> getModelOptions (String modelType) { | ||
| 95 | + List<AiragModel> modelList = airagModelService.list( | ||
| 96 | + new QueryWrapper<AiragModel>(). | ||
| 97 | + eq("model_type", modelType)); | ||
| 98 | + | ||
| 99 | + List<Map<String, Object>> options = new ArrayList<>(); | ||
| 100 | + for(AiragModel airagModel : modelList) { | ||
| 101 | + Map<String, Object> option = new HashMap<>(); | ||
| 102 | + option.put("value", airagModel.getId()); | ||
| 103 | + option.put("label", airagModel.getModelName()); | ||
| 104 | + options.add(option); | ||
| 105 | + } | ||
| 106 | + return options; | ||
| 107 | + } | ||
| 108 | + | ||
| 109 | + /** | ||
| 110 | + * 获取知识库名称 | ||
| 111 | + */ | ||
| 112 | + private List<Map<String, Object>> getKnowledgeOptions () { | ||
| 113 | + List<AiragKnowledge> knowledgeList = airagKnowledgeService.list(); | ||
| 114 | + | ||
| 115 | + List<Map<String, Object>> options = new ArrayList<>(); | ||
| 116 | + for(AiragKnowledge airagKnowledge : knowledgeList) { | ||
| 117 | + Map<String, Object> option = new HashMap<>(); | ||
| 118 | + option.put("value", airagKnowledge.getId()); | ||
| 119 | + option.put("label", airagKnowledge.getName()); | ||
| 120 | + options.add(option); | ||
| 121 | + } | ||
| 122 | + | ||
| 123 | + return options; | ||
| 124 | + } | ||
| 125 | + | ||
| 126 | + | ||
| 127 | + /** | ||
| 128 | + * 获取按钮名称 | ||
| 129 | + */ | ||
| 130 | + private List<Map<String, Object>> getButtonOptions () { | ||
| 131 | + List<AiragButton> buttonList = airagButtonService.list(); | ||
| 132 | + | ||
| 133 | + List<Map<String, Object>> options = new ArrayList<>(); | ||
| 134 | + for(AiragButton airagButton : buttonList) { | ||
| 135 | + Map<String, Object> option = new HashMap<>(); | ||
| 136 | + option.put("value", airagButton.getId()); | ||
| 137 | + option.put("label", airagButton.getButtonName()); | ||
| 138 | + options.add(option); | ||
| 139 | + } | ||
| 140 | + | ||
| 141 | + return options; | ||
| 142 | + } | ||
| 143 | + | ||
| 144 | + | ||
| 145 | + /** | ||
| 146 | + * 编辑 | ||
| 147 | + * | ||
| 148 | + * @param config | ||
| 149 | + * @return | ||
| 150 | + */ | ||
| 151 | + @AutoLog(value = "智能助手配置-编辑") | ||
| 152 | + @Operation(summary="智能助手配置-编辑") | ||
| 153 | + @RequiresPermissions("airagchatsetting:airag_chatsetting:saveConfig") | ||
| 154 | + @RequestMapping(value = "/saveConfig", method = {RequestMethod.PUT,RequestMethod.POST}) | ||
| 155 | + public Result<String> saveConfig(@RequestBody AiragChatsetting config) { | ||
| 156 | + // 处理多选按钮ID | ||
| 157 | + if (config.getButtonIds() != null && !config.getButtonIds().isEmpty()) { | ||
| 158 | + config.setButtonId(String.join(",", config.getButtonIds())); | ||
| 159 | + } else { | ||
| 160 | + config.setButtonId(null); | ||
| 161 | + } | ||
| 162 | + | ||
| 163 | + if(StringUtils.isNotBlank(config.getId())){ | ||
| 164 | + airagChatsettingService.updateById(config); | ||
| 165 | + return Result.OK("更新成功!"); | ||
| 166 | + }else{ | ||
| 167 | + if(airagChatsettingService.list().isEmpty()){ | ||
| 168 | + return Result.OK("只需要一条配置信息"); | ||
| 169 | + } | ||
| 170 | + config.setId(UUID.randomUUID().toString()); | ||
| 171 | + airagChatsettingService.save(config); | ||
| 172 | + return Result.OK("创建成功!"); | ||
| 173 | + } | ||
| 174 | + | ||
| 175 | + } | ||
| 176 | + | ||
| 177 | +} |
| 1 | +package org.jeecg.modules.airag.airagchatsetting.entity; | ||
| 2 | + | ||
| 3 | +import java.io.Serializable; | ||
| 4 | +import java.io.UnsupportedEncodingException; | ||
| 5 | +import java.util.Date; | ||
| 6 | +import java.math.BigDecimal; | ||
| 7 | +import java.util.List; | ||
| 8 | + | ||
| 9 | +import com.baomidou.mybatisplus.annotation.*; | ||
| 10 | +import org.jeecg.common.constant.ProvinceCityArea; | ||
| 11 | +import org.jeecg.common.util.SpringContextUtils; | ||
| 12 | +import lombok.Data; | ||
| 13 | +import com.fasterxml.jackson.annotation.JsonFormat; | ||
| 14 | +import org.springframework.format.annotation.DateTimeFormat; | ||
| 15 | +import org.jeecgframework.poi.excel.annotation.Excel; | ||
| 16 | +import org.jeecg.common.aspect.annotation.Dict; | ||
| 17 | +import io.swagger.v3.oas.annotations.media.Schema; | ||
| 18 | +import lombok.EqualsAndHashCode; | ||
| 19 | +import lombok.experimental.Accessors; | ||
| 20 | + | ||
| 21 | +/** | ||
| 22 | + * @Description: 智能助手配置 | ||
| 23 | + * @Author: jeecg-boot | ||
| 24 | + * @Date: 2025-06-27 | ||
| 25 | + * @Version: V1.0 | ||
| 26 | + */ | ||
| 27 | +@Data | ||
| 28 | +@TableName("airag_chatsetting") | ||
| 29 | +@Accessors(chain = true) | ||
| 30 | +@EqualsAndHashCode(callSuper = false) | ||
| 31 | +@Schema(description="智能助手配置") | ||
| 32 | +public class AiragChatsetting implements Serializable { | ||
| 33 | + private static final long serialVersionUID = 1L; | ||
| 34 | + | ||
| 35 | + /**主键*/ | ||
| 36 | + @TableId(type = IdType.ASSIGN_ID) | ||
| 37 | + @Schema(description = "主键") | ||
| 38 | + private java.lang.String id; | ||
| 39 | + /**创建人*/ | ||
| 40 | + @Schema(description = "创建人") | ||
| 41 | + private java.lang.String createBy; | ||
| 42 | + /**创建日期*/ | ||
| 43 | + @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss") | ||
| 44 | + @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") | ||
| 45 | + @Schema(description = "创建日期") | ||
| 46 | + private java.util.Date createTime; | ||
| 47 | + /**更新人*/ | ||
| 48 | + @Schema(description = "更新人") | ||
| 49 | + private java.lang.String updateBy; | ||
| 50 | + /**更新日期*/ | ||
| 51 | + @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss") | ||
| 52 | + @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") | ||
| 53 | + @Schema(description = "更新日期") | ||
| 54 | + private java.util.Date updateTime; | ||
| 55 | + /**所属部门*/ | ||
| 56 | + @Schema(description = "所属部门") | ||
| 57 | + private java.lang.String sysOrgCode; | ||
| 58 | + /**向量模型id*/ | ||
| 59 | + @Excel(name = "向量模型id", width = 15) | ||
| 60 | + @Schema(description = "向量模型id") | ||
| 61 | + private java.lang.String embeddingId; | ||
| 62 | + /**大语言模型id*/ | ||
| 63 | + @Excel(name = "大语言模型id", width = 15) | ||
| 64 | + @Schema(description = "大语言模型id") | ||
| 65 | + private java.lang.String llmId; | ||
| 66 | + /**知识库id*/ | ||
| 67 | + @Excel(name = "知识库id", width = 15) | ||
| 68 | + @Schema(description = "知识库id") | ||
| 69 | + private java.lang.String knowledgeId; | ||
| 70 | + /**头像*/ | ||
| 71 | + @Excel(name = "头像", width = 15) | ||
| 72 | + @Schema(description = "头像") | ||
| 73 | + private java.lang.String image; | ||
| 74 | + /**按钮id*/ | ||
| 75 | + @Excel(name = "按钮id", width = 15) | ||
| 76 | + @Schema(description = "按钮id") | ||
| 77 | + private java.lang.String buttonId; | ||
| 78 | + /**按钮id*/ | ||
| 79 | + @Excel(name = "提示词", width = 15) | ||
| 80 | + @Schema(description = "提示词") | ||
| 81 | + private java.lang.String prompt; | ||
| 82 | + // 新增:临时字段(非数据库字段) | ||
| 83 | + @TableField(exist = false) | ||
| 84 | + private List<String> buttonIds; | ||
| 85 | +} |
| 1 | +package org.jeecg.modules.airag.airagchatsetting.mapper; | ||
| 2 | + | ||
| 3 | +import org.jeecg.modules.airag.airagchatsetting.entity.AiragChatsetting; | ||
| 4 | +import com.baomidou.mybatisplus.core.mapper.BaseMapper; | ||
| 5 | + | ||
| 6 | +/** | ||
| 7 | + * @Description: 智能助手配置 | ||
| 8 | + * @Author: jeecg-boot | ||
| 9 | + * @Date: 2025-06-27 | ||
| 10 | + * @Version: V1.0 | ||
| 11 | + */ | ||
| 12 | +public interface AiragChatsettingMapper extends BaseMapper<AiragChatsetting> { | ||
| 13 | + | ||
| 14 | +} |
| 1 | +package org.jeecg.modules.airag.airagchatsetting.service; | ||
| 2 | + | ||
| 3 | +import org.jeecg.modules.airag.airagchatsetting.entity.AiragChatsetting; | ||
| 4 | +import com.baomidou.mybatisplus.extension.service.IService; | ||
| 5 | + | ||
| 6 | +/** | ||
| 7 | + * @Description: 智能助手配置 | ||
| 8 | + * @Author: jeecg-boot | ||
| 9 | + * @Date: 2025-06-27 | ||
| 10 | + * @Version: V1.0 | ||
| 11 | + */ | ||
| 12 | +public interface IAiragChatsettingService extends IService<AiragChatsetting> { | ||
| 13 | + | ||
| 14 | +} |
| 1 | +package org.jeecg.modules.airag.airagchatsetting.service.impl; | ||
| 2 | + | ||
| 3 | +import org.jeecg.modules.airag.airagchatsetting.entity.AiragChatsetting; | ||
| 4 | +import org.jeecg.modules.airag.airagchatsetting.mapper.AiragChatsettingMapper; | ||
| 5 | +import org.jeecg.modules.airag.airagchatsetting.service.IAiragChatsettingService; | ||
| 6 | +import org.springframework.stereotype.Service; | ||
| 7 | + | ||
| 8 | +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | ||
| 9 | + | ||
| 10 | +/** | ||
| 11 | + * @Description: 智能助手配置 | ||
| 12 | + * @Author: jeecg-boot | ||
| 13 | + * @Date: 2025-06-27 | ||
| 14 | + * @Version: V1.0 | ||
| 15 | + */ | ||
| 16 | +@Service | ||
| 17 | +public class AiragChatsettingServiceImpl extends ServiceImpl<AiragChatsettingMapper, AiragChatsetting> implements IAiragChatsettingService { | ||
| 18 | + | ||
| 19 | +} |
| @@ -55,7 +55,6 @@ public class AiragButtonController extends JeecgController<AiragButton, IAiragBu | @@ -55,7 +55,6 @@ public class AiragButtonController extends JeecgController<AiragButton, IAiragBu | ||
| 55 | QueryWrapper<AiragButton> queryWrapper = QueryGenerator.initQueryWrapper(airagButton, req.getParameterMap()); | 55 | QueryWrapper<AiragButton> queryWrapper = QueryGenerator.initQueryWrapper(airagButton, req.getParameterMap()); |
| 56 | Page<AiragButton> page = new Page<AiragButton>(pageNo, pageSize); | 56 | Page<AiragButton> page = new Page<AiragButton>(pageNo, pageSize); |
| 57 | IPage<AiragButton> pageList = airagButtonService.page(page, queryWrapper); | 57 | IPage<AiragButton> pageList = airagButtonService.page(page, queryWrapper); |
| 58 | -// pageList.setRecords(airagButtonService. findAll(airagButton)); | ||
| 59 | return Result.OK(pageList); | 58 | return Result.OK(pageList); |
| 60 | } | 59 | } |
| 61 | 60 |
| @@ -50,13 +50,12 @@ import java.util.stream.Collectors; | @@ -50,13 +50,12 @@ import java.util.stream.Collectors; | ||
| 50 | @RequestMapping("/airaglog/airagLog") | 50 | @RequestMapping("/airaglog/airagLog") |
| 51 | @Slf4j | 51 | @Slf4j |
| 52 | public class AiragLogController extends JeecgController<AiragLog, IAiragLogService> { | 52 | public class AiragLogController extends JeecgController<AiragLog, IAiragLogService> { |
| 53 | - @Autowired | ||
| 54 | - private IAiragLogService airagLogService; | 53 | + @Autowired |
| 54 | + private IAiragLogService airagLogService; | ||
| 55 | 55 | ||
| 56 | - @Autowired | ||
| 57 | - private IAiragModelService airagModelService; | ||
| 58 | @Autowired | 56 | @Autowired |
| 59 | - private DataSourceConfig dataSourceConfig; | 57 | + private IAiragModelService airagModelService; |
| 58 | + | ||
| 60 | 59 | ||
| 61 | @Autowired | 60 | @Autowired |
| 62 | private IQuestionEmbeddingService questionEmbeddingService; | 61 | private IQuestionEmbeddingService questionEmbeddingService; |
| @@ -94,20 +94,17 @@ public class EmbeddingsController { | @@ -94,20 +94,17 @@ public class EmbeddingsController { | ||
| 94 | @RequiresPermissions("embeddings:embeddings:add") | 94 | @RequiresPermissions("embeddings:embeddings:add") |
| 95 | @PostMapping(value = "/add") | 95 | @PostMapping(value = "/add") |
| 96 | public Result<String> add(@RequestBody Embeddings embeddings) { | 96 | public Result<String> add(@RequestBody Embeddings embeddings) { |
| 97 | -// embeddingsService.save(Embeddings); | ||
| 98 | // 1. 构建完整的metadata | 97 | // 1. 构建完整的metadata |
| 99 | Map<String, Object> metadata = embeddings.getMetadata(); | 98 | Map<String, Object> metadata = embeddings.getMetadata(); |
| 100 | SnowflakeGenerator snowflakeGenerator = new SnowflakeGenerator(); | 99 | SnowflakeGenerator snowflakeGenerator = new SnowflakeGenerator(); |
| 101 | metadata.put("docName", embeddings.getDocName()); | 100 | metadata.put("docName", embeddings.getDocName()); |
| 102 | String docId = String.valueOf(snowflakeGenerator.next()); | 101 | String docId = String.valueOf(snowflakeGenerator.next()); |
| 103 | metadata.put("docId", docId); // 自动生成唯一文档ID | 102 | metadata.put("docId", docId); // 自动生成唯一文档ID |
| 104 | - metadata.put("index", "0"); // 默认索引位置为0 | 103 | + metadata.put("index", "0"); // 默认索引位置为0 |
| 105 | // 2. 设置到embeddings对象 | 104 | // 2. 设置到embeddings对象 |
| 106 | embeddings.setMetadata(metadata); | 105 | embeddings.setMetadata(metadata); |
| 107 | 106 | ||
| 108 | - /*// 3. 生成向量嵌入(实际项目中应调用嵌入模型API) | ||
| 109 | - embeddings.setEmbedding(generateEmbedding(embeddings.getText())); | ||
| 110 | -*/ | 107 | + |
| 111 | System.out.println(new SnowflakeGenerator().next()); | 108 | System.out.println(new SnowflakeGenerator().next()); |
| 112 | 109 | ||
| 113 | embeddingsService.insert(embeddings); | 110 | embeddingsService.insert(embeddings); |
| @@ -125,15 +122,6 @@ public class EmbeddingsController { | @@ -125,15 +122,6 @@ public class EmbeddingsController { | ||
| 125 | @RequiresPermissions("embeddings:embeddings:edit") | 122 | @RequiresPermissions("embeddings:embeddings:edit") |
| 126 | @RequestMapping(value = "/edit", method = {RequestMethod.PUT, RequestMethod.POST}) | 123 | @RequestMapping(value = "/edit", method = {RequestMethod.PUT, RequestMethod.POST}) |
| 127 | public Result<String> edit(@RequestBody Embeddings embeddings) { | 124 | public Result<String> edit(@RequestBody Embeddings embeddings) { |
| 128 | -// embeddingsService.updateById(Embeddings); | ||
| 129 | -// Map<String, Object> metadata = embeddings.getMetadata(); | ||
| 130 | -// SnowflakeGenerator snowflakeGenerator = new SnowflakeGenerator(); | ||
| 131 | -// metadata.put("docName", embeddings.getDocName()); | ||
| 132 | -// String docId = String.valueOf(snowflakeGenerator.next()); | ||
| 133 | -// metadata.put("docId", docId); // 自动生成唯一文档ID | ||
| 134 | -// metadata.put("index", "0"); | ||
| 135 | -// // 2. 设置到embeddings对象 | ||
| 136 | -// embeddings.setMetadata(metadata); | ||
| 137 | embeddingsService.update(embeddings); | 125 | embeddingsService.update(embeddings); |
| 138 | return Result.OK("编辑成功!"); | 126 | return Result.OK("编辑成功!"); |
| 139 | } | 127 | } |
| @@ -149,7 +137,6 @@ public class EmbeddingsController { | @@ -149,7 +137,6 @@ public class EmbeddingsController { | ||
| 149 | @RequiresPermissions("embeddings:embeddings:delete") | 137 | @RequiresPermissions("embeddings:embeddings:delete") |
| 150 | @DeleteMapping(value = "/delete") | 138 | @DeleteMapping(value = "/delete") |
| 151 | public Result<String> delete(@RequestParam(name = "id", required = true) String id) { | 139 | public Result<String> delete(@RequestParam(name = "id", required = true) String id) { |
| 152 | - //embeddingsService.removeById(id); | ||
| 153 | embeddingsService.deleteById(id); | 140 | embeddingsService.deleteById(id); |
| 154 | return Result.OK("删除成功!"); | 141 | return Result.OK("删除成功!"); |
| 155 | } | 142 | } |
| @@ -179,10 +166,6 @@ public class EmbeddingsController { | @@ -179,10 +166,6 @@ public class EmbeddingsController { | ||
| 179 | @Operation(summary = "Embeddings-通过id查询") | 166 | @Operation(summary = "Embeddings-通过id查询") |
| 180 | @GetMapping(value = "/queryById") | 167 | @GetMapping(value = "/queryById") |
| 181 | public Result<Embeddings> queryById(@RequestParam(name = "id", required = true) String id) { | 168 | public Result<Embeddings> queryById(@RequestParam(name = "id", required = true) String id) { |
| 182 | -// Embeddings Embeddings = embeddingsService.getById(id); | ||
| 183 | -// if(Embeddings==null) { | ||
| 184 | -// return Result.error("未找到对应数据"); | ||
| 185 | -// } | ||
| 186 | embeddingsService.findById(id); | 169 | embeddingsService.findById(id); |
| 187 | return Result.OK(); | 170 | return Result.OK(); |
| 188 | } | 171 | } |
| @@ -151,7 +151,7 @@ public class PgVectorMapper { | @@ -151,7 +151,7 @@ public class PgVectorMapper { | ||
| 151 | List<Object> params = new ArrayList<>(); | 151 | List<Object> params = new ArrayList<>(); |
| 152 | 152 | ||
| 153 | if(StringUtils.isNotBlank(embeddings.getText())){ | 153 | if(StringUtils.isNotBlank(embeddings.getText())){ |
| 154 | - sql.append(" AND text = ?"); // 使用 ILIKE 进行不区分大小写的模糊匹配 | 154 | + sql.append(" AND text = ?"); |
| 155 | params.add(embeddings.getText()); | 155 | params.add(embeddings.getText()); |
| 156 | } | 156 | } |
| 157 | 157 | ||
| @@ -185,7 +185,6 @@ public class PgVectorMapper { | @@ -185,7 +185,6 @@ public class PgVectorMapper { | ||
| 185 | PreparedStatement stmt = conn.prepareStatement(sql)) { | 185 | PreparedStatement stmt = conn.prepareStatement(sql)) { |
| 186 | 186 | ||
| 187 | stmt.setString(1, UUID.randomUUID().toString()); | 187 | stmt.setString(1, UUID.randomUUID().toString()); |
| 188 | -// stmt.setObject(2, new PGvector(record.getEmbedding())); | ||
| 189 | Response<Embedding> embedding = aiModelUtils.getEmbedding(embedId, record.getText()); | 188 | Response<Embedding> embedding = aiModelUtils.getEmbedding(embedId, record.getText()); |
| 190 | stmt.setObject(2, embedding.content().vector()); | 189 | stmt.setObject(2, embedding.content().vector()); |
| 191 | stmt.setObject(3, record.getText()); | 190 | stmt.setObject(3, record.getText()); |
| @@ -211,7 +210,7 @@ public class PgVectorMapper { | @@ -211,7 +210,7 @@ public class PgVectorMapper { | ||
| 211 | //获取record数据中的docId | 210 | //获取record数据中的docId |
| 212 | Map<String, Object> map = record.getMetadata(); | 211 | Map<String, Object> map = record.getMetadata(); |
| 213 | System.out.println("map = " + map); | 212 | System.out.println("map = " + map); |
| 214 | - mataData.put("docId", record.getDocId()); // 自动生成唯一文档ID | 213 | + mataData.put("docId", record.getDocId()); |
| 215 | mataData.put("index", "0"); | 214 | mataData.put("index", "0"); |
| 216 | System.out.println("原始数据: " + mataData); | 215 | System.out.println("原始数据: " + mataData); |
| 217 | 216 |
| @@ -128,7 +128,7 @@ public class QuestionEmbeddingMapper { | @@ -128,7 +128,7 @@ public class QuestionEmbeddingMapper { | ||
| 128 | List<Object> params = new ArrayList<>(); | 128 | List<Object> params = new ArrayList<>(); |
| 129 | 129 | ||
| 130 | if(StringUtils.isNotBlank(questionEmbedding.getQuestion())){ | 130 | if(StringUtils.isNotBlank(questionEmbedding.getQuestion())){ |
| 131 | - sql.append(" AND question = ?"); // 使用 ILIKE 进行不区分大小写的模糊匹配 | 131 | + sql.append(" AND question = ?"); |
| 132 | params.add(questionEmbedding.getQuestion()); | 132 | params.add(questionEmbedding.getQuestion()); |
| 133 | } | 133 | } |
| 134 | 134 | ||
| @@ -208,13 +208,6 @@ public class QuestionEmbeddingMapper { | @@ -208,13 +208,6 @@ public class QuestionEmbeddingMapper { | ||
| 208 | stmt.setString(1, record.getText()); | 208 | stmt.setString(1, record.getText()); |
| 209 | stmt.setString(2, record.getQuestion()); | 209 | stmt.setString(2, record.getQuestion()); |
| 210 | stmt.setString(3, record.getAnswer()); | 210 | stmt.setString(3, record.getAnswer()); |
| 211 | - /* PGobject jsonObject = new PGobject(); | ||
| 212 | - jsonObject.setType("json"); | ||
| 213 | - | ||
| 214 | - JSONObject mataData = new JSONObject(); | ||
| 215 | -// mataData.put("knowledgeId",record.getKnowledgeId()); | ||
| 216 | - | ||
| 217 | - jsonObject.setValue(mataData.toJSONString());*/ | ||
| 218 | stmt.setObject(4, record.getMetadata()); | 211 | stmt.setObject(4, record.getMetadata()); |
| 219 | 212 | ||
| 220 | Response<Embedding> embedding = aiModelUtils.getEmbedding(embedId, record.getQuestion()); | 213 | Response<Embedding> embedding = aiModelUtils.getEmbedding(embedId, record.getQuestion()); |
| @@ -401,48 +394,4 @@ public class QuestionEmbeddingMapper { | @@ -401,48 +394,4 @@ public class QuestionEmbeddingMapper { | ||
| 401 | } | 394 | } |
| 402 | } | 395 | } |
| 403 | 396 | ||
| 404 | - // 获取知识库名称映射 | ||
| 405 | - private Map<String, String> getKnowledgeNameMap(List<QuestionEmbedding> records) { | ||
| 406 | - // 提取所有知识库ID | ||
| 407 | - Set<String> knowledgeIds = records.stream() | ||
| 408 | - .map(QuestionEmbedding::getKnowledgeId) | ||
| 409 | - .filter(Objects::nonNull) | ||
| 410 | - .collect(Collectors.toSet()); | ||
| 411 | - | ||
| 412 | - if (knowledgeIds.isEmpty()) { | ||
| 413 | - return Collections.emptyMap(); | ||
| 414 | - } | ||
| 415 | - | ||
| 416 | - // 从 MySQL 查询知识库名称 | ||
| 417 | - Map<String, String> knowledgeNameMap = new HashMap<>(); | ||
| 418 | - try (Connection mysqlConn = getMysqlConnection()) { | ||
| 419 | - String placeholders = String.join(",", Collections.nCopies(knowledgeIds.size(), "?")); | ||
| 420 | - String sql = String.format("SELECT id, name FROM airag_knowledge WHERE id IN (%s)", placeholders); | ||
| 421 | - | ||
| 422 | - try (PreparedStatement stmt = mysqlConn.prepareStatement(sql)) { | ||
| 423 | - int index = 1; | ||
| 424 | - for (String id : knowledgeIds) { | ||
| 425 | - stmt.setString(index++, id); | ||
| 426 | - } | ||
| 427 | - | ||
| 428 | - try (ResultSet rs = stmt.executeQuery()) { | ||
| 429 | - while (rs.next()) { | ||
| 430 | - knowledgeNameMap.put(rs.getString("id"), rs.getString("name")); | ||
| 431 | - } | ||
| 432 | - } | ||
| 433 | - } | ||
| 434 | - } catch (SQLException e) { | ||
| 435 | - log.error("查询知识库名称失败", e); | ||
| 436 | - } | ||
| 437 | - | ||
| 438 | - return knowledgeNameMap; | ||
| 439 | - } | ||
| 440 | - | ||
| 441 | - // 获取 MySQL 连接 | ||
| 442 | - private Connection getMysqlConnection() throws SQLException { | ||
| 443 | - String url = "jdbc:mysql://localhost:3306/jeecg-boot-dev?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai"; | ||
| 444 | - String user = "root"; | ||
| 445 | - String password = "123456"; | ||
| 446 | - return DriverManager.getConnection(url, user, password); | ||
| 447 | - } | ||
| 448 | } | 397 | } |
| @@ -18,7 +18,6 @@ import java.util.Map; | @@ -18,7 +18,6 @@ import java.util.Map; | ||
| 18 | * @Version: V1.0 | 18 | * @Version: V1.0 |
| 19 | */ | 19 | */ |
| 20 | public interface IAiragLogService extends IService<AiragLog> { | 20 | public interface IAiragLogService extends IService<AiragLog> { |
| 21 | -// List<AiragLog> getLogListWithModelName(); | ||
| 22 | void saveToQuestionLibrary(AiragLog log) throws JsonProcessingException; | 21 | void saveToQuestionLibrary(AiragLog log) throws JsonProcessingException; |
| 23 | 22 | ||
| 24 | void saveToEmbeddingLibrary(AiragLog log) throws JsonProcessingException; | 23 | void saveToEmbeddingLibrary(AiragLog log) throws JsonProcessingException; |
| @@ -26,6 +25,4 @@ public interface IAiragLogService extends IService<AiragLog> { | @@ -26,6 +25,4 @@ public interface IAiragLogService extends IService<AiragLog> { | ||
| 26 | IPage<AiragLog> pageList(AiragLog airagLog, Page<AiragLog> page); | 25 | IPage<AiragLog> pageList(AiragLog airagLog, Page<AiragLog> page); |
| 27 | 26 | ||
| 28 | Map<String, Object> getStatistics(String rangeType, String startTime, String endTime); | 27 | Map<String, Object> getStatistics(String rangeType, String startTime, String endTime); |
| 29 | - | ||
| 30 | -// List<T> list(Page<AiragLog> page, QueryWrapper<AiragLog> queryWrapper); | ||
| 31 | } | 28 | } |
| @@ -60,7 +60,7 @@ public class AiragLogServiceImpl extends ServiceImpl<AiragLogMapper, AiragLog> i | @@ -60,7 +60,7 @@ public class AiragLogServiceImpl extends ServiceImpl<AiragLogMapper, AiragLog> i | ||
| 60 | SnowflakeGenerator snowflakeGenerator = new SnowflakeGenerator(); | 60 | SnowflakeGenerator snowflakeGenerator = new SnowflakeGenerator(); |
| 61 | metadata.put("docName", ""); | 61 | metadata.put("docName", ""); |
| 62 | String docId = String.valueOf(snowflakeGenerator.next()); | 62 | String docId = String.valueOf(snowflakeGenerator.next()); |
| 63 | - metadata.put("docId", docId); // 自动生成唯一文档ID | 63 | + metadata.put("docId", docId); |
| 64 | metadata.put("knowledgeId", questionEmbedding.getKnowledgeId()); | 64 | metadata.put("knowledgeId", questionEmbedding.getKnowledgeId()); |
| 65 | // 使用 Jackson 序列化 Map 到 JSON | 65 | // 使用 Jackson 序列化 Map 到 JSON |
| 66 | ObjectMapper mapper = new ObjectMapper(); | 66 | ObjectMapper mapper = new ObjectMapper(); |
| @@ -74,8 +74,6 @@ public class AiragLogServiceImpl extends ServiceImpl<AiragLogMapper, AiragLog> i | @@ -74,8 +74,6 @@ public class AiragLogServiceImpl extends ServiceImpl<AiragLogMapper, AiragLog> i | ||
| 74 | 74 | ||
| 75 | @Override | 75 | @Override |
| 76 | public void saveToEmbeddingLibrary(AiragLog log) throws JsonProcessingException { | 76 | public void saveToEmbeddingLibrary(AiragLog log) throws JsonProcessingException { |
| 77 | - // 这里实现将问题和回答存入问题库数据表的逻辑 | ||
| 78 | - // 假设问题库数据表的实体类为 QuestionLibrary,Mapper 接口为 QuestionLibraryMapper | ||
| 79 | Embeddings embeddings = new Embeddings(); | 77 | Embeddings embeddings = new Embeddings(); |
| 80 | embeddings.setText(log.getAnswer()); | 78 | embeddings.setText(log.getAnswer()); |
| 81 | embeddings.setKnowledgeId(log.getKnowledgeId()); | 79 | embeddings.setKnowledgeId(log.getKnowledgeId()); |
| @@ -144,13 +142,12 @@ public class AiragLogServiceImpl extends ServiceImpl<AiragLogMapper, AiragLog> i | @@ -144,13 +142,12 @@ public class AiragLogServiceImpl extends ServiceImpl<AiragLogMapper, AiragLog> i | ||
| 144 | startTime, | 142 | startTime, |
| 145 | endTime | 143 | endTime |
| 146 | ); | 144 | ); |
| 147 | - // 8.对按钮进行今日本周本月本年的实时查询和根据选定日期范围内的查询 | ||
| 148 | 145 | ||
| 149 | 146 | ||
| 150 | - // 9. 获取最近12个月的月度数据 | 147 | + // 8. 获取最近12个月的月度数据 |
| 151 | List<Map<String, Object>> monthlyData = airagLogMapper.getMonthlyCount(); | 148 | List<Map<String, Object>> monthlyData = airagLogMapper.getMonthlyCount(); |
| 152 | 149 | ||
| 153 | - // 10. 添加前一天数据 | 150 | + // 9. 添加数据 |
| 154 | result.put("yesterdayCount", yesterdayCount); | 151 | result.put("yesterdayCount", yesterdayCount); |
| 155 | result.put("growthRate", Math.round(growthRate * 100.0) / 100.0); // 保留两位小数 | 152 | result.put("growthRate", Math.round(growthRate * 100.0) / 100.0); // 保留两位小数 |
| 156 | result.put("todayCount", todayCount); | 153 | result.put("todayCount", todayCount); |
-
请 注册 或 登录 后发表评论