|
@@ -654,7 +654,7 @@ public class AiHookServiceImpl implements AiHookService {
|
|
|
}*/
|
|
}*/
|
|
|
if (result.isLongText()){
|
|
if (result.isLongText()){
|
|
|
//新增用户信息
|
|
//新增用户信息
|
|
|
- addUserInfo(contentKh, qwExternalContacts.getId(),fastGptChatSession);
|
|
|
|
|
|
|
+ addUserInfoNew(contentKh, qwExternalContacts.getId(),fastGptChatSession);
|
|
|
if (type==16){
|
|
if (type==16){
|
|
|
sendAiVoiceMsg(content,sender,uid,serverId,user);
|
|
sendAiVoiceMsg(content,sender,uid,serverId,user);
|
|
|
}else {
|
|
}else {
|
|
@@ -665,7 +665,7 @@ public class AiHookServiceImpl implements AiHookService {
|
|
|
|
|
|
|
|
List<String> countList = countString(content);
|
|
List<String> countList = countString(content);
|
|
|
//新增用户信息
|
|
//新增用户信息
|
|
|
- addUserInfo(contentKh, qwExternalContacts.getId(),fastGptChatSession);
|
|
|
|
|
|
|
+ addUserInfoNew(contentKh, qwExternalContacts.getId(),fastGptChatSession);
|
|
|
for (String msg : countList) {
|
|
for (String msg : countList) {
|
|
|
if (type==16){
|
|
if (type==16){
|
|
|
sendAiVoiceMsg(msg,sender,uid,serverId,user);
|
|
sendAiVoiceMsg(msg,sender,uid,serverId,user);
|
|
@@ -1537,7 +1537,7 @@ public class AiHookServiceImpl implements AiHookService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//添加关键词
|
|
//添加关键词
|
|
|
- addPromptWord(messageList,msgC,qwExternalContactsId,role.getReminderWords(), role.getContactInfo(),fastGptChatSession.getSessionId());
|
|
|
|
|
|
|
+ addPromptWordNew(messageList,msgC,qwExternalContactsId,role,fastGptChatSession);
|
|
|
R r = chatService.initiatingTakeChat(param, "http://1.95.196.10:3000/api/", appKey);
|
|
R r = chatService.initiatingTakeChat(param, "http://1.95.196.10:3000/api/", appKey);
|
|
|
Object data1 = r.get("data");
|
|
Object data1 = r.get("data");
|
|
|
if(!(data1 instanceof KnowledgeBaseResult)){
|
|
if(!(data1 instanceof KnowledgeBaseResult)){
|
|
@@ -1590,6 +1590,70 @@ public class AiHookServiceImpl implements AiHookService {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
/** 组装发送AI内容 **/
|
|
/** 组装发送AI内容 **/
|
|
|
|
|
+ private void addPromptWordNew(List<ChatParam.Message> messageList,String count,Long extId,FastGptRole role,FastGptChatSession fastGptChatSession){
|
|
|
|
|
+
|
|
|
|
|
+ FastGptChatConversation conversation = new FastGptChatConversation();
|
|
|
|
|
+ conversation.setAiInfo(new com.alibaba.fastjson.JSONObject());
|
|
|
|
|
+ conversation.setUserInfo(new com.alibaba.fastjson.JSONObject());
|
|
|
|
|
+ conversation.setHistory(new com.alibaba.fastjson.JSONObject());
|
|
|
|
|
+
|
|
|
|
|
+ //组装客户信息
|
|
|
|
|
+ String sessionUserInfo = fastGptChatSession.getUserInfo();
|
|
|
|
|
+ String[] split = role.getUserInfo().split(",");
|
|
|
|
|
+ com.alibaba.fastjson.JSONObject userInfo = conversation.getUserInfo();
|
|
|
|
|
+ if(sessionUserInfo != null){
|
|
|
|
|
+ Map<String,String> map = com.alibaba.fastjson.JSONObject.parseObject(sessionUserInfo, HashMap.class);
|
|
|
|
|
+ if(role.getUserInfo() != null){
|
|
|
|
|
+ for (String name : split) {
|
|
|
|
|
+ if (name != null) {
|
|
|
|
|
+ String value = map.get(name);
|
|
|
|
|
+ if(value != null){
|
|
|
|
|
+ userInfo.put(name,value);
|
|
|
|
|
+ }else{
|
|
|
|
|
+ userInfo.put(name,"");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }else{
|
|
|
|
|
+ for (String name : split) {
|
|
|
|
|
+ if (name != null) {
|
|
|
|
|
+ userInfo.put(name,"");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ List<FastGptChatMsg> msgs=fastGptChatMsgService.selectFastGptChatMsgByMsgSessionIdAndExtId(fastGptChatSession.getSessionId(),extId);
|
|
|
|
|
+ if (!msgs.isEmpty()){
|
|
|
|
|
+ com.alibaba.fastjson.JSONObject history = conversation.getHistory();
|
|
|
|
|
+ Collections.reverse(msgs);
|
|
|
|
|
+ msgs.remove(msgs.size() - 1);
|
|
|
|
|
+ for (FastGptChatMsg msg : msgs) {
|
|
|
|
|
+ Integer sendType = msg.getSendType();
|
|
|
|
|
+ String content = msg.getContent();
|
|
|
|
|
+ if(sendType!=1){
|
|
|
|
|
+ if (content!=null&&content.length()>150){
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ history.put(sendType==1?"user":"ai",content);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (count!=null&& !count.isEmpty()){
|
|
|
|
|
+ conversation.setUserContent(count);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ ChatParam.Message message1=new ChatParam.Message();
|
|
|
|
|
+ message1.setRole("user");
|
|
|
|
|
+ Gson gson = new Gson();
|
|
|
|
|
+ String jsonStr = gson.toJson(conversation);
|
|
|
|
|
+ message1.setContent(jsonStr);
|
|
|
|
|
+ messageList.add(message1);
|
|
|
|
|
+ }
|
|
|
|
|
+ /** 组装发送AI内容 **/
|
|
|
private void addPromptWord(List<ChatParam.Message> messageList,String count,Long extId,String words,String countInfo,Long sessionId){
|
|
private void addPromptWord(List<ChatParam.Message> messageList,String count,Long extId,String words,String countInfo,Long sessionId){
|
|
|
|
|
|
|
|
FastGptChatConversation conversation = new FastGptChatConversation();
|
|
FastGptChatConversation conversation = new FastGptChatConversation();
|
|
@@ -1683,7 +1747,10 @@ public class AiHookServiceImpl implements AiHookService {
|
|
|
|
|
|
|
|
List<String> stringList = new ArrayList<>();
|
|
List<String> stringList = new ArrayList<>();
|
|
|
// 所有的回车都分段发送
|
|
// 所有的回车都分段发送
|
|
|
- String[] split = input.split("\n");
|
|
|
|
|
|
|
+ String[] split = input.split("\n\n");
|
|
|
|
|
+ if(split.length == 1){
|
|
|
|
|
+ split = input.split("\n");
|
|
|
|
|
+ }
|
|
|
for (String s : split) {
|
|
for (String s : split) {
|
|
|
List<String> sList = subCount(s);
|
|
List<String> sList = subCount(s);
|
|
|
stringList.addAll(sList);
|
|
stringList.addAll(sList);
|
|
@@ -1733,36 +1800,57 @@ public class AiHookServiceImpl implements AiHookService {
|
|
|
|
|
|
|
|
return stringList;
|
|
return stringList;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ private static final Pattern SENTENCE_PATTERN = Pattern.compile("([~。!?]+)");
|
|
|
/** 内容分段 **/
|
|
/** 内容分段 **/
|
|
|
static List<String> subCount(String s){
|
|
static List<String> subCount(String s){
|
|
|
- ArrayList<String> a = new ArrayList<>();
|
|
|
|
|
- if (s.length()>30){
|
|
|
|
|
- String substring = s.substring(30);
|
|
|
|
|
- Pattern pattern = Pattern.compile("([~。!?]+)");
|
|
|
|
|
- String[] segments = pattern.split(substring);
|
|
|
|
|
- Matcher matcher = pattern.matcher(substring);
|
|
|
|
|
- if (matcher.find()&&segments.length>1) {
|
|
|
|
|
- int dh=0;
|
|
|
|
|
- String group = matcher.group();
|
|
|
|
|
- if (group.equals("。")){
|
|
|
|
|
- group="";
|
|
|
|
|
- dh=1;
|
|
|
|
|
- }
|
|
|
|
|
- String s1 = s.substring(0, 30) + segments[0] + group;
|
|
|
|
|
- a.addAll(Arrays.asList(s1));
|
|
|
|
|
- if (s.substring(s1.length())!=null&&!s.substring(s1.length()+dh).equals("")){
|
|
|
|
|
- List<String> add = subCount(s.substring(s1.length()+dh));
|
|
|
|
|
- a.addAll(add);
|
|
|
|
|
|
|
+ List<String> result = new ArrayList<>();
|
|
|
|
|
+
|
|
|
|
|
+ if (s == null || s.isEmpty()) {
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ int start = 0;
|
|
|
|
|
+ while (start < s.length()) {
|
|
|
|
|
+ if (s.length() - start <= 30) {
|
|
|
|
|
+ result.add(s.substring(start));
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ String remainingText = s.substring(start + 30);
|
|
|
|
|
+ Matcher matcher = SENTENCE_PATTERN.matcher(remainingText);
|
|
|
|
|
+
|
|
|
|
|
+ if (matcher.find()) {
|
|
|
|
|
+ String delimiter = matcher.group();
|
|
|
|
|
+ int delimiterEndPos = matcher.end();
|
|
|
|
|
+ String firstSegment = remainingText.substring(0, delimiterEndPos - delimiter.length());
|
|
|
|
|
+ String completeSegment = s.substring(start, start + 30) + firstSegment;
|
|
|
|
|
+
|
|
|
|
|
+ if ("。".equals(delimiter)) {
|
|
|
|
|
+ result.add(completeSegment);
|
|
|
|
|
+ start = start + 30 + (delimiterEndPos - delimiter.length()) + 1;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ result.add(completeSegment + delimiter);
|
|
|
|
|
+ start = start + 30 + delimiterEndPos;
|
|
|
}
|
|
}
|
|
|
- }else {
|
|
|
|
|
- a.add(s);
|
|
|
|
|
- return a;
|
|
|
|
|
|
|
+ } else {
|
|
|
|
|
+ result.add(s.substring(start));
|
|
|
|
|
+ break;
|
|
|
}
|
|
}
|
|
|
- }else {
|
|
|
|
|
- a.add(s);
|
|
|
|
|
}
|
|
}
|
|
|
- return a;
|
|
|
|
|
|
|
+
|
|
|
|
|
+ return result;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ private void addUserInfoNew(String word,Long extId,FastGptChatSession fastGptChatSession) {
|
|
|
|
|
+ com.alibaba.fastjson.JSONObject jsonObject = com.alibaba.fastjson.JSONObject.parseObject(word);
|
|
|
|
|
+ String userInfo = jsonObject.getString("userInfo");
|
|
|
|
|
+ FastGptChatSession chatSession = new FastGptChatSession();
|
|
|
|
|
+ chatSession.setSessionId(fastGptChatSession.getSessionId());
|
|
|
|
|
+ chatSession.setUserInfo(userInfo);
|
|
|
|
|
+ fastGptChatSessionMapper.updateFastGptChatSession(chatSession);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/** 增加用户信息以及打标签 **/
|
|
/** 增加用户信息以及打标签 **/
|
|
|
private void addUserInfo(String word,Long extId,FastGptChatSession fastGptChatSession) {
|
|
private void addUserInfo(String word,Long extId,FastGptChatSession fastGptChatSession) {
|
|
|
Pattern pattern = Pattern.compile("【用户状态信息(.*?)】", Pattern.DOTALL);
|
|
Pattern pattern = Pattern.compile("【用户状态信息(.*?)】", Pattern.DOTALL);
|
|
@@ -2098,28 +2186,28 @@ public class AiHookServiceImpl implements AiHookService {
|
|
|
}else {
|
|
}else {
|
|
|
|
|
|
|
|
if(qwExternalContacts.getType()!=null&&qwExternalContacts.getType()==1){
|
|
if(qwExternalContacts.getType()!=null&&qwExternalContacts.getType()==1){
|
|
|
- if(sendUser.getFastGptRoleId()!=null){
|
|
|
|
|
- fastGptChatSession = new FastGptChatSession();
|
|
|
|
|
- String chatId = UUID.randomUUID().toString();
|
|
|
|
|
- fastGptChatSession.setChatId(chatId);
|
|
|
|
|
|
|
+ fastGptChatSession = new FastGptChatSession();
|
|
|
|
|
+ String chatId = UUID.randomUUID().toString();
|
|
|
|
|
+ fastGptChatSession.setChatId(chatId);
|
|
|
|
|
+ if(sendUser.getFastGptRoleId() != null){
|
|
|
fastGptChatSession.setKfId(sendUser.getFastGptRoleId().toString());
|
|
fastGptChatSession.setKfId(sendUser.getFastGptRoleId().toString());
|
|
|
- fastGptChatSession.setStatus(1);
|
|
|
|
|
- fastGptChatSession.setRemindCount(0);
|
|
|
|
|
- fastGptChatSession.setRemindStatus(0);
|
|
|
|
|
- fastGptChatSession.setCreateTime(new Date());
|
|
|
|
|
- fastGptChatSession.setQwExtId(qwExternalContacts.getId());
|
|
|
|
|
- fastGptChatSession.setQwUserId(sendUser.getId());
|
|
|
|
|
- fastGptChatSession.setIsArtificial(0);
|
|
|
|
|
- fastGptChatSession.setAvatar(qwExternalContacts.getAvatar());
|
|
|
|
|
- fastGptChatSession.setNickName(qwExternalContacts.getName());
|
|
|
|
|
- fastGptChatSession.setCompanyId(sendUser.getCompanyId());
|
|
|
|
|
- fastGptChatSession.setLastTime(new Date());
|
|
|
|
|
- fastGptChatSession.setIsReply(0);
|
|
|
|
|
- fastGptChatSession.setUserId(String.valueOf(sender));
|
|
|
|
|
- fastGptChatSessionMapper.insertFastGptChatSession(fastGptChatSession);
|
|
|
|
|
- addUserSex(qwExternalContacts);
|
|
|
|
|
- saveQwUserMsg(fastGptChatSession,2,count,sendUser);
|
|
|
|
|
}
|
|
}
|
|
|
|
|
+ fastGptChatSession.setStatus(1);
|
|
|
|
|
+ fastGptChatSession.setRemindCount(0);
|
|
|
|
|
+ fastGptChatSession.setRemindStatus(0);
|
|
|
|
|
+ fastGptChatSession.setCreateTime(new Date());
|
|
|
|
|
+ fastGptChatSession.setQwExtId(qwExternalContacts.getId());
|
|
|
|
|
+ fastGptChatSession.setQwUserId(sendUser.getId());
|
|
|
|
|
+ fastGptChatSession.setIsArtificial(0);
|
|
|
|
|
+ fastGptChatSession.setAvatar(qwExternalContacts.getAvatar());
|
|
|
|
|
+ fastGptChatSession.setNickName(qwExternalContacts.getName());
|
|
|
|
|
+ fastGptChatSession.setCompanyId(sendUser.getCompanyId());
|
|
|
|
|
+ fastGptChatSession.setLastTime(new Date());
|
|
|
|
|
+ fastGptChatSession.setIsReply(0);
|
|
|
|
|
+ fastGptChatSession.setUserId(String.valueOf(sender));
|
|
|
|
|
+ fastGptChatSessionMapper.insertFastGptChatSession(fastGptChatSession);
|
|
|
|
|
+ addUserSex(qwExternalContacts);
|
|
|
|
|
+ saveQwUserMsg(fastGptChatSession,2,count,sendUser);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|