feat: 不选择模型自动选择时走原始默认逻辑;

This commit is contained in:
likunlong
2025-08-19 18:00:20 +08:00
committed by Administrator
parent 4b37cfe97d
commit ccdbb20935

View File

@@ -126,26 +126,31 @@ public class SseServiceImpl implements ISseService {
// 自动选择模型并获取对应的聊天服务 // 自动选择模型并获取对应的聊天服务
IChatService chatService = autoSelectModelAndGetService(chatRequest); IChatService chatService = autoSelectModelAndGetService(chatRequest);
// 统一重试与降级封装启动逻辑并通过ThreadLocal传递失败回调 // 仅当 autoSelectModel = true 时,才启用重试与降级
ChatModelVo currentModel = this.chatModelVo; if (Boolean.TRUE.equals(chatRequest.getAutoSelectModel())) {
String currentCategory = currentModel.getCategory(); ChatModelVo currentModel = this.chatModelVo;
ChatRetryHelper.executeWithRetry( String currentCategory = currentModel.getCategory();
currentModel, ChatRetryHelper.executeWithRetry(
currentCategory, currentModel,
chatModelService, currentCategory,
sseEmitter, chatModelService,
(modelForTry, onFailure) -> { sseEmitter,
// 替换请求中的模型名称 (modelForTry, onFailure) -> {
chatRequest.setModel(modelForTry.getModelName()); // 替换请求中的模型名称
// 以 emitter 实例为唯一键注册失败回调 chatRequest.setModel(modelForTry.getModelName());
RetryNotifier.setFailureCallback(sseEmitter, onFailure); // 以 emitter 实例为唯一键注册失败回调
try { RetryNotifier.setFailureCallback(sseEmitter, onFailure);
autoSelectServiceByCategoryAndInvoke(chatRequest, sseEmitter, modelForTry.getCategory()); try {
} finally { autoSelectServiceByCategoryAndInvoke(chatRequest, sseEmitter, modelForTry.getCategory());
// 不在此处清理,待下游结束/失败时清理 } finally {
// 不在此处清理,待下游结束/失败时清理
}
} }
} );
); } else {
// 不重试不降级,直接调用
chatService.chat(chatRequest, sseEmitter);
}
} catch (Exception e) { } catch (Exception e) {
log.error(e.getMessage(),e); log.error(e.getMessage(),e);
SSEUtil.sendErrorEvent(sseEmitter,e.getMessage()); SSEUtil.sendErrorEvent(sseEmitter,e.getMessage());