聊天时加入基因情况
This commit is contained in:
@@ -3,7 +3,9 @@ package com.peanut.common.utils;
|
|||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.peanut.config.WebSocket;
|
import com.peanut.config.WebSocket;
|
||||||
import com.peanut.modules.common.entity.AiChatContent;
|
import com.peanut.modules.common.entity.AiChatContent;
|
||||||
|
import com.peanut.modules.common.entity.PrecisionMedicineGene;
|
||||||
import com.peanut.modules.common.service.AiChatContentService;
|
import com.peanut.modules.common.service.AiChatContentService;
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.apache.http.Consts;
|
import org.apache.http.Consts;
|
||||||
import org.apache.http.HttpEntity;
|
import org.apache.http.HttpEntity;
|
||||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||||
@@ -138,8 +140,31 @@ public class RagFlowApiUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//与助手聊天流式
|
//与助手聊天流式
|
||||||
public void chatToAssistantStream(String chatId,String chatName,String sessionId,String sessionName,String question,String patientName) {
|
public void chatToAssistantStream(String chatId,String chatName,String sessionId,String sessionName,String question,String patientName,Map<String,Object> geneInfo) {
|
||||||
try {
|
try {
|
||||||
|
String allQuestion = question;
|
||||||
|
if (geneInfo!=null){
|
||||||
|
String geneStr = "";
|
||||||
|
String geneInfoStr = "";
|
||||||
|
String prescriptionStr = "";
|
||||||
|
List<PrecisionMedicineGene> geneList = (List<PrecisionMedicineGene>) geneInfo.get("geneList");
|
||||||
|
for (PrecisionMedicineGene gene:geneList){
|
||||||
|
// geneStr += gene.getName()+"("+gene.getNamecn()+")基因阳性。";
|
||||||
|
if (StringUtils.isEmpty(geneInfoStr)){
|
||||||
|
geneInfoStr = "已知"+gene.getDescription()+"匹配药材:"+gene.getTcmName()+"。";
|
||||||
|
}else {
|
||||||
|
geneInfoStr += gene.getDescription()+"匹配药材:"+gene.getTcmName()+"。";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
allQuestion+=geneStr+geneInfoStr;
|
||||||
|
List<Map<String,Object>> prescriptionList = (List<Map<String, Object>>) geneInfo.get("prescriptionList");
|
||||||
|
if (prescriptionList.size()>0){
|
||||||
|
for (Map<String, Object> prescription:prescriptionList) {
|
||||||
|
prescriptionStr+="基因匹配方剂:"+prescription.get("name")+",方剂组成:"+prescription.get("compose")+"出处:"+prescription.get("source");
|
||||||
|
}
|
||||||
|
allQuestion+=prescriptionStr;
|
||||||
|
}
|
||||||
|
}
|
||||||
String userId = ShiroUtils.getUId()+"";
|
String userId = ShiroUtils.getUId()+"";
|
||||||
Map<String, Object> entity = new HashMap<>();
|
Map<String, Object> entity = new HashMap<>();
|
||||||
entity.put("question", question);
|
entity.put("question", question);
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ import com.peanut.common.utils.RagFlowApiUtil;
|
|||||||
import com.peanut.common.utils.ShiroUtils;
|
import com.peanut.common.utils.ShiroUtils;
|
||||||
import com.peanut.modules.common.entity.AiChatContent;
|
import com.peanut.modules.common.entity.AiChatContent;
|
||||||
import com.peanut.modules.common.service.AiChatContentService;
|
import com.peanut.modules.common.service.AiChatContentService;
|
||||||
|
import com.peanut.modules.common.service.AiVipLogService;
|
||||||
|
import com.peanut.modules.common.service.PrecisionMedicineGeneService;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -13,6 +15,9 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@@ -25,13 +30,20 @@ public class RagFlowApiController {
|
|||||||
private RagFlowApiUtil ragFlowApiUtil;
|
private RagFlowApiUtil ragFlowApiUtil;
|
||||||
@Autowired
|
@Autowired
|
||||||
private AiChatContentService aiChatContentService;
|
private AiChatContentService aiChatContentService;
|
||||||
|
@Autowired
|
||||||
|
private AiVipLogService aiVipLogService;
|
||||||
|
@Autowired
|
||||||
|
private PrecisionMedicineGeneService geneService;
|
||||||
|
|
||||||
//聊天助手列表
|
//聊天助手列表
|
||||||
@RequestMapping("/getChatAssistants")
|
@RequestMapping("/getChatAssistants")
|
||||||
public R getChatAssistants() throws Exception{
|
public R getChatAssistants() throws Exception{
|
||||||
List<Map<String,Object>> list = ragFlowApiUtil.getChatAssistants("");
|
List<Map<String,Object>> list = ragFlowApiUtil.getChatAssistants("");
|
||||||
List<Map<String,Object>> res = list;
|
List<Map<String,Object>> res = new ArrayList<>();
|
||||||
for (int i=0; i<list.size(); i++) {
|
res.add(new HashMap<>());res.add(new HashMap<>());
|
||||||
|
res.add(new HashMap<>());res.add(new HashMap<>());
|
||||||
|
res.add(new HashMap<>());res.add(new HashMap<>());
|
||||||
|
for (int i=0; i<6; i++) {
|
||||||
Map<String,Object> map = list.get(i);
|
Map<String,Object> map = list.get(i);
|
||||||
if (map.get("name").toString().contains("消化")){
|
if (map.get("name").toString().contains("消化")){
|
||||||
res.set(0,map);
|
res.set(0,map);
|
||||||
@@ -72,15 +84,43 @@ public class RagFlowApiController {
|
|||||||
|
|
||||||
//创建会话
|
//创建会话
|
||||||
@RequestMapping("/createChat")
|
@RequestMapping("/createChat")
|
||||||
|
@Transactional
|
||||||
public R createChat(@RequestBody Map<String,Object> params) throws Exception{
|
public R createChat(@RequestBody Map<String,Object> params) throws Exception{
|
||||||
return R.ok().put("id",ragFlowApiUtil.createChat(params));
|
List<AiChatContent> quankeContentList = aiChatContentService.list(new LambdaQueryWrapper<AiChatContent>()
|
||||||
|
.eq(AiChatContent::getUserId,ShiroUtils.getUId())
|
||||||
|
.like(AiChatContent::getChatAssistantName,"全科")
|
||||||
|
.orderByAsc(AiChatContent::getCreateTime)
|
||||||
|
.groupBy(AiChatContent::getChatId));
|
||||||
|
if (!aiVipLogService.isAiVip()){
|
||||||
|
if (quankeContentList.size()>=3){
|
||||||
|
return R.error("试用机会已用完,开通VIP拥有更多次数");
|
||||||
|
}else {
|
||||||
|
if (!params.get("assistantName").toString().contains("全科")){
|
||||||
|
return R.error("免费次数只能使用全科医生");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
if (params.get("assistantName").toString().contains("全科")&&quankeContentList.size()<3){
|
||||||
|
}else {
|
||||||
|
boolean res = aiVipLogService.userCount();
|
||||||
|
if (!res){
|
||||||
|
return R.error("VIP次数已用完");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String chatId = ragFlowApiUtil.createChat(params);
|
||||||
|
return R.ok().put("id",chatId);
|
||||||
}
|
}
|
||||||
|
|
||||||
//与助手聊天流式
|
//与助手聊天流式
|
||||||
@RequestMapping(value = "/chatToAssistantStream")
|
@RequestMapping(value = "/chatToAssistantStream")
|
||||||
@Transactional
|
@Transactional
|
||||||
public R chatToAssistantStream(String chatId,String chatName,String sessionId,String sessionName,String question,String patientName){
|
public R chatToAssistantStream(String chatId,String chatName,String sessionId,String sessionName,String question,String patientName,String geneIds){
|
||||||
ragFlowApiUtil.chatToAssistantStream(chatId,chatName,sessionId,sessionName,question,patientName);
|
Map<String,Object> geneInfo = null;
|
||||||
|
if (StringUtils.isNotEmpty(geneIds)){
|
||||||
|
geneInfo = geneService.getGeneInfo(geneIds);
|
||||||
|
}
|
||||||
|
ragFlowApiUtil.chatToAssistantStream(chatId,chatName,sessionId,sessionName,question,patientName,geneInfo);
|
||||||
return R.ok();
|
return R.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user