Commit 7d7aaeef authored by luojun's avatar luojun

deepseek优化

parent cbf680d1
......@@ -2,13 +2,12 @@ package admin.listener;
import admin.model.MaxKbChatReq;
import admin.model.WebSocketModel;
import admin.model.maxdb.req.MaxdbReq;
import admin.model.maxdb.resp.MaxdbStreamResponse;
import admin.modules.chatgpt.domain.ChatgptRoleRecords;
import admin.modules.chatgpt.service.ChatgptRoleRecordsService;
import admin.util.DateUtil;
import admin.util.ScreenEnum;
import admin.util.WebConnectUtil;
import admin.util.WebSocketUtil;
import admin.util.*;
import com.alibaba.fastjson.JSON;
import com.google.gson.Gson;
import lombok.SneakyThrows;
......@@ -45,6 +44,42 @@ public class DeepSeekAiListener extends EventSourceListener {
@Override
public void onOpen(EventSource eventSource, Response response) {
super.onOpen(eventSource, response);
//1.中科慧居简介直接发送
if (maxKbChatReq.getShowType()!=null && maxKbChatReq.getShowType().equals(ResponseEnum.ZK_PROFILE.getDesc())){
WebSocketModel webSocketModel = new WebSocketModel();
webSocketModel.setAction("start");
webSocketModel.setType("text");
webSocketModel.setShowType(maxKbChatReq.getShowType());
webSocketModel.setContent("");
try {
maxKbChatReq.getSession().getBasicRemote().sendText(JSON.toJSONString(webSocketModel));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
// else if (maxKbChatReq.getShowType().equals(ResponseEnum.ZK_PRODUCT.getDesc())){
// WebSocketModel webSocketModel = new WebSocketModel();
// webSocketModel.setAction("start");
// webSocketModel.setType("text");
// webSocketModel.setShowType(maxKbChatReq.getShowType());
// webSocketModel.setContent("");
// try {
// maxKbChatReq.getSession().getBasicRemote().sendText(JSON.toJSONString(webSocketModel));
// } catch (IOException e) {
// throw new RuntimeException(e);
// }
// }else if (maxKbChatReq.getShowType().equals(ResponseEnum.ZK_USER.getDesc())){
// WebSocketModel webSocketModel = new WebSocketModel();
// webSocketModel.setAction("start");
// webSocketModel.setType("text");
// webSocketModel.setShowType(maxKbChatReq.getShowType());
// webSocketModel.setContent("");
// try {
// maxKbChatReq.getSession().getBasicRemote().sendText(JSON.toJSONString(webSocketModel));
// } catch (IOException e) {
// throw new RuntimeException(e);
// }
// }
log.info("DeepSeek建立sse连接...onOpen");
}
......@@ -65,6 +100,7 @@ public class DeepSeekAiListener extends EventSourceListener {
map.put("content",completionResponse.getContent());
String msg = JSON.toJSONString(map);
maxKbChatReq.getSession().getBasicRemote().sendText(msg);
// introduce();
//存储聊天记录
ChatgptRoleRecords chatgptRoleRecords = new ChatgptRoleRecords();
chatgptRoleRecords.setMessage(this.stringBuffer.toString());
......@@ -110,6 +146,25 @@ public class DeepSeekAiListener extends EventSourceListener {
}
/**
* 发送介绍信息(介绍产品信息 介绍人员信息)
*/
private void introduce() {
if (maxKbChatReq.getShowType().equals(ResponseEnum.ZK_PROFILE.getDesc())){
maxKbChatReq.setMessage(ResponseEnum.ZK_PRODUCT.getDesc());
maxKbChatReq.setShowType(ResponseEnum.ZK_PRODUCT.getDesc());
MaxdbReq maxdbReq = new MaxdbReq();
maxdbReq.setMessage(maxKbChatReq.getMessage());
HttpUtil.postCallBackStream(maxKbChatReq.getMaxkbTalkUrl(),maxdbReq,maxKbChatReq.getMaxkbApiKey(),maxKbChatReq,chatgptRoleRecordsService);
}else if (maxKbChatReq.getShowType().equals(ResponseEnum.ZK_PRODUCT.getDesc())){
maxKbChatReq.setMessage(ResponseEnum.ZK_USER.getDesc());
maxKbChatReq.setShowType(ResponseEnum.ZK_USER.getDesc());
MaxdbReq maxdbReq = new MaxdbReq();
maxdbReq.setMessage(maxKbChatReq.getMessage());
HttpUtil.postCallBackStream(maxKbChatReq.getMaxkbTalkUrl(),maxdbReq,maxKbChatReq.getMaxkbApiKey(),maxKbChatReq,chatgptRoleRecordsService);
}
}
@Override
public void onClosed(EventSource eventSource) {
super.onClosed(eventSource);
......
......@@ -38,4 +38,13 @@ public class MaxKbChatReq {
* 前端展示类型 1-中科慧居简介
*/
private String showType;
/**
* maxkb访问路径
*/
private String maxkbTalkUrl;
/**
* maxkb密钥
*/
private String maxkbApiKey;
}
......@@ -15,4 +15,17 @@ public class MaxdbReq {
private boolean reChat=false;
@SerializedName("stream")
private boolean stream=true;
/**
* maxkb访问路径
*/
private String maxkbTalkUrl;
/**
* maxkb应用id
*/
private String maxkbApplicationId;
/**
* maxkb对话id
*/
private String maxkbChatId;
}
......@@ -17,7 +17,10 @@ import org.springframework.data.domain.Pageable;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.Comparator;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
/**
* @author wk
......@@ -53,7 +56,9 @@ public class ChatgptRoleRecordsController {
@GetMapping(value = "queryTenRecords")
public ApiResponse<Object> queryTenRecords(@RequestParam String userName) {
Integer userId = ScreenEnum.getByUserName(userName);
return ApiResponse.buildSuccess(chatgptRoleRecordsService.queryTenRecords(userId));
List<ChatgptRoleRecordsDto> chatgptRoleRecordsDtos = chatgptRoleRecordsService.queryTenRecords(userId);
List<ChatgptRoleRecordsDto> collect = chatgptRoleRecordsDtos.stream().sorted(Comparator.comparing(ChatgptRoleRecordsDto::getId)).collect(Collectors.toList());
return ApiResponse.buildSuccess(collect);
}
@ApiOperation("查询屏幕列表")
......
......@@ -10,6 +10,7 @@ import admin.modules.chatgpt.service.ChatgptRoleSessionService;
import admin.service.MaxkbOpenApiService;
import admin.util.*;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import okhttp3.HttpUrl;
import okhttp3.OkHttpClient;
......@@ -82,6 +83,7 @@ public class VoiceWebSocketServer {
//4.存储不同的连接
if (mark.equals(WebSocketUtil.H5)){
H5ConnectUtil.add(name);
popUpEvent(name,"webOnOpen");
}else {
WebConnectUtil.put(sessionId,name,session);
}
......@@ -115,11 +117,32 @@ public class VoiceWebSocketServer {
//存储不同的连接
if (mark.equals(WebSocketUtil.H5)){
H5ConnectUtil.remove(name);
popUpEvent(name,"webOnClose");
}else {
WebConnectUtil.remove(sessionId);
}
}
/**
* web弹窗事件
*/
private void popUpEvent(String name, String action) {
WebSocketModel webSocketModel = new WebSocketModel();
webSocketModel.setType("text");
webSocketModel.setAction(action);
String msg = JSONObject.toJSONString(webSocketModel);
List<Session> webMap = WebConnectUtil.getWebMap(name);
if (!webMap.isEmpty()){
webMap.forEach(i->{
try {
i.getBasicRemote().sendText(msg);
} catch (IOException e) {
throw new RuntimeException(e);
}
});
}
}
//收到客户端信息
@OnMessage(maxMessageSize = 10*1024*1024)
public void onTextMessage(Session session,String message,@PathParam(value = "memberId") String memberId) throws IOException {
......@@ -252,7 +275,11 @@ public class VoiceWebSocketServer {
}
public String getShowType(String msg){
if (msg.contains("中科慧居") && msg.contains("简介")){
if (msg.contains("中科慧居") && msg.contains("产品介绍")){
return ResponseEnum.ZK_PRODUCT.getDesc();
}else if (msg.contains("中科慧居") && msg.contains("人员介绍")){
return ResponseEnum.ZK_USER.getDesc();
}else if (msg.contains("中科慧居") && msg.contains("简介")){
return ResponseEnum.ZK_PROFILE.getDesc();
}else if (msg.contains( ResponseEnum.PIE_CHART.getDesc())){
return ResponseEnum.PIE_CHART.getDesc();
......
......@@ -42,6 +42,9 @@ public class MaxkbOpenApiServiceImpl implements MaxkbOpenApiService {
public void chatCompletions(MaxKbChatReq maxKbChatReq) {
MaxdbReq maxdbReq = new MaxdbReq();
maxdbReq.setMessage(maxKbChatReq.getMessage());
maxKbChatReq.setMaxkbTalkUrl(String.format(maxdbScreenConfig.getTalkUrl(),maxKbChatReq.getChatId()));
maxKbChatReq.setMaxkbApiKey(maxdbScreenConfig.getApiKey());
// WebSocketModel webSocketModel = JSONObject.parseObject(message, WebSocketModel.class);
HttpUtil.postCallBackStream(String.format(maxdbScreenConfig.getTalkUrl(),maxKbChatReq.getChatId()), maxdbReq, maxdbScreenConfig.getApiKey(),maxKbChatReq,chatgptRoleRecordsService);
}
......
......@@ -13,7 +13,9 @@ public enum ResponseEnum{
ZK_PROFILE(1,"中科慧居简介"),
PIE_CHART(2,"饼状图"),
BAR_CHART(3,"柱状图"),
TREND_CHART(4,"趋势图");
TREND_CHART(4,"趋势图"),
ZK_PRODUCT(5,"中科慧居产品介绍"),
ZK_USER(6,"中科慧居人员介绍");
int type;
String desc;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment