|
|
@ -13,6 +13,7 @@ import com.supervision.websocket.cache.WebSocketUserCache;
|
|
|
|
import com.supervision.websocket.dto.ActionDTO;
|
|
|
|
import com.supervision.websocket.dto.ActionDTO;
|
|
|
|
import com.supervision.websocket.dto.SocketMessageDTO;
|
|
|
|
import com.supervision.websocket.dto.SocketMessageDTO;
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
import org.springframework.web.socket.TextMessage;
|
|
|
|
import org.springframework.web.socket.TextMessage;
|
|
|
@ -21,6 +22,7 @@ import org.springframework.web.socket.WebSocketSession;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Slf4j
|
|
|
|
@Service
|
|
|
|
@Service
|
|
|
|
@RequiredArgsConstructor
|
|
|
|
@RequiredArgsConstructor
|
|
|
|
public class AskServiceImpl implements AskService {
|
|
|
|
public class AskServiceImpl implements AskService {
|
|
|
@ -42,17 +44,18 @@ public class AskServiceImpl implements AskService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// 进行rasa对话
|
|
|
|
// 进行rasa对话
|
|
|
|
List<String> rasaResultList = RasaUtil.talkRasa(text, socketMessageDTO.getSocketId());
|
|
|
|
List<String> rasaResultList = RasaUtil.talkRasa(text, socketMessageDTO.getSocketId());
|
|
|
|
|
|
|
|
log.info("问题:{},rasa回复:{}", text, JSONUtil.toJsonStr(rasaResultList));
|
|
|
|
WebSocketSession session = WebSocketUserCache.getSession(socketMessageDTO.getSocketId());
|
|
|
|
WebSocketSession session = WebSocketUserCache.getSession(socketMessageDTO.getSocketId());
|
|
|
|
for (String rasaResult : rasaResultList) {
|
|
|
|
for (String rasaResult : rasaResultList) {
|
|
|
|
if (StrUtil.isNotBlank(rasaResult)){
|
|
|
|
if (StrUtil.isNotBlank(rasaResult)) {
|
|
|
|
// 这里校验,rasa回复的结果是不是action
|
|
|
|
// 这里校验,rasa回复的结果是不是action
|
|
|
|
// 这里设置的模板,对于action的动作全部是用---进行标记,详情看生成rasa的yml的代码:RasaServiceImpl.generateDomain
|
|
|
|
// 这里设置的模板,对于action的动作全部是用---进行标记,详情看生成rasa的yml的代码:RasaServiceImpl.generateDomain
|
|
|
|
// ---ancillary---xxx
|
|
|
|
// ---ancillary---xxx
|
|
|
|
// ---tool---xxx
|
|
|
|
// ---tool---xxx
|
|
|
|
if (rasaResult.startsWith("---")){
|
|
|
|
if (rasaResult.startsWith("---")) {
|
|
|
|
// ["","ancillary","xxx"]
|
|
|
|
// ["","ancillary","xxx"]
|
|
|
|
List<String> actionList = StrUtil.split(rasaResult, "---");
|
|
|
|
List<String> actionList = StrUtil.split(rasaResult, "---");
|
|
|
|
if (actionList.size() > 2){
|
|
|
|
if (actionList.size() > 2) {
|
|
|
|
ActionDTO actionDTO = new ActionDTO();
|
|
|
|
ActionDTO actionDTO = new ActionDTO();
|
|
|
|
actionDTO.setActionType(actionList.get(1));
|
|
|
|
actionDTO.setActionType(actionList.get(1));
|
|
|
|
actionDTO.setActionId(actionList.get(2));
|
|
|
|
actionDTO.setActionId(actionList.get(2));
|
|
|
@ -65,7 +68,7 @@ public class AskServiceImpl implements AskService {
|
|
|
|
session.sendMessage(new TextMessage(JSONUtil.toJsonStr(res)));
|
|
|
|
session.sendMessage(new TextMessage(JSONUtil.toJsonStr(res)));
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}else {
|
|
|
|
} else {
|
|
|
|
// 走到这里,说明是文字,这个时候文字转语音
|
|
|
|
// 走到这里,说明是文字,这个时候文字转语音
|
|
|
|
String replyVoiceResVO = TtsUtil.ttsTransform(rasaResult);
|
|
|
|
String replyVoiceResVO = TtsUtil.ttsTransform(rasaResult);
|
|
|
|
// 在这里给socket回复
|
|
|
|
// 在这里给socket回复
|
|
|
@ -87,6 +90,7 @@ public class AskServiceImpl implements AskService {
|
|
|
|
res.setTextMessage("医生,我们有听懂您说的什么");
|
|
|
|
res.setTextMessage("医生,我们有听懂您说的什么");
|
|
|
|
res.setType(1);
|
|
|
|
res.setType(1);
|
|
|
|
session.sendMessage(new TextMessage(JSONUtil.toJsonStr(res)));
|
|
|
|
session.sendMessage(new TextMessage(JSONUtil.toJsonStr(res)));
|
|
|
|
|
|
|
|
log.info("兜底话术,需要检查上面是不是出什么问题了");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|