From 39ecc7a0373610d14c7b6f630256996b8680a1cb Mon Sep 17 00:00:00 2001 From: cherishsince Date: Thu, 27 Jun 2024 17:16:04 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E8=A7=A3=E5=86=B3todo=E3=80=91?= =?UTF-8?q?=E6=8E=92=E6=9F=A5=E6=96=87=E5=BF=83=E4=B8=80=E8=A8=80=EF=BC=8C?= =?UTF-8?q?=E9=9B=86=E6=88=90=E5=88=B0=20chat=20flux=20=E8=BF=94=E5=9B=9E?= =?UTF-8?q?=20null=20=E7=BB=88=E7=AB=AF=E9=97=AE=E9=A2=98(=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E9=83=A8=E5=88=86=E4=BB=A3=E7=A0=81=EF=BC=8C=E6=9C=AA?= =?UTF-8?q?=E8=A7=A3=E5=86=B3=E9=97=AE=E9=A2=98=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ai/core/model/yiyan/YiYanChatClient.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/core/model/yiyan/YiYanChatClient.java b/yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/core/model/yiyan/YiYanChatClient.java index 4a2fa7b3a..ab24f9584 100644 --- a/yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/core/model/yiyan/YiYanChatClient.java +++ b/yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/core/model/yiyan/YiYanChatClient.java @@ -3,8 +3,8 @@ package cn.iocoder.yudao.framework.ai.core.model.yiyan; import cn.hutool.core.bean.BeanUtil; import cn.iocoder.yudao.framework.ai.core.exception.ChatException; import cn.iocoder.yudao.framework.ai.core.model.yiyan.api.YiYanApi; -import cn.iocoder.yudao.framework.ai.core.model.yiyan.api.YiYanChatCompletionResponse; import cn.iocoder.yudao.framework.ai.core.model.yiyan.api.YiYanChatCompletionRequest; +import cn.iocoder.yudao.framework.ai.core.model.yiyan.api.YiYanChatCompletionResponse; import cn.iocoder.yudao.framework.ai.core.model.yiyan.exception.YiYanApiException; import lombok.extern.slf4j.Slf4j; import org.springframework.ai.chat.ChatClient; @@ -76,21 +76,23 @@ public class YiYanChatClient implements ChatClient, StreamingChatClient { ResponseEntity response = yiYanApi.chatCompletionEntity(request); // 获取结果封装 ChatResponse YiYanChatCompletionResponse chatCompletion = response.getBody(); - // TODO @fan:为空时,参考 OpenAiChatClient 的封装; - // TODO @fan:chatResponseMetadata,参考 OpenAiChatResponseMetadata.from(completionEntity.getBody()) - return new ChatResponse(List.of(new Generation(chatCompletion.getResult()))); + if (chatCompletion == null) { + log.warn("No chat completion returned for prompt: {}", prompt); + return new ChatResponse(List.of()); + } else { + // TODO @fan:chatResponseMetadata,参考 OpenAiChatResponseMetadata.from(completionEntity.getBody()) + return new ChatResponse(List.of(new Generation(chatCompletion.getResult()))); + } }); } @Override public Flux stream(Prompt prompt) { YiYanChatCompletionRequest request = this.createRequest(prompt, true); - // TODO done @fan:return this.retryTemplate.execute(ctx -> { - return retryTemplate.execute(ctx -> { + return this.retryTemplate.execute(ctx -> { // 调用 callWithFunctionSupport 发送请求 Flux response = this.yiYanApi.chatCompletionStream(request); return response.map(chunk -> { -// System.err.println("---".concat(chunk.getResult())); // TODO @fan:ChatResponseMetadata chatResponseMetadata return new ChatResponse(List.of(new Generation(chunk.getResult()))); });