|
@@ -3,14 +3,13 @@ package com.takai.bigmodel.service.impl;
|
|
|
import com.alibaba.fastjson2.JSON;
|
|
import com.alibaba.fastjson2.JSON;
|
|
|
import com.alibaba.fastjson2.JSONArray;
|
|
import com.alibaba.fastjson2.JSONArray;
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
|
-import com.takai.bigmodel.domain.dto.DialogDetailReqDTO;
|
|
|
|
|
-import com.takai.bigmodel.domain.dto.DialogReqDTO;
|
|
|
|
|
-import com.takai.bigmodel.domain.dto.DialogRespDTO;
|
|
|
|
|
|
|
+import com.takai.bigmodel.domain.dto.*;
|
|
|
import com.takai.bigmodel.domain.entity.*;
|
|
import com.takai.bigmodel.domain.entity.*;
|
|
|
import com.takai.bigmodel.mapper.*;
|
|
import com.takai.bigmodel.mapper.*;
|
|
|
import com.takai.bigmodel.service.IBigModelService;
|
|
import com.takai.bigmodel.service.IBigModelService;
|
|
|
import com.takai.common.config.BigModelConfig;
|
|
import com.takai.common.config.BigModelConfig;
|
|
|
import com.takai.common.core.redis.RedisCache;
|
|
import com.takai.common.core.redis.RedisCache;
|
|
|
|
|
+import com.takai.common.utils.uuid.IdUtils;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import okhttp3.*;
|
|
import okhttp3.*;
|
|
|
import okhttp3.sse.EventSource;
|
|
import okhttp3.sse.EventSource;
|
|
@@ -24,10 +23,13 @@ import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
|
|
|
|
|
|
|
|
import javax.validation.constraints.NotNull;
|
|
import javax.validation.constraints.NotNull;
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
|
-import java.util.ArrayList;
|
|
|
|
|
-import java.util.List;
|
|
|
|
|
-import java.util.Optional;
|
|
|
|
|
|
|
+import java.time.LocalDate;
|
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
|
|
+import java.time.temporal.ChronoUnit;
|
|
|
|
|
+import java.util.*;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 智谱 业务层处理
|
|
* 智谱 业务层处理
|
|
@@ -376,6 +378,12 @@ public class BigModelServiceImpl implements IBigModelService
|
|
|
|
|
|
|
|
OkHttpClient client = buildOkHttpClient();
|
|
OkHttpClient client = buildOkHttpClient();
|
|
|
List<BmApplication> applicationList = new ArrayList<>();
|
|
List<BmApplication> applicationList = new ArrayList<>();
|
|
|
|
|
+ // 默认一个
|
|
|
|
|
+// BmApplication application = BmApplication.builder()
|
|
|
|
|
+// .appId("1234567890123456789").build();
|
|
|
|
|
+// List<BmApplication> l = bmApplicationMapper.selectApplicationList(application);
|
|
|
|
|
+// applicationList.addAll(l);
|
|
|
|
|
+
|
|
|
try {
|
|
try {
|
|
|
Response response = client.newCall(request).execute();
|
|
Response response = client.newCall(request).execute();
|
|
|
if(response.isSuccessful()) {
|
|
if(response.isSuccessful()) {
|
|
@@ -401,6 +409,24 @@ public class BigModelServiceImpl implements IBigModelService
|
|
|
.build();
|
|
.build();
|
|
|
applicationList.add(bmApplication);
|
|
applicationList.add(bmApplication);
|
|
|
}
|
|
}
|
|
|
|
|
+ }else{
|
|
|
|
|
+ // 默认一个
|
|
|
|
|
+ String uuid = IdUtils.simpleUUID();
|
|
|
|
|
+ BmApplication bmApplication = BmApplication.builder()
|
|
|
|
|
+ .appId(uuid)
|
|
|
|
|
+ .name("default")
|
|
|
|
|
+ .desc("default")
|
|
|
|
|
+ .prompt("frist")
|
|
|
|
|
+ .topP("0.1")
|
|
|
|
|
+ .temperature("0.05")
|
|
|
|
|
+ .knowledgeIds("["+uuid+"]")
|
|
|
|
|
+ .sliceCount(4)
|
|
|
|
|
+ .model("glm-4-plus")
|
|
|
|
|
+ .iconColor("blue")
|
|
|
|
|
+ .iconType("robot_assist")
|
|
|
|
|
+ .build();
|
|
|
|
|
+ bmApplicationMapper.insertApplication(bmApplication);
|
|
|
|
|
+ applicationList.add(bmApplication);
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
log.error("智谱 获取应用列表失败:", response);
|
|
log.error("智谱 获取应用列表失败:", response);
|
|
@@ -493,24 +519,331 @@ public class BigModelServiceImpl implements IBigModelService
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public void saveDialog(DialogReqDTO dialogReqDTO) {
|
|
public void saveDialog(DialogReqDTO dialogReqDTO) {
|
|
|
- String dialogId = dialogReqDTO.getId();
|
|
|
|
|
- String id = dialogMapper.selectDialogById(dialogId);
|
|
|
|
|
- if(id == null) {
|
|
|
|
|
- dialogMapper.insertDialog(dialogId);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ //String dialogId = dialogReqDTO.getId();
|
|
|
|
|
+ //String id = dialogMapper.selectDialogById(dialogId);
|
|
|
|
|
+// if(id == null) {
|
|
|
|
|
+// String i = dialogMapper.insertDialog(dialogReqDTO);
|
|
|
|
|
+// }
|
|
|
|
|
+ String uuid = IdUtils.fastSimpleUUID();
|
|
|
|
|
+ dialogReqDTO.setId(uuid);
|
|
|
|
|
+ dialogMapper.insertDialog(dialogReqDTO);
|
|
|
for(DialogDetailReqDTO dto : dialogReqDTO.getMessages()) {
|
|
for(DialogDetailReqDTO dto : dialogReqDTO.getMessages()) {
|
|
|
- dto.setDialogId(dialogId);
|
|
|
|
|
- String detailId = dialogMapper.selectDialogDetailById(dto.getId());
|
|
|
|
|
|
|
+ dto.setDialogId(uuid);
|
|
|
|
|
+ String detailId = dialogMapper.selectDialogDetailById(uuid);
|
|
|
if(detailId == null) {
|
|
if(detailId == null) {
|
|
|
|
|
+ String detailUuid = IdUtils.fastSimpleUUID();
|
|
|
|
|
+ dto.setId(detailUuid);
|
|
|
dialogMapper.insertDialogDetail(dto);
|
|
dialogMapper.insertDialogDetail(dto);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
- public List<DialogRespDTO> getDialogList() {
|
|
|
|
|
- List<DialogRespDTO> dialogRespDTOS = dialogMapper.selectDialogList();
|
|
|
|
|
- return dialogRespDTOS;
|
|
|
|
|
|
|
+ public List<Object> getDialogList(String appId) {
|
|
|
|
|
+ List<DialogRespDTO> dialogRespDTOS = dialogMapper.selectDialogList(appId);
|
|
|
|
|
+ //当前日期
|
|
|
|
|
+ LocalDate today = LocalDate.now();
|
|
|
|
|
+ //根据时间分组降序排序
|
|
|
|
|
+ NavigableMap<LocalDateTime, List<DialogRespDTO>> groupList = dialogRespDTOS.stream().collect(Collectors.groupingBy(DialogRespDTO::getCreate_time, TreeMap::new, Collectors.toList())).descendingMap();
|
|
|
|
|
+ List<Object> obj = new ArrayList();
|
|
|
|
|
+ if(!groupList.isEmpty()){
|
|
|
|
|
+ for(Map.Entry<LocalDateTime, List<DialogRespDTO>> entry: groupList.entrySet()){
|
|
|
|
|
+ // 对比两个时间相差多少天
|
|
|
|
|
+ long daysBetween = ChronoUnit.DAYS.between(today, entry.getKey());
|
|
|
|
|
+ Map<String, Object> m = new HashMap();
|
|
|
|
|
+ m.put("key", System.currentTimeMillis());
|
|
|
|
|
+ m.put("type", "group");
|
|
|
|
|
+ if(daysBetween == 0l){
|
|
|
|
|
+ m.put("label", "今天");
|
|
|
|
|
+ m.put("children", setValue(entry.getValue()));
|
|
|
|
|
+ obj.add(m);
|
|
|
|
|
+ }else{
|
|
|
|
|
+ m.put("label", -daysBetween+"天前");
|
|
|
|
|
+ m.put("children", setValue(entry.getValue()));
|
|
|
|
|
+ obj.add(m);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return obj;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public DialogRespDTO getDialogDetail(String dialogId) {
|
|
|
|
|
+ DialogRespDTO detail = dialogMapper.selectDialogDetail(dialogId);
|
|
|
|
|
+ return detail;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public SseEmitter getCompletions(CompletionsParams params) {
|
|
|
|
|
+ String url = bigModelConfig.getCompletions();
|
|
|
|
|
+ System.out.println("------------------------"+url+"------------------------");
|
|
|
|
|
+ SseEmitter sseEmitter = new SseEmitter(0L);
|
|
|
|
|
+ JSONObject json = new JSONObject();
|
|
|
|
|
+ json.put("model",params.getModel());
|
|
|
|
|
+ json.put("messages",params.getMessages());
|
|
|
|
|
+ json.put("stream", params.getStream());
|
|
|
|
|
+ json.put("request_id", params.getRequest_id());
|
|
|
|
|
+// json.put("tools", params.getTools());
|
|
|
|
|
+// json.put("tool_choice", params.getTool_choice());
|
|
|
|
|
+ RequestBody requestBody = FormBody.create(MediaType.parse("application/json; charset=utf-8") , json.toJSONString());
|
|
|
|
|
+
|
|
|
|
|
+ Request request = buildPostRequest(url,requestBody);
|
|
|
|
|
+ // 使用EventSourceListener处理来自服务器的SSE事件
|
|
|
|
|
+ EventSourceListener listener = new EventSourceListener() {
|
|
|
|
|
+ private String preData = "";
|
|
|
|
|
+ //图片识别
|
|
|
|
|
+ private String symbolData = "";
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onOpen(@NotNull EventSource eventSource, @NotNull Response response) {
|
|
|
|
|
+ log.info("智谱 Connection opened.");
|
|
|
|
|
+ }
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onClosed(@NotNull EventSource eventSource) {
|
|
|
|
|
+ log.info("智谱 Connection closed.");
|
|
|
|
|
+ sseEmitter.complete();
|
|
|
|
|
+ }
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onEvent(@NotNull EventSource eventSource, String id, String type, @NotNull String data) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ boolean isJsonObj = isJsonObject(data);
|
|
|
|
|
+ if(isJsonObj){
|
|
|
|
|
+ JSONObject jsonObj = JSON.parseObject(data);
|
|
|
|
|
+ if(jsonObj != null){
|
|
|
|
|
+ log.info("jsonObj", jsonObj.toJSONString());
|
|
|
|
|
+ JSONArray array = jsonObj.getJSONArray("choices");
|
|
|
|
|
+ if(array != null){
|
|
|
|
|
+ for (int i=0; i<array.size(); i++) {
|
|
|
|
|
+ JSONObject json = new JSONObject();
|
|
|
|
|
+ JSONObject msgs = array.getJSONObject(i);
|
|
|
|
|
+ boolean status = msgs.containsKey("finish_reason");
|
|
|
|
|
+ JSONObject s = msgs.getJSONObject("delta");
|
|
|
|
|
+ json.put("id", String.valueOf(jsonObj.get("id")));
|
|
|
|
|
+ if(status){
|
|
|
|
|
+ json.put("event", "finish");
|
|
|
|
|
+ }else{
|
|
|
|
|
+ json.put("event", "add");
|
|
|
|
|
+ }
|
|
|
|
|
+ json.put("data", String.valueOf(s.get("content")));
|
|
|
|
|
+ log.info("智谱返回信息:" + json);
|
|
|
|
|
+ send(sseEmitter,json);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("智谱 推送数据失败", e);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onFailure(@NotNull EventSource eventSource, Throwable t, Response response) {
|
|
|
|
|
+ log.error("智谱 Connection failed.", t);
|
|
|
|
|
+ sseEmitter.completeWithError(t);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void send(SseEmitter sseEmitter, Object obj) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ sseEmitter.send(obj);
|
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
|
+ log.error("智谱 推送数据失败", e);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+ OkHttpClient client = buildOkHttpClient();
|
|
|
|
|
+ EventSource.Factory factory = EventSources.createFactory(client);
|
|
|
|
|
+ factory.newEventSource(request, listener);
|
|
|
|
|
+ return sseEmitter;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public String getSliceInfo(String requestId) {
|
|
|
|
|
+ String body = null;
|
|
|
|
|
+ String url = bigModelConfig.getBaseurl() + bigModelConfig.getSliceInfo().replace("{request_id}",requestId);
|
|
|
|
|
+ Request request = buildGetRequest(url);
|
|
|
|
|
+ OkHttpClient client = buildOkHttpClient();
|
|
|
|
|
+ try {
|
|
|
|
|
+ Response response = client.newCall(request).execute();
|
|
|
|
|
+ if(response.isSuccessful()) {
|
|
|
|
|
+ body = response.body().string();
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
|
+ throw new RuntimeException(e);
|
|
|
|
|
+ }
|
|
|
|
|
+ return body;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public AsyncCompletions getAsyncCompletions(CompletionsParams params) {
|
|
|
|
|
+ String url = bigModelConfig.getAsyncCompletions();
|
|
|
|
|
+ JSONObject json = new JSONObject();
|
|
|
|
|
+ json.put("model",params.getModel());
|
|
|
|
|
+ json.put("messages",params.getMessages());
|
|
|
|
|
+ RequestBody requestBody = FormBody.create(MediaType.parse("application/json; charset=utf-8") , json.toJSONString());
|
|
|
|
|
+
|
|
|
|
|
+ Request request = buildPostRequest(url,requestBody);
|
|
|
|
|
+ OkHttpClient client = buildOkHttpClient();
|
|
|
|
|
+ AsyncCompletions result = null;
|
|
|
|
|
+ try {
|
|
|
|
|
+ Response response = client.newCall(request).execute();
|
|
|
|
|
+ if(response.isSuccessful()){
|
|
|
|
|
+ String body = response.body().string();
|
|
|
|
|
+ JSONObject jsonObj = JSON.parseObject(body);
|
|
|
|
|
+ result = JSONObject.parseObject(String.valueOf(jsonObj), AsyncCompletions.class);
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
|
+ throw new RuntimeException(e);
|
|
|
|
|
+ }
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public AsyncResult getAsyncResult(String id) {
|
|
|
|
|
+ String url = bigModelConfig.getAsyncResult().replace("{id}", id);
|
|
|
|
|
+ Request request = buildGetRequest(url);
|
|
|
|
|
+ OkHttpClient client = buildOkHttpClient();
|
|
|
|
|
+ AsyncResult vo = null;
|
|
|
|
|
+ try {
|
|
|
|
|
+ Response response = client.newCall(request).execute();
|
|
|
|
|
+ if(response.isSuccessful()){
|
|
|
|
|
+ String body = response.body().string();
|
|
|
|
|
+ JSONObject jsonObj = JSON.parseObject(body);
|
|
|
|
|
+ vo = JSONObject.parseObject(String.valueOf(jsonObj), AsyncResult.class);
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
|
+ throw new RuntimeException(e);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return vo;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public SseEmitter assistant(AssistantParams params) {
|
|
|
|
|
+ String url = bigModelConfig.getAssistant();
|
|
|
|
|
+ log.info("------------------------"+url+"------------------------");
|
|
|
|
|
+ SseEmitter sseEmitter = new SseEmitter(0L);
|
|
|
|
|
+ JSONObject json = new JSONObject();
|
|
|
|
|
+ json.put("assistant_id", params.getAssistant_id());
|
|
|
|
|
+ json.put("model", params.getModel());
|
|
|
|
|
+ json.put("messages",params.getMessages());
|
|
|
|
|
+ json.put("stream", params.getStream());
|
|
|
|
|
+ RequestBody requestBody = FormBody.create(MediaType.parse("application/json; charset=utf-8") , json.toJSONString());
|
|
|
|
|
+
|
|
|
|
|
+ Request request = buildPostRequest(url,requestBody);
|
|
|
|
|
+ // 使用EventSourceListener处理来自服务器的SSE事件
|
|
|
|
|
+ EventSourceListener listener = new EventSourceListener() {
|
|
|
|
|
+ private String preData = "";
|
|
|
|
|
+ //图片识别
|
|
|
|
|
+ private String symbolData = "";
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onOpen(@NotNull EventSource eventSource, @NotNull Response response) {
|
|
|
|
|
+ log.info("智谱 Connection opened.");
|
|
|
|
|
+ }
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onClosed(@NotNull EventSource eventSource) {
|
|
|
|
|
+ log.info("智谱 Connection closed.");
|
|
|
|
|
+ sseEmitter.complete();
|
|
|
|
|
+ }
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onEvent(@NotNull EventSource eventSource, String id, String type, @NotNull String data) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ log.info("----------assistant---------"+data+"----------------assistant--------------");
|
|
|
|
|
+ boolean status = isJsonObject(data);
|
|
|
|
|
+ if(status){
|
|
|
|
|
+ JSONObject jsonObj = JSON.parseObject(data);
|
|
|
|
|
+ if(jsonObj != null){
|
|
|
|
|
+ JSONArray array = jsonObj.getJSONArray("choices");
|
|
|
|
|
+ if(array != null){
|
|
|
|
|
+ for(int i=0; i<array.size(); i++){
|
|
|
|
|
+ JSONObject obj = array.getJSONObject(i);
|
|
|
|
|
+ JSONObject deltaObj = obj.getJSONObject("delta");
|
|
|
|
|
+ String role = String.valueOf(deltaObj.get("role"));
|
|
|
|
|
+ boolean toolStatus = deltaObj.containsKey("tool_calls");
|
|
|
|
|
+ if("tool".equals(role) && toolStatus){
|
|
|
|
|
+ JSONObject json = new JSONObject();
|
|
|
|
|
+ json.put("id", jsonObj.get("id"));
|
|
|
|
|
+ json.put("assistant_id", jsonObj.get("assistant_id"));
|
|
|
|
|
+ json.put("conversation_id", jsonObj.get("conversation_id"));
|
|
|
|
|
+ JSONArray toolArray = deltaObj.getJSONArray("tool_calls");
|
|
|
|
|
+ if(toolArray != null){
|
|
|
|
|
+ for(int j=0; j<toolArray.size(); j++){
|
|
|
|
|
+ JSONObject toolObj = toolArray.getJSONObject(j);
|
|
|
|
|
+ String toolType = String.valueOf(toolObj.get("type"));
|
|
|
|
|
+ JSONObject webObj = toolObj.getJSONObject("web_browser");
|
|
|
|
|
+ JSONObject codeObj = toolObj.getJSONObject("code_interpreter");
|
|
|
|
|
+ json.put("event", "add");
|
|
|
|
|
+ if("web_browser".equals(toolType) && webObj != null){
|
|
|
|
|
+ if(webObj.containsKey("input")){
|
|
|
|
|
+ json.put("data", webObj.get("input"));
|
|
|
|
|
+ }
|
|
|
|
|
+ if(webObj.containsKey("outputs")){
|
|
|
|
|
+ json.put("data", webObj.getJSONArray("outputs"));
|
|
|
|
|
+ }
|
|
|
|
|
+ }else if("code_interpreter".equals(toolType) && codeObj != null){
|
|
|
|
|
+ if(codeObj.containsKey("input")){
|
|
|
|
|
+ json.put("data", codeObj.get("input"));
|
|
|
|
|
+ }
|
|
|
|
|
+ if(codeObj.containsKey("outputs")){
|
|
|
|
|
+ json.put("data", codeObj.getJSONArray("outputs"));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ log.info("智谱返回信息:" + json);
|
|
|
|
|
+ send(sseEmitter,json);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }else{
|
|
|
|
|
+ boolean finishStatus = deltaObj.containsKey("finish_reason");
|
|
|
|
|
+ if(finishStatus){
|
|
|
|
|
+ json.put("event", "finish");
|
|
|
|
|
+ }else{
|
|
|
|
|
+ json.put("event", "add");
|
|
|
|
|
+ }
|
|
|
|
|
+ json.put("data", deltaObj.get("content"));
|
|
|
|
|
+ log.info("智谱返回信息:" + json);
|
|
|
|
|
+ send(sseEmitter,json);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("智谱 推送数据失败", e);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onFailure(@NotNull EventSource eventSource, Throwable t, Response response) {
|
|
|
|
|
+ log.error("智谱 Connection failed.", t);
|
|
|
|
|
+ sseEmitter.completeWithError(t);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void send(SseEmitter sseEmitter, Object obj) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ sseEmitter.send(obj);
|
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
|
+ log.error("智谱 推送数据失败", e);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+ OkHttpClient client = buildOkHttpClient();
|
|
|
|
|
+ EventSource.Factory factory = EventSources.createFactory(client);
|
|
|
|
|
+ factory.newEventSource(request, listener);
|
|
|
|
|
+ return sseEmitter;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void DelDialogDetail(String id) {
|
|
|
|
|
+ int result = dialogMapper.delDialog(id);
|
|
|
|
|
+ if(result > 0){
|
|
|
|
|
+ dialogMapper.delDialogDetail(id);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void updateDialog(DialogReqDTO dialogReqDTO) {
|
|
|
|
|
+ dialogMapper.updateDialog(dialogReqDTO);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public List<DialogRespDTO> exportExcel(String id) {
|
|
|
|
|
+ return dialogMapper.selectDialogExport(id);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private Request buildGetRequest(String url) {
|
|
private Request buildGetRequest(String url) {
|
|
@@ -537,5 +870,24 @@ public class BigModelServiceImpl implements IBigModelService
|
|
|
.build();
|
|
.build();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private boolean isJsonObject(String data){
|
|
|
|
|
+ try {
|
|
|
|
|
+ JSON.parseObject(data);
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }catch (Exception e){
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private List<Map<String, Object>> setValue(List<DialogRespDTO> list){
|
|
|
|
|
+ List<Map<String, Object>> l = new ArrayList();
|
|
|
|
|
+ for (DialogRespDTO vo : list) {
|
|
|
|
|
+ Map<String, Object> map = new HashMap();
|
|
|
|
|
+ map.put("key", vo.getId());
|
|
|
|
|
+ map.put("label", vo.getDialog_name());
|
|
|
|
|
+ l.add(map);
|
|
|
|
|
+ }
|
|
|
|
|
+ return l;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
}
|
|
}
|