| | |
| | | import com.iailab.framework.common.util.object.BeanUtils; |
| | | import com.iailab.framework.tenant.core.util.TenantUtils; |
| | | import com.iailab.module.ai.controller.admin.chat.vo.message.*; |
| | | import com.iailab.module.ai.controller.admin.schedulesuggest.vo.ScheduleSuggestSaveReqVO; |
| | | import com.iailab.module.ai.dal.dataobject.chat.AiChatConversationDO; |
| | | import com.iailab.module.ai.dal.dataobject.chat.AiChatMessageDO; |
| | | import com.iailab.module.ai.dal.dataobject.knowledge.AiKnowledgeDocumentDO; |
| | |
| | | import com.iailab.module.ai.service.model.AiChatRoleService; |
| | | import com.iailab.module.ai.service.model.AiModelService; |
| | | import com.iailab.module.ai.service.model.AiToolService; |
| | | import com.iailab.module.ai.service.schedulesuggest.ScheduleSuggestService; |
| | | import jakarta.annotation.Resource; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.ObjectUtils; |
| | | import org.springframework.ai.chat.messages.Message; |
| | | import org.springframework.ai.chat.messages.MessageType; |
| | | import org.springframework.ai.chat.messages.SystemMessage; |
| | |
| | | |
| | | import java.time.LocalDateTime; |
| | | import java.util.*; |
| | | import java.util.regex.Matcher; |
| | | import java.util.regex.Pattern; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import static com.iailab.framework.common.exception.util.ServiceExceptionUtil.exception; |
| | |
| | | private AiKnowledgeDocumentService knowledgeDocumentService; |
| | | @Resource |
| | | private AiToolService toolService; |
| | | @Resource |
| | | private ScheduleSuggestService scheduleSuggestService; |
| | | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public AiChatMessageSendRespVO sendMessage(AiChatMessageSendReqVO sendReqVO, Long userId) { |
| | |
| | | .getKnowledgeDocument(segment.getDocumentId()); |
| | | segment.setDocumentName(document != null ? document.getName() : null); |
| | | }); |
| | | // 3.5 存储大模型推断结论 |
| | | if(model.getType().equals(6)) { |
| | | String scheduleSuggest = getScheduleSuggest(newContent); |
| | | if(ObjectUtils.isNotEmpty(scheduleSuggest)) { |
| | | ScheduleSuggestSaveReqVO saveReqVO = new ScheduleSuggestSaveReqVO(); |
| | | saveReqVO.setModelId(model.getId()) |
| | | .setConversationId(conversation.getId()) |
| | | .setMessageId(assistantMessage.getId()) |
| | | .setCreateTime(assistantMessage.getCreateTime()) |
| | | .setContent(scheduleSuggest); |
| | | scheduleSuggestService.createScheduleSuggest(saveReqVO); |
| | | } |
| | | } |
| | | return new AiChatMessageSendRespVO() |
| | | .setSend(BeanUtils.toBean(userMessage, AiChatMessageSendRespVO.Message.class)) |
| | | .setReceive(BeanUtils.toBean(assistantMessage, AiChatMessageSendRespVO.Message.class) |
| | |
| | | public PageResult<AiChatMessageDO> getChatMessagePage(AiChatMessagePageReqVO pageReqVO) { |
| | | return chatMessageMapper.selectPage(pageReqVO); |
| | | } |
| | | |
| | | private String getScheduleSuggest(String content) { |
| | | String spliceText = content.contains("总结:") ? "总结:" : "结论:"; |
| | | String regex = "^([\\s\\S]*?)" + spliceText + "([\\s\\S]*)$"; |
| | | Pattern pattern = java.util.regex.Pattern.compile(regex); |
| | | Matcher matcher = pattern.matcher(content); |
| | | if (matcher.find()) { |
| | | return matcher.group(2).trim(); |
| | | } |
| | | return ""; |
| | | } |
| | | } |