2 Commits

Author SHA1 Message Date
ageerle
b1ff44df4b feat: sse对话样式优化 2025-04-29 11:44:47 +08:00
ageerle
dc6d00f0fc feat: 查询gpts无需登录 2025-04-29 11:00:34 +08:00
4 changed files with 6 additions and 8 deletions

View File

@@ -39,7 +39,6 @@ public class ChatGptsController extends BaseController {
/**
* 查询应用管理列表
*/
@SaCheckPermission("system:gpts:list")
@GetMapping("/list")
public TableDataInfo<ChatGptsVo> list(ChatGptsBo bo, PageQuery pageQuery) {
return chatGptsService.queryPageList(bo, pageQuery);

View File

@@ -12,6 +12,7 @@ import okhttp3.sse.EventSource;
import okhttp3.sse.EventSourceListener;
import org.jetbrains.annotations.NotNull;
import org.ruoyi.chat.service.chat.IChatCostService;
import org.ruoyi.chat.util.SSEUtil;
import org.ruoyi.common.chat.entity.chat.ChatCompletionResponse;
import org.ruoyi.common.chat.request.ChatRequest;
import org.ruoyi.common.core.utils.SpringUtils;
@@ -84,10 +85,10 @@ public class SSEEventSourceListener extends EventSourceListener {
modelName = completionResponse.getModel();
}
stringBuffer.append(content);
emitter.send(content);
emitter.send(data);
}
} catch (Exception e) {
emitter.completeWithError(e);
log.error(e.getMessage(), e);
}
}

View File

@@ -11,6 +11,7 @@ import org.ruoyi.chat.enums.ChatModeType;
import org.ruoyi.chat.service.chat.IChatCostService;
import org.ruoyi.chat.service.chat.ISseService;
import org.ruoyi.chat.util.IpUtil;
import org.ruoyi.chat.util.SSEUtil;
import org.ruoyi.common.chat.config.LocalCache;
import org.ruoyi.common.chat.entity.Tts.TextToSpeech;
import org.ruoyi.common.chat.entity.chat.ChatCompletion;
@@ -88,7 +89,7 @@ public class SseServiceImpl implements ISseService {
switchModelAndHandle(chatRequest,sseEmitter);
} catch (Exception e) {
log.error(e.getMessage(),e);
sseEmitter.completeWithError(e);
SSEUtil.sendErrorEvent(sseEmitter,e.getMessage());
}
return sseEmitter;
}

View File

@@ -21,11 +21,8 @@ public class SSEUtil {
* @param errorMessage 错误信息
*/
public static void sendErrorEvent(ResponseBodyEmitter sseEmitter, String errorMessage) {
SseEmitter.SseEventBuilder event = SseEmitter.event()
.name("error")
.data(errorMessage);
try {
sseEmitter.send(event);
sseEmitter.send(errorMessage);
} catch (IOException e) {
log.error("SSE发送失败: {}", e.getMessage());
}