Commit b09a62a2 authored by luojun's avatar luojun

deepseek优化

parent 78c55c1d
......@@ -49,50 +49,24 @@ public class DeepSeekAiListener extends EventSourceListener {
}
private void sendStartTranslate(Session session) {
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 {
session.getBasicRemote().sendText(JSON.toJSONString(webSocketModel));
} catch (IOException e) {
throw new RuntimeException(e);
}
} else if (maxKbChatReq.getShowType()!=null && maxKbChatReq.getShowType().equals(ResponseEnum.ZK_PRODUCT.getDesc())){
WebSocketModel webSocketModel = new WebSocketModel();
webSocketModel.setAction("start");
webSocketModel.setType("text");
webSocketModel.setShowType(maxKbChatReq.getShowType());
webSocketModel.setContent("");
try {
session.getBasicRemote().sendText(JSON.toJSONString(webSocketModel));
} catch (IOException e) {
throw new RuntimeException(e);
}
}else if (maxKbChatReq.getShowType()!=null && maxKbChatReq.getShowType().equals(ResponseEnum.ZK_USER.getDesc())){
WebSocketModel webSocketModel = new WebSocketModel();
webSocketModel.setAction("start");
webSocketModel.setType("text");
webSocketModel.setShowType(maxKbChatReq.getShowType());
webSocketModel.setContent("");
try {
session.getBasicRemote().sendText(JSON.toJSONString(webSocketModel));
} catch (IOException e) {
throw new RuntimeException(e);
}
}else if (maxKbChatReq.getShowType()!=null && maxKbChatReq.getShowType().equals(ResponseEnum.ZK_SOFTWARE.getDesc())){
WebSocketModel webSocketModel = new WebSocketModel();
webSocketModel.setAction("start");
webSocketModel.setType("text");
webSocketModel.setShowType(maxKbChatReq.getShowType());
webSocketModel.setContent("");
try {
session.getBasicRemote().sendText(JSON.toJSONString(webSocketModel));
} catch (IOException e) {
throw new RuntimeException(e);
}
if (maxKbChatReq.getShowType()!=null){
sendStartMessage(session);
}
}
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.setContent("");
try {
session.getBasicRemote().sendText(JSON.toJSONString(webSocketModel));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
......@@ -109,7 +83,9 @@ public class DeepSeekAiListener extends EventSourceListener {
Map<String,Object> map = new HashMap<>();
map.put("action","done");
map.put("type","text");
map.put("showType",maxKbChatReq.getShowType());
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);
......@@ -184,25 +160,6 @@ 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);
......
package admin.model;
import admin.util.ResponseEnum;
import lombok.Data;
import javax.websocket.Session;
......@@ -37,7 +38,7 @@ public class MaxKbChatReq {
/**
* 前端展示类型 1-中科慧居简介
*/
private String showType;
private ResponseEnum showType;
/**
* maxkb访问路径
*/
......
package admin.model;
import admin.util.ResponseEnum;
import lombok.AllArgsConstructor;
import lombok.Data;
......@@ -37,5 +38,5 @@ public class SendSseModel {
/**
* 前端根据这类型进行判断:1-中科慧居简介 2-饼状图 3-柱状图 4-趋势图
*/
private String showType;
private ResponseEnum showType;
}
......@@ -2,6 +2,8 @@ package admin.model;
import lombok.Data;
import java.util.List;
/**
* @author lj
* @date 2025/2/27 17:38
......@@ -31,5 +33,13 @@ public class WebSocketModel {
/**
* 前端根据这类型进行判断:1-中科慧居简介 2-饼状图 3-柱状图 4-趋势图
*/
private String showType;
private Integer showType;
/**
* 组件展示的标题名称
*/
private String title;
/**
* 图片列表
*/
private List<String> imgs;
}
......@@ -6,12 +6,14 @@ import admin.model.python.PythonApiReq;
import admin.resp.ApiResponse;
import admin.service.DeepSeekOpenApiService;
import admin.service.MaxkbOpenApiService;
import admin.service.OpenConnectService;
import admin.service.PythonOpenApiClient;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import javax.websocket.Session;
import java.util.List;
/**
* @author lj
......@@ -23,33 +25,9 @@ import javax.websocket.Session;
@Slf4j
public class OpenApiController {
private final DeepSeekOpenApiService deepSeekOpenApiService;
private final MaxkbOpenApiService maxkbOpenApiService;
private final PythonOpenApiClient pythonOpenApiClient;
@PostMapping(value = "completions")
public ApiResponse<Object> completions(@RequestParam String content){
deepSeekOpenApiService.chatCompletions(content);
return null;
}
@GetMapping("testOpen")
public ApiResponse<Object> open(@RequestParam String applicationId){
return maxkbOpenApiService.getMaxkbSessionId(applicationId);
}
@GetMapping("testcompletions")
public void testcompletions(@RequestParam MaxKbChatReq maxKbChatReqe){
maxkbOpenApiService.chatCompletions(maxKbChatReqe);
}
@GetMapping("aItalk")
public void testcompletions(@RequestParam SendSseModel sendSseModel){
maxkbOpenApiService.talk(sendSseModel);
}
private final PythonOpenApiClient pythonOpenApiClient;
private final OpenConnectService openConnectService;
@GetMapping("testAnalysis")
public ApiResponse<Object> testAnalysis(PythonApiReq pythonApiReq){
......@@ -57,4 +35,21 @@ public class OpenApiController {
return ApiResponse.buildSuccess(analysisData);
}
/**
* 相似问题
* @param pythonApiReq
* @return
*/
@PostMapping("similarProblems")
public ApiResponse<Object> similarProblems(@RequestBody PythonApiReq pythonApiReq){
List<String> similarProblems = pythonOpenApiClient.getSimilarProblems(pythonApiReq);
return ApiResponse.buildSuccess(similarProblems);
}
@GetMapping("webOnOpen")
public ApiResponse<Object> webOnOpen(@RequestParam String name,@RequestParam String action){
openConnectService.popUpEvent(name,action);
return ApiResponse.buildSuccess();
}
}
......@@ -92,7 +92,7 @@ public class VoiceWebSocketServer {
//4.存储不同的连接
if (mark.equals(WebSocketUtil.H5)){
H5ConnectUtil.add(name);
popUpEvent(name,"webOnOpen");
// popUpEvent(name,"webOnOpen");
}else {
WebConnectUtil.put(sessionId,name,session);
}
......@@ -198,7 +198,7 @@ public class VoiceWebSocketServer {
if ("sendText".equals(webSocketModel.getAction())) {
String msg = webSocketModel.getData();
if (msg != null && !msg.isEmpty()) {
String showType = getShowType(msg);
ResponseEnum showType = getShowType(msg);
SendSseModel sendSseModel = new SendSseModel(msg, webSocketModel.getSessionId(), session, webSocketModel.getName(), memberId.split("__")[0].equals(WebSocketUtil.H5),showType);
maxkbOpenApiService.talk(sendSseModel);
}
......@@ -299,21 +299,39 @@ public class VoiceWebSocketServer {
sendMessage(session, null);
}
public String getShowType(String msg){
if (msg.contains("中科慧居") && msg.contains("产品介绍")){
return ResponseEnum.ZK_PRODUCT.getDesc();
public ResponseEnum getShowType(String msg){
if (msg.contains("中科慧居") && (msg.contains("超级魔盒") || msg.contains("物联网超级魔盒"))){
return ResponseEnum.ZK_SMH;
}else if (msg.contains("中科慧居") && (msg.contains("无线高位视频") || msg.contains("ETC系列设备"))){
return ResponseEnum.ZK_WHETC;
}else if (msg.contains("中科慧居") &&(msg.contains("无线视频桩") || msg.contains("视频桩"))){
return ResponseEnum.ZK_WVP;
}else if (msg.contains("中科慧居") && (msg.contains("无线路牙机") || msg.contains("路牙机"))){
return ResponseEnum.ZK_WCC;
}else if (msg.contains("中科慧居") && msg.contains("巡检车")){
return ResponseEnum.ZK_IRV;
}else if (msg.contains("中科慧居") && (msg.contains("太阳能平板地锁") || msg.contains("地锁"))){
return ResponseEnum.ZK_SPPL;
}else if (msg.contains("中科慧居") && msg.contains("立体车库")){
return ResponseEnum.ZK_APS;
}else if (msg.contains("中科慧居") && msg.contains("自助洗车一体化")){
return ResponseEnum.ZK_ISCW;
}else if (msg.contains("中科慧居") && msg.contains("停充储一体化")){
return ResponseEnum.ZK_IPCS;
} else if (msg.contains("中科慧居") && msg.contains("产品介绍")){
return ResponseEnum.ZK_PRODUCT;
}else if (msg.contains("中科慧居") && msg.contains("人员介绍")){
return ResponseEnum.ZK_USER.getDesc();
return ResponseEnum.ZK_USER;
}else if (msg.contains("中科慧居") && msg.contains("软件介绍")){
return ResponseEnum.ZK_SOFTWARE.getDesc();
return ResponseEnum.ZK_SOFTWARE;
}else if (msg.contains("中科慧居") && msg.contains("简介")){
return ResponseEnum.ZK_PROFILE.getDesc();
return ResponseEnum.ZK_PROFILE;
}else if (msg.contains( ResponseEnum.PIE_CHART.getDesc())){
return ResponseEnum.PIE_CHART.getDesc();
return ResponseEnum.PIE_CHART;
}else if (msg.contains( ResponseEnum.BAR_CHART.getDesc())){
return ResponseEnum.BAR_CHART.getDesc();
return ResponseEnum.BAR_CHART;
}else if (msg.contains( ResponseEnum.TREND_CHART.getDesc())){
return ResponseEnum.TREND_CHART.getDesc();
return ResponseEnum.TREND_CHART;
}
return null;
}
......
package admin.service;
/**
* @author lj
* @date 2025/3/18 18:18
*/
public interface OpenConnectService {
/**
* 唤醒大屏
* @param name 大屏名称
* @param action 行为
*/
void popUpEvent(String name, String action);
}
......@@ -2,11 +2,25 @@ package admin.service;
import admin.model.python.PythonApiReq;
import java.util.List;
/**
* @author lj
* @date 2025/3/13 15:17
*/
public interface PythonOpenApiClient {
/**
* 获取分析结果
* @param pythonApiReq
* @return
*/
String getAnalysisData(PythonApiReq pythonApiReq);
/**
* 获取相似问题
* @param pythonApiReq
* @return
*/
List<String> getSimilarProblems(PythonApiReq pythonApiReq);
}
package admin.service.impl;
import admin.model.WebSocketModel;
import admin.service.OpenConnectService;
import admin.util.WebConnectUtil;
import com.alibaba.fastjson.JSONObject;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import javax.websocket.Session;
import java.io.IOException;
import java.util.List;
/**
* @author lj
* @date 2025/3/18 18:18
*/
@Service
@RequiredArgsConstructor
public class OpenConnectServiceImpl implements OpenConnectService {
@Override
public 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);
}
});
}
}
}
......@@ -8,6 +8,8 @@ import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* @author lj
* @date 2025/3/13 15:17
......@@ -20,4 +22,10 @@ public class PythonOpenApiClientImpl implements PythonOpenApiClient {
public String getAnalysisData(PythonApiReq pythonApiReq) {
return HttpUtil.post("http://py.justh5.com/aiapi/sqlqa/", pythonApiReq);
}
@Override
public List<String> getSimilarProblems(PythonApiReq pythonApiReq) {
String post = HttpUtil.post("http://py.justh5.com/aiapi/relatedIssues", pythonApiReq);
return JSONObject.parseArray(post,String.class);
}
}
......@@ -3,6 +3,9 @@ package admin.util;
import lombok.AllArgsConstructor;
import lombok.Getter;
import java.util.Arrays;
import java.util.List;
/**
* @author lj
* @date 2025/3/5 14:23
......@@ -10,14 +13,24 @@ import lombok.Getter;
@Getter
@AllArgsConstructor
public enum ResponseEnum{
ZK_PROFILE(1,"中科慧居简介"),
PIE_CHART(2,"饼状图"),
BAR_CHART(3,"柱状图"),
TREND_CHART(4,"趋势图"),
ZK_PRODUCT(5,"中科慧居产品介绍"),
ZK_USER(6,"中科慧居人员介绍"),
ZK_SOFTWARE(7,"中科慧居软件介绍");
ZK_PROFILE(1,"中科慧居简介",null),
PIE_CHART(2,"饼状图",null),
BAR_CHART(3,"柱状图",null),
TREND_CHART(4,"趋势图",null),
ZK_PRODUCT(5,"中科慧居产品介绍",null),
ZK_USER(6,"中科慧居人员介绍",null),
ZK_SOFTWARE(7,"中科慧居软件介绍",null),
ZK_SMH(8,"物联网超级魔盒", Arrays.asList("https://bj-img.justh5.com/newBigScreen/product/wlhh1.png", "https://bj-img.justh5.com/newBigScreen/product/wlhh2.png")),
ZK_WHETC(8,"无线高位视频+ETC系列设备", Arrays.asList("https://bj-img.justh5.com/newBigScreen/product/wxgw1.png", "https://bj-img.justh5.com/newBigScreen/product/wxgw2.png")),
ZK_WVP(8,"无线视频桩", Arrays.asList("https://bj-img.justh5.com/newBigScreen/product/wxsp1.png", "https://bj-img.justh5.com/newBigScreen/product/wxsp2.png")),
ZK_WCC(8,"无线路牙机", Arrays.asList("https://bj-img.justh5.com/newBigScreen/product/lyj1.jpg")),
ZK_IRV(8,"巡检车", Arrays.asList("https://bj-img.justh5.com/newBigScreen/product/xjc1.png", "https://bj-img.justh5.com/newBigScreen/product/xjc2.png")),
ZK_SPPL(8,"太阳能平板地锁", Arrays.asList("https://bj-img.justh5.com/newBigScreen/product/tyn1.png", "https://bj-img.justh5.com/newBigScreen/product/tyn2.png")),
ZK_APS(8,"立体车库", Arrays.asList("https://bj-img.justh5.com/newBigScreen/product/ltck1.png", "https://bj-img.justh5.com/newBigScreen/product/ltck2.png")),
ZK_ISCW(8,"自助洗车一体化场景", Arrays.asList("https://bj-img.justh5.com/newBigScreen/product/tcc3.png", "https://bj-img.justh5.com/newBigScreen/product/tcc4.png")),
ZK_IPCS(8,"停充储一体化服务", Arrays.asList("https://bj-img.justh5.com/newBigScreen/product/tcc1.png", "https://bj-img.justh5.com/newBigScreen/product/tcc2.png"));
int type;
String desc;
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