|
@@ -74,7 +74,7 @@ public class ChatHistoryController extends BaseController {
|
|
|
@PostMapping("/refresh")
|
|
|
@JwtIgnore
|
|
|
@ApiOperation(value = "刷新某条回答", notes = "ChatHistory对象")
|
|
|
- public Result refresh(@RequestBody String json) {
|
|
|
+ public Result refresh(@RequestBody String json) throws InterruptedException {
|
|
|
ChatHistoryEntity chatHistoryEntity = JSONObject.parseObject(json, ChatHistoryEntity.class);
|
|
|
String dialogueId = chatHistoryEntity.getDialogueId();
|
|
|
String createTime = chatHistoryEntity.getCreateTime();
|
|
@@ -151,7 +151,9 @@ public class ChatHistoryController extends BaseController {
|
|
|
.post(requestBody)
|
|
|
.build();
|
|
|
// 发送请求并处理响应
|
|
|
+ String progress = "undo";
|
|
|
try (Response response = client.newCall(request).execute()) {
|
|
|
+ progress = "doing";
|
|
|
if (!response.isSuccessful()) {
|
|
|
log.error("Unexpected code " + response);
|
|
|
return fail();
|
|
@@ -162,55 +164,63 @@ public class ChatHistoryController extends BaseController {
|
|
|
if (responseBody != null) {
|
|
|
BufferedSource bufferedSource = responseBody.source();
|
|
|
try {
|
|
|
- String line;
|
|
|
byte[] buffer = new byte[1024];
|
|
|
while (!bufferedSource.exhausted()) {
|
|
|
int bytesRead = bufferedSource.read(buffer);
|
|
|
- line = new String(buffer, 0, bytesRead);
|
|
|
+ String datas = new String(buffer, 0, bytesRead);
|
|
|
if (sseEmitterService.getEmitter(dialogueId) == null) {
|
|
|
if (flag.equals("think")) {
|
|
|
stringBuilder.append("</").append(flag).append(">");
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
- sseResultDataDto.setType(flag);
|
|
|
- System.out.println("line==" + line);
|
|
|
- JSONObject jsonObject = null;
|
|
|
- try {
|
|
|
- if(StringUtils.isNotEmpty(line)){
|
|
|
- jsonObject=JSONObject.parseObject(line);
|
|
|
- }
|
|
|
+ log.info("datas==" + datas+"===end");
|
|
|
+ String[] lines = datas.split("<quan-cut>");
|
|
|
+ for (String line : lines) {
|
|
|
|
|
|
- } catch (Exception e) {
|
|
|
- log.error(line+"json解析失败",e);
|
|
|
- continue;
|
|
|
+ sseResultDataDto.setType(flag);
|
|
|
+ System.out.println("line==" + line);
|
|
|
+ log.info("line==="+line+"===");
|
|
|
+ JSONObject jsonObject = null;
|
|
|
+ try {
|
|
|
+ if (StringUtils.isNotEmpty(line)) {
|
|
|
+ jsonObject = JSONObject.parseObject(line);
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(line + "json解析失败", e);
|
|
|
+ continue;
|
|
|
|
|
|
- }
|
|
|
- String event = jsonObject.getString("event");
|
|
|
- if(event.equals("error")){
|
|
|
- if (flag.equals("think")) {
|
|
|
- stringBuilder.append("</").append(flag).append(">");
|
|
|
}
|
|
|
- break;
|
|
|
- }
|
|
|
- String data = jsonObject.getString("data");
|
|
|
- if (StringUtils.isNotEmpty(data)) {
|
|
|
- stringBuilder.append(data);
|
|
|
- if(data.contains("</think>")){
|
|
|
- flag = "text";
|
|
|
- data = data.replace("</think>","");
|
|
|
+ String event = jsonObject.getString("event");
|
|
|
+ if (event.equals("error")) {
|
|
|
+ if (flag.equals("think")) {
|
|
|
+ stringBuilder.append("</").append(flag).append(">");
|
|
|
+ }
|
|
|
+ break;
|
|
|
}
|
|
|
- if(data.contains("<think>")){
|
|
|
- data = data.replace("<think>","");
|
|
|
+ String data = jsonObject.getString("data");
|
|
|
+ if (StringUtils.isNotEmpty(data)) {
|
|
|
+ stringBuilder.append(data);
|
|
|
+ if (data.contains("</think>")) {
|
|
|
+ flag = "text";
|
|
|
+ data = data.replace("</think>", "");
|
|
|
+ }
|
|
|
+ if (data.contains("<think>")) {
|
|
|
+ data = data.replace("<think>", "");
|
|
|
+ }
|
|
|
+ sseResultDataDto.setContent(data);
|
|
|
+ log.info("发送消息:{}", sseResultDataDto);
|
|
|
+ sseEmitterService.sendMessage(dialogueId, sseResultDataDto);
|
|
|
}
|
|
|
- sseResultDataDto.setContent(data);
|
|
|
- sseEmitterService.sendMessage(dialogueId, sseResultDataDto);
|
|
|
+ Thread.sleep(5);
|
|
|
}
|
|
|
- Thread.sleep(5);
|
|
|
+
|
|
|
}
|
|
|
+ progress = "done";
|
|
|
} catch (InterruptedException e) {
|
|
|
throw new RuntimeException(e);
|
|
|
- }finally {
|
|
|
+ } finally {
|
|
|
bufferedSource.close();
|
|
|
}
|
|
|
}
|
|
@@ -228,7 +238,9 @@ public class ChatHistoryController extends BaseController {
|
|
|
chatHistoryEntity.setCreateTime(DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss.SSS"));
|
|
|
chatHistoryEntity.setUpdateTime(DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss.SSS"));
|
|
|
chatHistoryEntity = this.chatHistoryService.save(chatHistoryEntity);
|
|
|
-
|
|
|
+ while (progress.equals("doing")) {
|
|
|
+ Thread.sleep(100);
|
|
|
+ }
|
|
|
return success(chatHistoryEntity);
|
|
|
}
|
|
|
|