|
|
@@ -615,7 +615,7 @@ public class AiHookServiceImpl implements AiHookService {
|
|
|
return R.ok();
|
|
|
}
|
|
|
String contentKh = result.getChoices().get(0).getMessage().getContent();
|
|
|
- String finalContentKh = null;
|
|
|
+ /*String finalContentKh = null;
|
|
|
JSONArray jsonArray = JSON.parseArray(contentKh);
|
|
|
for (int i = 0; i < jsonArray.size(); i++) {
|
|
|
com.alibaba.fastjson.JSONObject jsonObject = (com.alibaba.fastjson.JSONObject)jsonArray.get(i);
|
|
|
@@ -626,8 +626,9 @@ public class AiHookServiceImpl implements AiHookService {
|
|
|
}
|
|
|
}
|
|
|
Gson gson = new Gson();
|
|
|
- contentKh = finalContentKh;
|
|
|
- FastGptChatConversation fastGptChatConversation = gson.fromJson(finalContentKh, FastGptChatConversation.class);
|
|
|
+ contentKh = finalContentKh;*/
|
|
|
+ Gson gson = new Gson();
|
|
|
+ FastGptChatConversation fastGptChatConversation = gson.fromJson(contentKh, FastGptChatConversation.class);
|
|
|
String content = fastGptChatConversation.getAiContent();
|
|
|
//计算token
|
|
|
List<ChatDetailTStreamFResult.ResponseNode> responseData = result.getResponseData();
|
|
|
@@ -657,23 +658,27 @@ public class AiHookServiceImpl implements AiHookService {
|
|
|
if (result.isLongText()){
|
|
|
//新增用户信息
|
|
|
addUserInfoNew(contentKh, qwExternalContacts.getId(),fastGptChatSession);
|
|
|
- if (type==16){
|
|
|
+ //发送图片消息
|
|
|
+ sendImgMsg(contentKh,sender,uid,serverId);
|
|
|
+ /*if (type==16){
|
|
|
sendAiVoiceMsg(content,sender,uid,serverId,user);
|
|
|
- }else {
|
|
|
+ }else {*/
|
|
|
sendAiMsg(content,sender,uid,serverId);
|
|
|
- }
|
|
|
+ //}
|
|
|
|
|
|
}else {
|
|
|
|
|
|
List<String> countList = countString(content);
|
|
|
//新增用户信息
|
|
|
addUserInfoNew(contentKh, qwExternalContacts.getId(),fastGptChatSession);
|
|
|
+ //发送图片消息
|
|
|
+ sendImgMsg(contentKh,sender,uid,serverId);
|
|
|
for (String msg : countList) {
|
|
|
- if (type==16){
|
|
|
+ /*if (type==16){
|
|
|
sendAiVoiceMsg(msg,sender,uid,serverId,user);
|
|
|
- }else {
|
|
|
+ }else {*/
|
|
|
sendAiMsg(msg,sender,uid,serverId);
|
|
|
- }
|
|
|
+ //}
|
|
|
try {
|
|
|
Thread.sleep(500);
|
|
|
} catch (InterruptedException e) {
|
|
|
@@ -699,6 +704,39 @@ public class AiHookServiceImpl implements AiHookService {
|
|
|
return R.ok();
|
|
|
}
|
|
|
|
|
|
+ private void sendImgMsg(String contentKh, Long sender, String uuid, Long serverId) {
|
|
|
+ com.alibaba.fastjson.JSONObject jsonObject = com.alibaba.fastjson.JSONObject.parseObject(contentKh);
|
|
|
+ JSONArray imgUrls = jsonObject.getJSONArray("imgUrl");
|
|
|
+
|
|
|
+
|
|
|
+ if(imgUrls != null && !imgUrls.isEmpty()){
|
|
|
+ WxWorkResponseDTO<WxwUploadCdnLinkImgRespDTO> dto = new WxWorkResponseDTO<>();
|
|
|
+ for (Object imgUrl : imgUrls) {
|
|
|
+ //1.上传cdn网络图片
|
|
|
+ if(imgUrl != null){
|
|
|
+ String imgUrlString = imgUrl.toString();
|
|
|
+ WxwUploadCdnLinkImgDTO wxwUploadCdnLinkImgDTO = new WxwUploadCdnLinkImgDTO();
|
|
|
+ wxwUploadCdnLinkImgDTO.setUuid(uuid);
|
|
|
+ wxwUploadCdnLinkImgDTO.setUrl(imgUrlString);
|
|
|
+ dto = wxWorkService.uploadCdnLinkImg(wxwUploadCdnLinkImgDTO,serverId);
|
|
|
+ }
|
|
|
+ //图片上传成功后再发送图片
|
|
|
+ if("成功".equals(dto.getErrmsg()) && imgUrl != null){
|
|
|
+ WxwUploadCdnLinkImgRespDTO imgRespDTO = dto.getData();
|
|
|
+ WxwSendCDNImgMsgDTO wxwSendCDNImgMsgDTO = new WxwSendCDNImgMsgDTO();
|
|
|
+ wxwSendCDNImgMsgDTO.setSend_userid(sender);
|
|
|
+ wxwSendCDNImgMsgDTO.setUuid(uuid);
|
|
|
+ wxwSendCDNImgMsgDTO.setIsRoom(false);
|
|
|
+ wxwSendCDNImgMsgDTO.setCdnkey(imgRespDTO.getCdn_key());
|
|
|
+ wxwSendCDNImgMsgDTO.setAeskey(imgRespDTO.getAes_key());
|
|
|
+ wxwSendCDNImgMsgDTO.setMd5(imgRespDTO.getMd5());
|
|
|
+ wxwSendCDNImgMsgDTO.setFileSize(imgRespDTO.getSize());
|
|
|
+ wxWorkService.SendCDNImgMsg(wxwSendCDNImgMsgDTO, serverId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 根据发送者id设置用户是否为首次回复
|
|
|
* @param sender 发送者id
|
|
|
@@ -1540,7 +1578,7 @@ public class AiHookServiceImpl implements AiHookService {
|
|
|
|
|
|
//添加关键词
|
|
|
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://129.28.170.206:3000/api/", appKey);
|
|
|
Object data1 = r.get("data");
|
|
|
if(!(data1 instanceof KnowledgeBaseResult)){
|
|
|
ChatDetailTStreamFResult data = (ChatDetailTStreamFResult) r.get("data");
|
|
|
@@ -1595,9 +1633,12 @@ public class AiHookServiceImpl implements AiHookService {
|
|
|
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());
|
|
|
+ conversation.setHistory(new com.alibaba.fastjson.JSONArray());
|
|
|
+
|
|
|
+ if(role.getReminderWords() != null && !role.getReminderWords().isEmpty()){
|
|
|
+ conversation.setAiInfo(role.getReminderWords());
|
|
|
+ }
|
|
|
|
|
|
//组装客户信息
|
|
|
String sessionUserInfo = fastGptChatSession.getUserInfo();
|
|
|
@@ -1628,19 +1669,23 @@ public class AiHookServiceImpl implements AiHookService {
|
|
|
|
|
|
List<FastGptChatMsg> msgs=fastGptChatMsgService.selectFastGptChatMsgByMsgSessionIdAndExtId(fastGptChatSession.getSessionId(),extId);
|
|
|
if (!msgs.isEmpty()){
|
|
|
- com.alibaba.fastjson.JSONObject history = conversation.getHistory();
|
|
|
+ com.alibaba.fastjson.JSONArray historyArray = new com.alibaba.fastjson.JSONArray();
|
|
|
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){
|
|
|
+ if (content!=null&&content.length()>500){
|
|
|
continue;
|
|
|
}
|
|
|
}
|
|
|
- history.put(sendType==1?"user":"ai",content);
|
|
|
+ com.alibaba.fastjson.JSONObject msgObj = new com.alibaba.fastjson.JSONObject();
|
|
|
+ msgObj.put("role", sendType==1?"user":"ai");
|
|
|
+ msgObj.put("content", content);
|
|
|
+ historyArray.add(msgObj);
|
|
|
}
|
|
|
+ conversation.setHistory(historyArray);
|
|
|
}
|
|
|
|
|
|
if (count!=null&& !count.isEmpty()){
|
|
|
@@ -1659,9 +1704,8 @@ public class AiHookServiceImpl implements AiHookService {
|
|
|
private void addPromptWord(List<ChatParam.Message> messageList,String count,Long extId,String words,String countInfo,Long sessionId){
|
|
|
|
|
|
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());
|
|
|
+ conversation.setHistory(new com.alibaba.fastjson.JSONArray());
|
|
|
|
|
|
|
|
|
// 这里获取后台的提示词进行匹配
|
|
|
@@ -1717,19 +1761,23 @@ public class AiHookServiceImpl implements AiHookService {
|
|
|
|
|
|
List<FastGptChatMsg> msgs=fastGptChatMsgService.selectFastGptChatMsgByMsgSessionIdAndExtId(sessionId,extId);
|
|
|
if (!msgs.isEmpty()){
|
|
|
- com.alibaba.fastjson.JSONObject history = conversation.getHistory();
|
|
|
+ com.alibaba.fastjson.JSONArray historyArray = new com.alibaba.fastjson.JSONArray();
|
|
|
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){
|
|
|
+ if (content!=null&&content.length()>500){
|
|
|
continue;
|
|
|
}
|
|
|
}
|
|
|
- history.put(sendType==1?"user":"ai",content);
|
|
|
+ com.alibaba.fastjson.JSONObject msgObj = new com.alibaba.fastjson.JSONObject();
|
|
|
+ msgObj.put("role", sendType==1?"user":"ai");
|
|
|
+ msgObj.put("content", content);
|
|
|
+ historyArray.add(msgObj);
|
|
|
}
|
|
|
+ conversation.setHistory(historyArray);
|
|
|
}
|
|
|
|
|
|
if (count!=null&& !count.isEmpty()){
|