| | |
| | | import org.ruoyi.common.core.utils.file.FileUtils; |
| | | import org.ruoyi.common.core.utils.file.MimeTypeUtils; |
| | | import org.ruoyi.common.redis.utils.RedisUtils; |
| | | import org.ruoyi.domain.ChatSession; |
| | | import org.ruoyi.domain.bo.ChatSessionBo; |
| | | import org.ruoyi.domain.vo.ChatModelVo; |
| | | import org.ruoyi.service.EmbeddingService; |
| | | import org.ruoyi.service.IChatModelService; |
| | | import org.ruoyi.service.IChatSessionService; |
| | | import org.ruoyi.service.VectorStoreService; |
| | | import org.springframework.core.io.InputStreamResource; |
| | | import org.springframework.core.io.Resource; |
| | |
| | | |
| | | private final OllamaServiceImpl ollamaService; |
| | | |
| | | private final IChatSessionService chatSessionService; |
| | | |
| | | private ChatModelVo chatModelVo; |
| | | |
| | | |
| | |
| | | }else { |
| | | LocalCache.CACHE.put("userId", chatCostService.getUserId()); |
| | | chatRequest.setUserId(chatCostService.getUserId()); |
| | | // 保存会话信息 |
| | | if(chatRequest.getSessionId()==null){ |
| | | ChatSessionBo chatSessionBo = new ChatSessionBo(); |
| | | chatSessionBo.setUserId(chatCostService.getUserId()); |
| | | chatSessionBo.setSessionTitle(getFirst10Characters(chatRequest.getPrompt())); |
| | | chatSessionBo.setSessionContent(chatRequest.getPrompt()); |
| | | chatSessionService.insertByBo(chatSessionBo); |
| | | chatRequest.setSessionId(chatSessionBo.getId()); |
| | | } |
| | | // 保存消息记录 并扣除费用 |
| | | chatCostService.deductToken(chatRequest); |
| | | } |
| | |
| | | } |
| | | |
| | | /** |
| | | * 获取对话标题 |
| | | * |
| | | * @param str 原字符 |
| | | * @return 截取后的字符 |
| | | */ |
| | | public static String getFirst10Characters(String str) { |
| | | // 判断字符串长度 |
| | | if (str.length() > 10) { |
| | | // 如果长度大于10,截取前10个字符 |
| | | return str.substring(0, 10); |
| | | } else { |
| | | // 如果长度不足10,返回整个字符串 |
| | | return str; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 检查未登录用户是否超过当日对话次数限制 |
| | | * |
| | | * @param request 当前请求 |