管理端登录报错修复

This commit is contained in:
2025-10-31 13:57:49 +08:00
parent e69e9920fe
commit cafbae4324
4 changed files with 54 additions and 16 deletions
@@ -971,7 +971,11 @@ public class AiChatServiceImpl implements AiChatService {
// 只处理answer类型的消息内容
if ("answer".equals(messageType) && content != null && !content.trim().isEmpty()) {
log.debug("提取增量内容: {}", content);
responseBuilder.append(content);
// 解析content中的JSON,提取output字段
String extractedContent = extractOutputFromContent(content);
if (extractedContent != null) {
responseBuilder.append(extractedContent);
}
}
}
@@ -990,7 +994,11 @@ public class AiChatServiceImpl implements AiChatService {
// 如果增量方式没有获取到内容,使用完整消息作为备用
if (responseBuilder.length() == 0) {
log.info("使用完整消息内容作为备用: {}", content);
responseBuilder.append(content);
// 解析content中的JSON,提取output字段
String extractedContent = extractOutputFromContent(content);
if (extractedContent != null) {
responseBuilder.append(extractedContent);
}
}
// 记录完整消息用于验证
log.debug("完整消息内容: {}", content);
@@ -1096,7 +1104,11 @@ public class AiChatServiceImpl implements AiChatService {
if ("answer".equals(jsonData.getString("type"))) {
String content = jsonData.getString("content");
if (content != null && !content.trim().isEmpty()) {
lastCompletedContent = content;
// 解析content中的JSON,提取output字段
String extractedContent = extractOutputFromContent(content);
if (extractedContent != null) {
lastCompletedContent = extractedContent;
}
}
}
} catch (Exception e) {
@@ -1987,6 +1999,27 @@ public class AiChatServiceImpl implements AiChatService {
return "/v3/chat";
}
/**
* 从content字段中提取output内容
*/
private String extractOutputFromContent(String content) {
try {
// 尝试解析content为JSON
JSONObject contentJson = JSON.parseObject(content);
if (contentJson.containsKey("output")) {
String output = contentJson.getString("output");
log.debug("成功提取output内容: {}", output);
return output;
} else {
log.debug("content中没有output字段,返回原始内容: {}", content);
return content;
}
} catch (Exception e) {
log.debug("content不是有效JSON,返回原始内容: {}, 错误: {}", content, e.getMessage());
return content;
}
}
/**
* 验证Coze请求参数
*/