Commit 071edf96 authored by luojun's avatar luojun

deepseek优化

parent 124ca54a
...@@ -3,11 +3,13 @@ package admin.listener; ...@@ -3,11 +3,13 @@ package admin.listener;
import admin.model.MaxKbChatReq; import admin.model.MaxKbChatReq;
import admin.model.WebSocketModel; import admin.model.WebSocketModel;
import admin.model.maxdb.req.MaxdbReq;
import admin.model.maxdb.resp.MaxdbStreamResponse; import admin.model.maxdb.resp.MaxdbStreamResponse;
import admin.modules.chatgpt.domain.ChatgptRoleRecords; import admin.modules.chatgpt.domain.ChatgptRoleRecords;
import admin.modules.chatgpt.service.ChatgptRoleRecordsService; import admin.modules.chatgpt.service.ChatgptRoleRecordsService;
import admin.util.*; import admin.util.DateUtil;
import admin.util.ScreenEnum;
import admin.util.WebConnectUtil;
import admin.util.WebSocketUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.google.gson.Gson; import com.google.gson.Gson;
import lombok.SneakyThrows; import lombok.SneakyThrows;
...@@ -21,7 +23,6 @@ import javax.websocket.Session; ...@@ -21,7 +23,6 @@ import javax.websocket.Session;
import java.io.IOException; import java.io.IOException;
import java.net.SocketException; import java.net.SocketException;
import java.util.*; import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
/** /**
* @author lj * @author lj
...@@ -43,34 +44,25 @@ public class DeepSeekAiListener extends EventSourceListener { ...@@ -43,34 +44,25 @@ public class DeepSeekAiListener extends EventSourceListener {
@Override @Override
public void onOpen(EventSource eventSource, Response response) { public void onOpen(EventSource eventSource, Response response) {
super.onOpen(eventSource, response); super.onOpen(eventSource, response);
//1.中科慧居简介直接发送 sendStartMessage(maxKbChatReq.getSession());
sendStartTranslate(maxKbChatReq.getSession());
log.info("DeepSeek建立sse连接...onOpen"); log.info("DeepSeek建立sse连接...onOpen");
} }
private void sendStartTranslate(Session session) { /**
* 发送中添加start标签,用于展示知识库中的信息
* @param session websocket中session
*/
private void sendStartMessage(Session session) {
if (maxKbChatReq.getShowType()!=null){ if (maxKbChatReq.getShowType()!=null){
sendStartMessage(session); WebSocketModel webSocketModel = WebSocketModel.createByMaxKbChatReq(maxKbChatReq, "start", "text","");
try {
session.getBasicRemote().sendText(JSON.toJSONString(webSocketModel));
} catch (IOException e) {
throw new RuntimeException(e);
}
} }
} }
private void sendStartMessage(Session session) {
WebSocketModel webSocketModel = new WebSocketModel();
webSocketModel.setAction("start");
webSocketModel.setType("text");
webSocketModel.setShowType(maxKbChatReq.getShowType().getType());
webSocketModel.setName(maxKbChatReq.getUserName());
webSocketModel.setTitle(maxKbChatReq.getShowType().getDesc());
webSocketModel.setImgs(maxKbChatReq.getShowType().getImgs());
webSocketModel.setNote(maxKbChatReq.getShowType().getNote());
webSocketModel.setPosition(maxKbChatReq.getShowType().getPosition());
webSocketModel.setContent("");
try {
session.getBasicRemote().sendText(JSON.toJSONString(webSocketModel));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
@Override @Override
...@@ -82,14 +74,8 @@ public class DeepSeekAiListener extends EventSourceListener { ...@@ -82,14 +74,8 @@ public class DeepSeekAiListener extends EventSourceListener {
MaxdbStreamResponse completionResponse = gson.fromJson(data, MaxdbStreamResponse.class); MaxdbStreamResponse completionResponse = gson.fromJson(data, MaxdbStreamResponse.class);
if (completionResponse.getIsEnd()) { if (completionResponse.getIsEnd()) {
log.info("DeepSeek返回数据结束了...onEvent"); log.info("DeepSeek返回数据结束了...onEvent");
Map<String,Object> map = new HashMap<>(); WebSocketModel webSocketModel = WebSocketModel.createByMaxKbChatReq(maxKbChatReq, "done", "text", completionResponse.getContent());
map.put("action","done"); String msg = JSON.toJSONString(webSocketModel);
map.put("type","text");
map.put("showType",maxKbChatReq.getShowType().getType());
map.put("imgs",maxKbChatReq.getShowType().getImgs());
map.put("title",maxKbChatReq.getShowType().getDesc());
map.put("content",completionResponse.getContent());
String msg = JSON.toJSONString(map);
maxKbChatReq.getSession().getBasicRemote().sendText(msg); maxKbChatReq.getSession().getBasicRemote().sendText(msg);
if (maxKbChatReq.getClient().equals(WebSocketUtil.H5)){ if (maxKbChatReq.getClient().equals(WebSocketUtil.H5)){
List<Session> webMap = WebConnectUtil.getWebMap(maxKbChatReq.getUserName()); List<Session> webMap = WebConnectUtil.getWebMap(maxKbChatReq.getUserName());
...@@ -103,27 +89,17 @@ public class DeepSeekAiListener extends EventSourceListener { ...@@ -103,27 +89,17 @@ public class DeepSeekAiListener extends EventSourceListener {
}); });
} }
} }
// introduce();
//存储聊天记录 //存储聊天记录
ChatgptRoleRecords chatgptRoleRecords = new ChatgptRoleRecords(); chatgptRoleRecordsService.saveRecords(this.stringBuffer.toString(),
chatgptRoleRecords.setMessage(this.stringBuffer.toString()); ScreenEnum.getByUserName(maxKbChatReq.getUserName()),
chatgptRoleRecords.setReceiverId(ScreenEnum.getByUserName(maxKbChatReq.getUserName())); Integer.valueOf(maxKbChatReq.getSessionId()), 10001, 0);
chatgptRoleRecords.setSessionId(Integer.valueOf(maxKbChatReq.getSessionId()));
chatgptRoleRecords.setSenderId(10001);
chatgptRoleRecords.setIsAsk(0);
chatgptRoleRecords.setCreateTime(DateUtil.getNowTimestamp());
chatgptRoleRecordsService.save(chatgptRoleRecords);
return; return;
} }
if (completionResponse.getContent()!=null){ if (completionResponse.getContent()!=null){
System.out.print(completionResponse.getContent()); System.out.print(completionResponse.getContent());
this.stringBuffer.append(completionResponse.getContent()); this.stringBuffer.append(completionResponse.getContent());
Map<String,Object> map = new HashMap<>(); WebSocketModel webSocketModel = WebSocketModel.createBaseMode("reply", "text", completionResponse.getContent());
map.put("action","reply"); String msg = JSON.toJSONString(webSocketModel);
map.put("type","text");
map.put("content",completionResponse.getContent());
String msg = JSON.toJSONString(map);
maxKbChatReq.getSession().getBasicRemote().sendText(msg); maxKbChatReq.getSession().getBasicRemote().sendText(msg);
if (maxKbChatReq.getClient().equals(WebSocketUtil.H5)){ if (maxKbChatReq.getClient().equals(WebSocketUtil.H5)){
List<Session> webMap = WebConnectUtil.getWebMap(maxKbChatReq.getUserName()); List<Session> webMap = WebConnectUtil.getWebMap(maxKbChatReq.getUserName());
...@@ -156,7 +132,7 @@ public class DeepSeekAiListener extends EventSourceListener { ...@@ -156,7 +132,7 @@ public class DeepSeekAiListener extends EventSourceListener {
for (Session session : webMap) { for (Session session : webMap) {
if (!set.contains(session.getId())){ if (!set.contains(session.getId())){
set.add(session.getId()); set.add(session.getId());
sendStartTranslate(session); sendStartMessage(session);
} }
} }
} }
......
...@@ -50,4 +50,52 @@ public class WebSocketModel { ...@@ -50,4 +50,52 @@ public class WebSocketModel {
* 人员职位 * 人员职位
*/ */
private String position; private String position;
/**
* 图片路径
*/
private String chartUrl;
/**
* 数据集
*/
private String dataList;
public static WebSocketModel createBaseMode(String action,String type,String content){
WebSocketModel webSocketModel = new WebSocketModel();
webSocketModel.setType(type);
webSocketModel.setAction(action);
webSocketModel.setContent(content);
return webSocketModel;
}
public static WebSocketModel createByMaxKbChatReq(MaxKbChatReq maxKbChatReq,String action,String type,String content){
WebSocketModel webSocketModel = new WebSocketModel();
webSocketModel.setAction(action);
webSocketModel.setType(type);
webSocketModel.setShowType(maxKbChatReq.getShowType()!=null?maxKbChatReq.getShowType().getType():null);
webSocketModel.setName(maxKbChatReq.getUserName());
webSocketModel.setTitle(maxKbChatReq.getShowType()!=null?maxKbChatReq.getShowType().getDesc():null);
webSocketModel.setImgs(maxKbChatReq.getShowType()!=null?maxKbChatReq.getShowType().getImgs():null);
webSocketModel.setNote(maxKbChatReq.getShowType()!=null?maxKbChatReq.getShowType().getNote():null);
webSocketModel.setPosition(maxKbChatReq.getShowType()!=null?maxKbChatReq.getShowType().getPosition():null);
webSocketModel.setContent(content);
return webSocketModel;
}
public static WebSocketModel createSessionMode(String action, String type, String content, String sessionId) {
WebSocketModel baseMode = createBaseMode(action, type, content);
baseMode.setSessionId(sessionId);
return baseMode;
}
public static WebSocketModel createChartMode(String action, String type, String content,String chartUrl) {
WebSocketModel baseMode = createBaseMode(action, type, content);
baseMode.setChartUrl(chartUrl);
return baseMode;
}
public static WebSocketModel createDataList(String action, String type, String content) {
WebSocketModel baseMode = createBaseMode(action, type, content);
baseMode.setDataList(content);
return baseMode;
}
} }
...@@ -50,6 +50,14 @@ public class ChatgptRoleRecords implements Serializable { ...@@ -50,6 +50,14 @@ public class ChatgptRoleRecords implements Serializable {
@TableField(fill= FieldFill.INSERT) @TableField(fill= FieldFill.INSERT)
private Timestamp createTime; private Timestamp createTime;
@ApiModelProperty(value = "1-收藏 0-不收藏")
private Integer isCollect;
@ApiModelProperty(value = "1-数据集,2-ai生成的url")
private Integer type;
@ApiModelProperty(value = "内容")
private String content;
public void copyFrom(ChatgptRoleRecords source){ public void copyFrom(ChatgptRoleRecords source){
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
} }
......
...@@ -50,6 +50,8 @@ public class ChatgptRoleSession implements Serializable { ...@@ -50,6 +50,8 @@ public class ChatgptRoleSession implements Serializable {
@TableField(fill= FieldFill.INSERT_UPDATE) @TableField(fill= FieldFill.INSERT_UPDATE)
private Timestamp updateTime; private Timestamp updateTime;
@ApiModelProperty(value = "1-收藏 0-不收藏")
private Integer isCollect;
public void copyFrom(ChatgptRoleSession source){ public void copyFrom(ChatgptRoleSession source){
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
} }
......
...@@ -85,4 +85,15 @@ public interface ChatgptRoleRecordsService extends CommonService<ChatgptRoleReco ...@@ -85,4 +85,15 @@ public interface ChatgptRoleRecordsService extends CommonService<ChatgptRoleReco
String queryMaxSessionId(); String queryMaxSessionId();
List<ChatgptRoleRecordsDto> queryTenRecords(Integer userId); List<ChatgptRoleRecordsDto> queryTenRecords(Integer userId);
/**
* 创建聊天记录
*/
void saveRecords(String message, Integer receiverId,Integer sessionId,Integer senderId,Integer isAsk);
/**
* 创建聊天记录
*/
void saveContent(String message, Integer receiverId,Integer sessionId,Integer senderId,Integer isAsk,Integer type,String content);
} }
...@@ -48,6 +48,8 @@ public interface ChatgptRoleSessionService extends CommonService<ChatgptRoleSess ...@@ -48,6 +48,8 @@ public interface ChatgptRoleSessionService extends CommonService<ChatgptRoleSess
@Async @Async
Integer updateUpdateTime(Integer id); Integer updateUpdateTime(Integer id);
void saveRecord(Integer id, String name, Integer roleDescId, Integer userId);
/** /**
* 导出数据 * 导出数据
* @param all 待导出的数据 * @param all 待导出的数据
......
...@@ -47,4 +47,16 @@ public class ChatgptRoleRecordsDto implements Serializable { ...@@ -47,4 +47,16 @@ public class ChatgptRoleRecordsDto implements Serializable {
* 问答 1-问 0-答 * 问答 1-问 0-答
*/ */
private Integer isAsk; private Integer isAsk;
/** 是否收藏 1-收藏 */
private Integer isCollect;
/**
* 1-数据集
* 2-ai生成的url
*/
private Integer type;
/**
* 内容
*/
private String content;
} }
...@@ -46,4 +46,7 @@ public class ChatgptRoleSessionDto implements Serializable { ...@@ -46,4 +46,7 @@ public class ChatgptRoleSessionDto implements Serializable {
/** 更新时间 */ /** 更新时间 */
private Timestamp updateTime; private Timestamp updateTime;
/** 是否收藏 1-收藏 */
private Integer isCollect;
} }
...@@ -10,9 +10,12 @@ import admin.modules.chatgpt.service.dto.ChatgptRoleRecordsQueryCriteria; ...@@ -10,9 +10,12 @@ import admin.modules.chatgpt.service.dto.ChatgptRoleRecordsQueryCriteria;
import admin.modules.chatgpt.service.mapper.ChatgptRoleRecordsMapper; import admin.modules.chatgpt.service.mapper.ChatgptRoleRecordsMapper;
import admin.util.ConvertUtil; import admin.util.ConvertUtil;
import admin.util.DateUtil;
import admin.util.PageUtil; import admin.util.PageUtil;
import admin.util.ScreenEnum;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import org.jetbrains.annotations.NotNull;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Propagation;
...@@ -120,6 +123,32 @@ public class ChatgptRoleRecordsServiceImpl extends CommonServiceImpl<ChatgptRole ...@@ -120,6 +123,32 @@ public class ChatgptRoleRecordsServiceImpl extends CommonServiceImpl<ChatgptRole
return ConvertUtil.convertList(chatgptRoleRecordsDtos,ChatgptRoleRecordsDto.class); return ConvertUtil.convertList(chatgptRoleRecordsDtos,ChatgptRoleRecordsDto.class);
} }
@Override
public void saveRecords(String message, Integer receiverId, Integer sessionId, Integer senderId, Integer isAsk) {
ChatgptRoleRecords chatgptRoleRecords = createRecords(message, receiverId, sessionId, senderId, isAsk);
save(chatgptRoleRecords);
}
@NotNull
private static ChatgptRoleRecords createRecords(String message, Integer receiverId, Integer sessionId, Integer senderId, Integer isAsk) {
ChatgptRoleRecords chatgptRoleRecords = new ChatgptRoleRecords();
chatgptRoleRecords.setMessage(message);
chatgptRoleRecords.setReceiverId(receiverId);
chatgptRoleRecords.setSessionId(sessionId);
chatgptRoleRecords.setSenderId(senderId);
chatgptRoleRecords.setIsAsk(isAsk);
chatgptRoleRecords.setCreateTime(DateUtil.getNowTimestamp());
return chatgptRoleRecords;
}
@Override
public void saveContent(String message, Integer receiverId, Integer sessionId, Integer senderId, Integer isAsk, Integer type, String content) {
ChatgptRoleRecords chatgptRoleRecords = createRecords(message, receiverId, sessionId, senderId, isAsk);
chatgptRoleRecords.setType(type);
chatgptRoleRecords.setContent(content);
save(chatgptRoleRecords);
}
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public Integer removeById(Integer id){ public Integer removeById(Integer id){
......
...@@ -10,6 +10,7 @@ import admin.modules.chatgpt.service.dto.ChatgptRoleSessionQueryCriteria; ...@@ -10,6 +10,7 @@ import admin.modules.chatgpt.service.dto.ChatgptRoleSessionQueryCriteria;
import admin.modules.chatgpt.service.mapper.ChatgptRoleSessionMapper; import admin.modules.chatgpt.service.mapper.ChatgptRoleSessionMapper;
import admin.util.ConvertUtil; import admin.util.ConvertUtil;
import admin.util.PageUtil; import admin.util.PageUtil;
import admin.util.ScreenEnum;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
...@@ -86,6 +87,16 @@ public class ChatgptRoleSessionServiceImpl extends CommonServiceImpl<ChatgptRole ...@@ -86,6 +87,16 @@ public class ChatgptRoleSessionServiceImpl extends CommonServiceImpl<ChatgptRole
return chatgptRoleSessionMapper.updateUpdateTime(id); return chatgptRoleSessionMapper.updateUpdateTime(id);
} }
@Override
public void saveRecord(Integer id, String name, Integer roleDescId, Integer userId) {
ChatgptRoleSession chatgptRoleSession = new ChatgptRoleSession();
chatgptRoleSession.setId(id);
chatgptRoleSession.setName(name);
chatgptRoleSession.setRoleDescId(roleDescId);
chatgptRoleSession.setUserId(userId);
save(chatgptRoleSession);
}
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public int removeById(Integer id){ public int removeById(Integer id){
......
package admin.resp;
import lombok.Data;
/**
* @author lj
* @date 2025/3/25 11:17
*/
@Data
public class PythonResp {
/**
* 文件地址
*/
private String file;
/**
* 数据
*/
private String data;
/**
* 数据集
*/
private String dataList;
/**
* type 1返回总结和原始数据集
* 2 返回总结和文件地址
*/
private Integer type;
}
...@@ -2,13 +2,17 @@ package admin.rest; ...@@ -2,13 +2,17 @@ package admin.rest;
import admin.base.PageInfo; import admin.base.PageInfo;
import admin.modules.chatgpt.domain.ChatgptRoleRecords;
import admin.modules.chatgpt.domain.ChatgptRoleSession;
import admin.modules.chatgpt.service.ChatgptRoleRecordsService; import admin.modules.chatgpt.service.ChatgptRoleRecordsService;
import admin.modules.chatgpt.service.ChatgptRoleSessionService; import admin.modules.chatgpt.service.ChatgptRoleSessionService;
import admin.modules.chatgpt.service.dto.ChatgptRoleRecordsDto; import admin.modules.chatgpt.service.dto.ChatgptRoleRecordsDto;
import admin.modules.chatgpt.service.dto.ChatgptRoleRecordsQueryCriteria; import admin.modules.chatgpt.service.dto.ChatgptRoleRecordsQueryCriteria;
import admin.modules.chatgpt.service.dto.ChatgptRoleSessionDto;
import admin.modules.chatgpt.service.dto.ChatgptRoleSessionQueryCriteria; import admin.modules.chatgpt.service.dto.ChatgptRoleSessionQueryCriteria;
import admin.resp.ApiResponse; import admin.resp.ApiResponse;
import admin.util.ScreenEnum; import admin.util.ScreenEnum;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
...@@ -38,20 +42,60 @@ public class ChatgptRoleRecordsController { ...@@ -38,20 +42,60 @@ public class ChatgptRoleRecordsController {
@ApiOperation("会话查询对话记录") @ApiOperation("会话查询对话记录")
@GetMapping(value = "sessionList") @GetMapping(value = "sessionList")
public ApiResponse<Object> querySessionList(ChatgptRoleRecordsQueryCriteria query, Pageable pageable) { public ApiResponse<Object> querySessionList(ChatgptRoleRecordsQueryCriteria query) {
return ApiResponse.buildSuccess(chatgptRoleRecordsService.queryAll(query, pageable)); List<ChatgptRoleRecordsDto> chatgptRoleRecordsDtoPageInfo = chatgptRoleRecordsService.queryAll(query);
return ApiResponse.buildSuccess(chatgptRoleRecordsDtoPageInfo);
} }
@ApiOperation("查询会话") @ApiOperation("查询会话")
@GetMapping(value = "list") @GetMapping(value = "list")
public ApiResponse<Object> query(ChatgptRoleSessionQueryCriteria query, Pageable pageable){ public ApiResponse<Object> query(ChatgptRoleSessionQueryCriteria query){
Integer byUserName = ScreenEnum.getByUserName(query.getName()); Integer byUserName = ScreenEnum.getByUserName(query.getName());
query.setUserId(byUserName); query.setUserId(byUserName);
return ApiResponse.buildSuccess(chatgptRoleSessionService.queryAll(query,pageable)); List<ChatgptRoleSessionDto> chatgptRoleSessionDtos = chatgptRoleSessionService.queryAll(query);
return ApiResponse.buildSuccess(chatgptRoleSessionDtos!=null ? chatgptRoleSessionDtos.stream().sorted(Comparator.comparing(ChatgptRoleSessionDto::getId).reversed()).collect(Collectors.toList()) : chatgptRoleSessionDtos);
} }
@ApiOperation("收藏会话")
@GetMapping(value = "collect/list")
public ApiResponse<Object> collectList(String content,String sessionId){
List<ChatgptRoleRecords> list = chatgptRoleRecordsService.lambdaQuery()
.eq(ChatgptRoleRecords::getMessage, content)
.eq(ChatgptRoleRecords::getSessionId,sessionId).list();
list.forEach(i->i.setIsCollect(1));
chatgptRoleRecordsService.updateBatchById(list);
return ApiResponse.buildSuccess();
}
@ApiOperation("取消收藏会话")
@GetMapping(value = "cancel/collect/list")
public ApiResponse<Object> cancelCollectList(Integer id){
ChatgptRoleRecordsDto byId = chatgptRoleRecordsService.findById(id);
if (byId == null) return ApiResponse.buildFailure("99","会话不存在");
byId.setIsCollect(0);
chatgptRoleRecordsService.updateById(byId);
return ApiResponse.buildSuccess();
}
@ApiOperation("查询收藏会话")
@GetMapping(value = "query/collect/list")
public ApiResponse<Object> queryCollectList(@RequestParam String userName){
Integer userId = ScreenEnum.getByUserName(userName);
List<ChatgptRoleRecords> list = chatgptRoleRecordsService.lambdaQuery().eq(ChatgptRoleRecords::getIsCollect, 1).and(i -> i.eq(ChatgptRoleRecords::getSenderId, userId).or().eq(ChatgptRoleRecords::getReceiverId, userId)).list();
return ApiResponse.buildSuccess(list.stream().sorted(Comparator.comparing(ChatgptRoleRecords::getId).reversed()).collect(Collectors.toList()));
}
@ApiOperation("删除会话")
@GetMapping(value = "delete")
public ApiResponse<Object> delete(Integer sessionId){
chatgptRoleSessionService.removeById(sessionId);
List<ChatgptRoleRecords> list = chatgptRoleRecordsService.lambdaQuery().eq(ChatgptRoleRecords::getSessionId, sessionId).list();
chatgptRoleRecordsService.removeBatchByIds(list);
return ApiResponse.buildSuccess();
}
@ApiOperation("大屏临时查询十条会话记录") @ApiOperation("大屏临时查询十条会话记录")
@GetMapping(value = "queryTenRecords") @GetMapping(value = "queryTenRecords")
public ApiResponse<Object> queryTenRecords(@RequestParam String userName) { public ApiResponse<Object> queryTenRecords(@RequestParam String userName) {
......
...@@ -4,6 +4,7 @@ import admin.model.MaxKbChatReq; ...@@ -4,6 +4,7 @@ import admin.model.MaxKbChatReq;
import admin.model.SendSseModel; import admin.model.SendSseModel;
import admin.model.python.PythonApiReq; import admin.model.python.PythonApiReq;
import admin.resp.ApiResponse; import admin.resp.ApiResponse;
import admin.resp.PythonResp;
import admin.service.DeepSeekOpenApiService; import admin.service.DeepSeekOpenApiService;
import admin.service.MaxkbOpenApiService; import admin.service.MaxkbOpenApiService;
import admin.service.OpenConnectService; import admin.service.OpenConnectService;
...@@ -31,7 +32,7 @@ public class OpenApiController { ...@@ -31,7 +32,7 @@ public class OpenApiController {
@GetMapping("testAnalysis") @GetMapping("testAnalysis")
public ApiResponse<Object> testAnalysis(PythonApiReq pythonApiReq){ public ApiResponse<Object> testAnalysis(PythonApiReq pythonApiReq){
String analysisData = pythonOpenApiClient.getAnalysisData(pythonApiReq); PythonResp analysisData = pythonOpenApiClient.getAnalysisData(pythonApiReq);
return ApiResponse.buildSuccess(analysisData); return ApiResponse.buildSuccess(analysisData);
} }
......
...@@ -8,6 +8,7 @@ import admin.modules.chatgpt.domain.ChatgptRoleRecords; ...@@ -8,6 +8,7 @@ import admin.modules.chatgpt.domain.ChatgptRoleRecords;
import admin.modules.chatgpt.domain.ChatgptRoleSession; import admin.modules.chatgpt.domain.ChatgptRoleSession;
import admin.modules.chatgpt.service.ChatgptRoleRecordsService; import admin.modules.chatgpt.service.ChatgptRoleRecordsService;
import admin.modules.chatgpt.service.ChatgptRoleSessionService; import admin.modules.chatgpt.service.ChatgptRoleSessionService;
import admin.resp.PythonResp;
import admin.service.MaxkbOpenApiService; import admin.service.MaxkbOpenApiService;
import admin.service.PythonOpenApiClient; import admin.service.PythonOpenApiClient;
import admin.util.*; import admin.util.*;
...@@ -18,6 +19,7 @@ import okhttp3.HttpUrl; ...@@ -18,6 +19,7 @@ import okhttp3.HttpUrl;
import okhttp3.OkHttpClient; import okhttp3.OkHttpClient;
import okhttp3.Request; import okhttp3.Request;
import okhttp3.ResponseBody; import okhttp3.ResponseBody;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.annotation.Resource; import javax.annotation.Resource;
...@@ -98,13 +100,8 @@ public class VoiceWebSocketServer { ...@@ -98,13 +100,8 @@ public class VoiceWebSocketServer {
} }
//5.获取最新的会话id //5.获取最新的会话id
String maxSessionId = chatgptRoleRecordsService.queryMaxSessionId(); String maxSessionId = chatgptRoleRecordsService.queryMaxSessionId();
WebSocketModel webSocketModel = new WebSocketModel();
webSocketModel.setType("text");
webSocketModel.setAction("replaySessionId");
webSocketModel.setContent(maxSessionId);
webSocketModel.setSessionId(maxSessionId);
//6.返回给前端最新的sessionId //6.返回给前端最新的sessionId
String msg = JSON.toJSONString(webSocketModel); String msg = JSON.toJSONString(WebSocketModel.createSessionMode("replaySessionId","text",maxSessionId,maxSessionId));
try { try {
session.getBasicRemote().sendText(msg); session.getBasicRemote().sendText(msg);
} catch (IOException e) { } catch (IOException e) {
...@@ -126,6 +123,7 @@ public class VoiceWebSocketServer { ...@@ -126,6 +123,7 @@ public class VoiceWebSocketServer {
//存储不同的连接 //存储不同的连接
if (mark.equals(WebSocketUtil.H5)){ if (mark.equals(WebSocketUtil.H5)){
H5ConnectUtil.remove(name); H5ConnectUtil.remove(name);
log.info("webOnClose关闭调用{}",name);
popUpEvent(name,"webOnClose"); popUpEvent(name,"webOnClose");
}else { }else {
WebConnectUtil.remove(sessionId); WebConnectUtil.remove(sessionId);
...@@ -161,34 +159,14 @@ public class VoiceWebSocketServer { ...@@ -161,34 +159,14 @@ public class VoiceWebSocketServer {
//1.如果问题不存在则创建问题 //1.如果问题不存在则创建问题
ChatgptRoleSession byId = chatgptRoleSessionService.getById(webSocketModel.getSessionId()); ChatgptRoleSession byId = chatgptRoleSessionService.getById(webSocketModel.getSessionId());
if (byId == null && "sendText".equals(webSocketModel.getAction())) { if (byId == null && "sendText".equals(webSocketModel.getAction())) {
ChatgptRoleSession chatgptRoleSession = new ChatgptRoleSession(); chatgptRoleSessionService.saveRecord(Integer.valueOf(webSocketModel.getSessionId()),
chatgptRoleSession.setId(Integer.valueOf(webSocketModel.getSessionId())); webSocketModel.getData(),10001,ScreenEnum.getByUserName(webSocketModel.getName()));
chatgptRoleSession.setName(webSocketModel.getData());
chatgptRoleSession.setRoleDescId(10001);
chatgptRoleSession.setUserId(ScreenEnum.getByUserName(webSocketModel.getName()));
chatgptRoleSessionService.save(chatgptRoleSession);
//创建问题记录
ChatgptRoleRecords chatgptRoleRecords = new ChatgptRoleRecords();
chatgptRoleRecords.setMessage(webSocketModel.getData());
chatgptRoleRecords.setReceiverId(10001);
chatgptRoleRecords.setSessionId(Integer.valueOf(webSocketModel.getSessionId()));
chatgptRoleRecords.setSenderId(ScreenEnum.getByUserName(webSocketModel.getName()));
chatgptRoleRecords.setCreateTime(DateUtil.getNowTimestamp());
chatgptRoleRecords.setIsAsk(1);
chatgptRoleRecordsService.save(chatgptRoleRecords);
//如果是H5则发送给大屏消息 //如果是H5则发送给大屏消息
sendMsgToWeb(memberId,webSocketModel.getData()); sendMsgToWeb(memberId,webSocketModel.getData());
} else if (byId != null && "sendText".equals(webSocketModel.getAction())) { } else if (byId != null && "sendText".equals(webSocketModel.getAction())) {
ChatgptRoleRecords chatgptRoleRecords = new ChatgptRoleRecords(); chatgptRoleRecordsService.saveRecords(webSocketModel.getData(),10001,Integer.valueOf(webSocketModel.getSessionId()),ScreenEnum.getByUserName(webSocketModel.getName()),1);
chatgptRoleRecords.setMessage(webSocketModel.getData());
chatgptRoleRecords.setReceiverId(10001);
chatgptRoleRecords.setSessionId(Integer.valueOf(webSocketModel.getSessionId()));
chatgptRoleRecords.setSenderId(ScreenEnum.getByUserName(webSocketModel.getName()));
chatgptRoleRecords.setIsAsk(1);
chatgptRoleRecords.setCreateTime(DateUtil.getNowTimestamp());
chatgptRoleRecordsService.save(chatgptRoleRecords);
//如果是H5则发送给大屏消息 //如果是H5则发送给大屏消息
sendMsgToWeb(memberId,webSocketModel.getData()); sendMsgToWeb(memberId,webSocketModel.getData());
...@@ -200,32 +178,42 @@ public class VoiceWebSocketServer { ...@@ -200,32 +178,42 @@ public class VoiceWebSocketServer {
if (msg != null && !msg.isEmpty()) { if (msg != null && !msg.isEmpty()) {
ResponseEnum showType = getShowType(msg); ResponseEnum showType = getShowType(msg);
SendSseModel sendSseModel = new SendSseModel(msg, webSocketModel.getSessionId(), session, webSocketModel.getName(), memberId.split("__")[0].equals(WebSocketUtil.H5),showType); SendSseModel sendSseModel = new SendSseModel(msg, webSocketModel.getSessionId(), session, webSocketModel.getName(), memberId.split("__")[0].equals(WebSocketUtil.H5),showType);
log.info("文字聊天发送:{}",sendSseModel);
maxkbOpenApiService.talk(sendSseModel); maxkbOpenApiService.talk(sendSseModel);
} }
// 心跳 // 心跳
}else if("heartbeat".equals(webSocketModel.getAction())){ }else if("heartbeat".equals(webSocketModel.getAction())){
WebSocketModel webSocketModel1 = new WebSocketModel(); String msg = JSON.toJSONString( WebSocketModel.createBaseMode("heartbeat_ack","text",""));
webSocketModel1.setAction("heartbeat_ack");
webSocketModel1.setType("text");
webSocketModel1.setContent("");
String msg = JSON.toJSONString(webSocketModel1);
sendMessage(session,msg); sendMessage(session,msg);
}else if ("startAnalysis".equals(webSocketModel.getAction())){ }else if ("startAnalysis".equals(webSocketModel.getAction())){
if (byId == null){
chatgptRoleSessionService.saveRecord(Integer.valueOf(webSocketModel.getSessionId()),
webSocketModel.getData(),10001,ScreenEnum.getByUserName(webSocketModel.getName()));
//创建问题记录
chatgptRoleRecordsService.saveRecords(webSocketModel.getData(),10001,Integer.valueOf(webSocketModel.getSessionId()),ScreenEnum.getByUserName(webSocketModel.getName()),1);
}
PythonApiReq pythonApiReq = new PythonApiReq(); PythonApiReq pythonApiReq = new PythonApiReq();
pythonApiReq.setQuestion(webSocketModel.getData()); pythonApiReq.setQuestion(webSocketModel.getData());
String analysisData = pythonOpenApiClient.getAnalysisData(pythonApiReq); PythonResp analysisData = pythonOpenApiClient.getAnalysisData(pythonApiReq);
char[] charArray = analysisData.toCharArray(); if (analysisData.getType().equals(1)) {
for (int i=0;i<charArray.length;i++){ //左边内容
WebSocketModel webSocketModel1 = new WebSocketModel(); sendMessage(session,JSONObject.toJSONString( WebSocketModel.createDataList("reply","text",analysisData.getData())));
webSocketModel1.setAction("reply"); //右边内容
webSocketModel1.setType("text"); sendMessage(session,JSONObject.toJSONString( WebSocketModel.createBaseMode("rightReply","text",analysisData.getDataList())));
webSocketModel1.setContent(String.valueOf(charArray[i])); //结束标识
sendMessage(session,JSONObject.toJSONString(webSocketModel1)); sendMessage(session,JSONObject.toJSONString(WebSocketModel.createBaseMode("done","text","")));
//存储会话记录
chatgptRoleRecordsService.saveContent(analysisData.getData(),ScreenEnum.getByUserName(memberId.split("__")[1]) ,Integer.valueOf(webSocketModel.getSessionId()),10001,0,analysisData.getDataList()!=null?1:0,analysisData.getDataList());
}else if (analysisData.getType().equals(2)){
//左边内容
sendMessage(session,JSONObject.toJSONString(WebSocketModel.createChartMode("reply","text",analysisData.getData(),StringUtils.isNotBlank(analysisData.getFile()) ? "http://newscreen.justh5.com/bg/" + analysisData.getFile() : null)));
//结束标识
sendMessage(session,JSONObject.toJSONString(WebSocketModel.createChartMode("done","chart",analysisData.getData(),StringUtils.isNotBlank(analysisData.getFile()) ? "http://newscreen.justh5.com/bg/" + analysisData.getFile() : null)));
//存储会话记录
chatgptRoleRecordsService.saveContent(analysisData.getData(),ScreenEnum.getByUserName(memberId.split("__")[1]),Integer.valueOf(webSocketModel.getSessionId()),10001,0,StringUtils.isNotBlank(analysisData.getFile())?2:0,StringUtils.isNotBlank(analysisData.getFile())?"http://newscreen.justh5.com/bg/" + analysisData.getFile():null);
} }
WebSocketModel endWebSocket = new WebSocketModel();
endWebSocket.setAction("done");
endWebSocket.setType("text");
sendMessage(session,JSONObject.toJSONString(endWebSocket));
} }
} }
......
package admin.service; package admin.service;
import admin.model.python.PythonApiReq; import admin.model.python.PythonApiReq;
import admin.resp.PythonResp;
import java.util.List; import java.util.List;
...@@ -15,7 +16,7 @@ public interface PythonOpenApiClient { ...@@ -15,7 +16,7 @@ public interface PythonOpenApiClient {
* @param pythonApiReq * @param pythonApiReq
* @return * @return
*/ */
String getAnalysisData(PythonApiReq pythonApiReq); PythonResp getAnalysisData(PythonApiReq pythonApiReq);
/** /**
* 获取相似问题 * 获取相似问题
......
package admin.service.impl; package admin.service.impl;
import admin.model.python.PythonApiReq; import admin.model.python.PythonApiReq;
import admin.resp.PythonResp;
import admin.service.PythonOpenApiClient; import admin.service.PythonOpenApiClient;
import admin.util.HttpUtil; import admin.util.HttpUtil;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
...@@ -19,8 +20,8 @@ import java.util.List; ...@@ -19,8 +20,8 @@ import java.util.List;
@Slf4j @Slf4j
public class PythonOpenApiClientImpl implements PythonOpenApiClient { public class PythonOpenApiClientImpl implements PythonOpenApiClient {
@Override @Override
public String getAnalysisData(PythonApiReq pythonApiReq) { public PythonResp getAnalysisData(PythonApiReq pythonApiReq) {
return HttpUtil.post("http://py.justh5.com/aiapi/sqlqa/", pythonApiReq); return JSONObject.parseObject(HttpUtil.post("http://py.justh5.com/aiapi/sqlqa/", pythonApiReq),PythonResp.class);
} }
@Override @Override
......
...@@ -39,7 +39,7 @@ public class HttpUtil { ...@@ -39,7 +39,7 @@ public class HttpUtil {
public static String post(String url,Object data){ public static String post(String url,Object data){
OkHttpClient okHttpClient = new OkHttpClient().newBuilder().connectTimeout(Duration.ofSeconds(30)).build(); OkHttpClient okHttpClient = new OkHttpClient().newBuilder().readTimeout(Duration.ofMinutes(1)).connectTimeout(Duration.ofMinutes(1)).build();
Request request = null; Request request = null;
try { try {
request = new Request.Builder() request = new Request.Builder()
......
...@@ -33,15 +33,15 @@ public enum ResponseEnum{ ...@@ -33,15 +33,15 @@ public enum ResponseEnum{
ZK_PLATFORM(8,"运营平台", Arrays.asList("https://bj-img.justh5.com/newBigScreen/software/yypt1.png", "https://bj-img.justh5.com/newBigScreen/software/yypt2.png","https://bj-img.justh5.com/newBigScreen/software/yypt3.png","https://bj-img.justh5.com/newBigScreen/software/yypt4.png"),null,null), ZK_PLATFORM(8,"运营平台", Arrays.asList("https://bj-img.justh5.com/newBigScreen/software/yypt1.png", "https://bj-img.justh5.com/newBigScreen/software/yypt2.png","https://bj-img.justh5.com/newBigScreen/software/yypt3.png","https://bj-img.justh5.com/newBigScreen/software/yypt4.png"),null,null),
ZK_SMALL_PROGRAM(8,"客户端小程序", Arrays.asList("https://bj-img.justh5.com/newBigScreen/software/khdxcx1.png", "https://bj-img.justh5.com/newBigScreen/software/khdxcx2.png","https://bj-img.justh5.com/newBigScreen/software/khdxcx3.png","https://bj-img.justh5.com/newBigScreen/software/khdxcx4.png"),null,null), ZK_SMALL_PROGRAM(8,"客户端小程序", Arrays.asList("https://bj-img.justh5.com/newBigScreen/software/khdxcx1.png", "https://bj-img.justh5.com/newBigScreen/software/khdxcx2.png","https://bj-img.justh5.com/newBigScreen/software/khdxcx3.png","https://bj-img.justh5.com/newBigScreen/software/khdxcx4.png"),null,null),
ZK_POS(8,"手持机收费终端", Arrays.asList("https://bj-img.justh5.com/newBigScreen/software/sjzd1.png", "https://bj-img.justh5.com/newBigScreen/software/sjzd2.png","https://bj-img.justh5.com/newBigScreen/software/sjzd3.png","https://bj-img.justh5.com/newBigScreen/software/sjzd4.png"),null,null), ZK_POS(8,"手持机收费终端", Arrays.asList("https://bj-img.justh5.com/newBigScreen/software/sjzd1.png", "https://bj-img.justh5.com/newBigScreen/software/sjzd2.png","https://bj-img.justh5.com/newBigScreen/software/sjzd3.png","https://bj-img.justh5.com/newBigScreen/software/sjzd4.png"),null,null),
ZK_TB(9,"汤波", Collections.singletonList("https://bj-img.justh5.com/newBigScreen/person/tb.png"),"创始人&董事长","中科慧居创始人;中科院研究生、MBA、中科院第一届创新创业班成员;动静态一体智能交通研究院副院长、中海地产项目经理、智能家居项目负责人;注册一级建造师、物联网领域资深专家;20多项国家专利发明人、2015年互联网+创新创业大赛全国总决赛最佳创业项目奖、2021年嘉兴市创业领军人才、2022年度科创中国长三角G60创业榜单30强。"), ZK_TB(9,"汤波", Collections.singletonList("https://bj-img.justh5.com/newBigScreen/person/tb1.png"),"创始人&董事长","中科慧居创始人;中科院研究生、MBA、中科院第一届创新创业班成员;动静态一体智能交通研究院副院长、中海地产项目经理、智能家居项目负责人;注册一级建造师、物联网领域资深专家;20多项国家专利发明人、2015年互联网+创新创业大赛全国总决赛最佳创业项目奖、2021年嘉兴市创业领军人才、2022年度科创中国长三角G60创业榜单30强。"),
ZK_LL(9,"李乐", Collections.singletonList("https://bj-img.justh5.com/newBigScreen/person/ll.png"),"联合创始人","中国科学院硕士研究生;人力资源经济师;原世界500强企业人力资源总监;十余年人力资源管理经验,具备系统的专业知识和丰富的实战经历。"), ZK_LL(9,"李乐", Collections.singletonList("https://bj-img.justh5.com/newBigScreen/person/ll1.png"),"联合创始人","中国科学院硕士研究生;人力资源经济师;原世界500强企业人力资源总监;十余年人力资源管理经验,具备系统的专业知识和丰富的实战经历。"),
ZK_LBL(9,"吕泊岚", Collections.singletonList("https://bj-img.justh5.com/newBigScreen/person/lbl.png"),"联合创始人","美国纽约伯克利大学海归,CFA;之江创业基金合伙人;中科慧居创始合伙人;沣墒资本管理合伙人;中科智泊科技董事长;畅尔装备监事。"), ZK_LBL(9,"吕泊岚", Collections.singletonList("https://bj-img.justh5.com/newBigScreen/person/lbl1.png"),"联合创始人","美国纽约伯克利大学海归,CFA;之江创业基金合伙人;中科慧居创始合伙人;沣墒资本管理合伙人;中科智泊科技董事长;畅尔装备监事。"),
ZK_SWW(9,"孙巍巍", Collections.singletonList("https://bj-img.justh5.com/newBigScreen/person/sww.png"),"联合创始人","原百度IDG事业部智慧停车行业总经理; 原精英路通常务副总经理;中交一公局停车行业运营总监; 两项国家行业标准参与制定者;省级科技进步一等奖。"), ZK_SWW(9,"孙巍巍", Collections.singletonList("https://bj-img.justh5.com/newBigScreen/person/sww1.png"),"联合创始人","原百度IDG事业部智慧停车行业总经理; 原精英路通常务副总经理;中交一公局停车行业运营总监; 两项国家行业标准参与制定者;省级科技进步一等奖。"),
ZK_LZL(9,"刘照琳", Collections.singletonList("https://bj-img.justh5.com/newBigScreen/person/lzl.png"),"联合创始人","英国巴斯大学硕士研究生;原世界五百强企业产品总监,具备丰富的设计及项目管理经验;熟悉3DSMAX、Rhino、SketchUp、AutoCAD等软件应用。"), ZK_LZL(9,"刘照琳", Collections.singletonList("https://bj-img.justh5.com/newBigScreen/person/lzl1.png"),"联合创始人","英国巴斯大学硕士研究生;原世界五百强企业产品总监,具备丰富的设计及项目管理经验;熟悉3DSMAX、Rhino、SketchUp、AutoCAD等软件应用。"),
ZK_ZH(9,"钟华", Collections.singletonList("https://bj-img.justh5.com/newBigScreen/person/zh.png"),"特聘专家顾问","中国科学院大学软件研究所所长;博士生导师;中科院软件工程技术研究开发中心主任;中国软件行业协会常务理事;中国计算机协会理事。"), ZK_ZH(9,"钟华", Collections.singletonList("https://bj-img.justh5.com/newBigScreen/person/zh1.png"),"特聘专家顾问","中国科学院大学软件研究所所长;博士生导师;中科院软件工程技术研究开发中心主任;中国软件行业协会常务理事;中国计算机协会理事。"),
ZK_LHQ(9,"李海青", Collections.singletonList("https://bj-img.justh5.com/newBigScreen/person/lhq.png"),"技术专家","中科院自动化所研究员;博士,师从谭铁牛院士;虹膜识别和人脸识别算法资深技术专家;中科虹霸、中科虹星人工智能算法首席技术负责人。"), ZK_LHQ(9,"李海青", Collections.singletonList("https://bj-img.justh5.com/newBigScreen/person/lhq1.png"),"技术专家","中科院自动化所研究员;博士,师从谭铁牛院士;虹膜识别和人脸识别算法资深技术专家;中科虹霸、中科虹星人工智能算法首席技术负责人。"),
ZK_FT(9,"冯涛", Collections.singletonList("https://bj-img.justh5.com/newBigScreen/person/ft.png"),"技术专家","北京科技大学博士、副教授;第21届北京市优秀青年工程师;专注于物联网、人工智能、机器人领域的研究;获得多项科技奖项与发明专利。"), ZK_FT(9,"冯涛", Collections.singletonList("https://bj-img.justh5.com/newBigScreen/person/ft1.png"),"技术专家","北京科技大学博士、副教授;第21届北京市优秀青年工程师;专注于物联网、人工智能、机器人领域的研究;获得多项科技奖项与发明专利。"),
ZK_LRH(9,"刘瑞华", Collections.singletonList("https://bj-img.justh5.com/newBigScreen/person/lhr.png"),"人工智能专家","中科院生态研究中心所博士;福布斯中国北美华人top60;美国希尔研究院创始合伙人;国家公派出国奖学金;中国科学院国际交流奖学金。"); ZK_LRH(9,"刘瑞华", Collections.singletonList("https://bj-img.justh5.com/newBigScreen/person/lhr1.png"),"人工智能专家","中科院生态研究中心所博士;福布斯中国北美华人top60;美国希尔研究院创始合伙人;国家公派出国奖学金;中国科学院国际交流奖学金。");
int type; int type;
String desc; String desc;
List<String> imgs; List<String> imgs;
......
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