|
@@ -150,7 +150,15 @@ public class AiChatMessageServiceImpl implements AiChatMessageService {
|
|
|
|
|
|
|
|
// 3.2 创建 chat 需要的 Prompt
|
|
// 3.2 创建 chat 需要的 Prompt
|
|
|
Prompt prompt = buildPrompt(conversation, historyMessages, knowledgeSegments, model, sendReqVO);
|
|
Prompt prompt = buildPrompt(conversation, historyMessages, knowledgeSegments, model, sendReqVO);
|
|
|
- ChatResponse chatResponse = chatModel.call(prompt);
|
|
|
|
|
|
|
+ ChatResponse chatResponse;
|
|
|
|
|
+ try {
|
|
|
|
|
+ chatResponse = chatModel.call(prompt);
|
|
|
|
|
+ } catch (org.springframework.web.reactive.function.client.WebClientResponseException e) {
|
|
|
|
|
+ log.error("===== 火山方舟错误详情 =====");
|
|
|
|
|
+ log.error("状态码:{}", e.getStatusCode());
|
|
|
|
|
+ log.error("响应体:{}", e.getResponseBodyAsString());
|
|
|
|
|
+ throw new RuntimeException("调用失败:" + e.getResponseBodyAsString());
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
// 3.3 更新响应内容
|
|
// 3.3 更新响应内容
|
|
|
String newContent = chatResponse.getResult().getOutput().getText();
|
|
String newContent = chatResponse.getResult().getOutput().getText();
|
|
@@ -219,7 +227,15 @@ public class AiChatMessageServiceImpl implements AiChatMessageService {
|
|
|
Flux<ChatResponse> streamResponse = Flux.defer(() -> chatModel.stream(prompt))
|
|
Flux<ChatResponse> streamResponse = Flux.defer(() -> chatModel.stream(prompt))
|
|
|
.retryWhen(Retry.backoff(2, Duration.ofSeconds(1))
|
|
.retryWhen(Retry.backoff(2, Duration.ofSeconds(1))
|
|
|
.filter(throwable -> throwable instanceof WebClientRequestException
|
|
.filter(throwable -> throwable instanceof WebClientRequestException
|
|
|
- && throwable.getMessage().contains("Connection reset by peer")));
|
|
|
|
|
|
|
+ && throwable.getMessage().contains("Connection reset by peer")))
|
|
|
|
|
+ // 捕获400错误,打印服务端返回的详情
|
|
|
|
|
+ .onErrorResume(org.springframework.web.reactive.function.client.WebClientResponseException.class, e -> {
|
|
|
|
|
+ System.out.println("===== 火山方舟错误详情 =====");
|
|
|
|
|
+ System.out.println("状态码:" + e.getStatusCode());
|
|
|
|
|
+ System.out.println("响应体:" + e.getResponseBodyAsString());
|
|
|
|
|
+ // 关键!
|
|
|
|
|
+ return Flux.error(new RuntimeException("调用失败:" + e.getResponseBodyAsString()));
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
// Flux<ChatResponse> streamResponse = chatModel.stream(prompt);
|
|
// Flux<ChatResponse> streamResponse = chatModel.stream(prompt);
|
|
|
|
|
|