Commit 39ecc7a0373610d14c7b6f630256996b8680a1cb
1 parent
dcab49bb
【解决todo】排查文心一言,集成到 chat flux 返回 null 终端问题(优化部分代码,未解决问题)
Showing
1 changed file
with
9 additions
and
7 deletions
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; |
| 3 | 3 | import cn.hutool.core.bean.BeanUtil; |
| 4 | 4 | import cn.iocoder.yudao.framework.ai.core.exception.ChatException; |
| 5 | 5 | import cn.iocoder.yudao.framework.ai.core.model.yiyan.api.YiYanApi; |
| 6 | -import cn.iocoder.yudao.framework.ai.core.model.yiyan.api.YiYanChatCompletionResponse; | |
| 7 | 6 | import cn.iocoder.yudao.framework.ai.core.model.yiyan.api.YiYanChatCompletionRequest; |
| 7 | +import cn.iocoder.yudao.framework.ai.core.model.yiyan.api.YiYanChatCompletionResponse; | |
| 8 | 8 | import cn.iocoder.yudao.framework.ai.core.model.yiyan.exception.YiYanApiException; |
| 9 | 9 | import lombok.extern.slf4j.Slf4j; |
| 10 | 10 | import org.springframework.ai.chat.ChatClient; |
| ... | ... | @@ -76,21 +76,23 @@ public class YiYanChatClient implements ChatClient, StreamingChatClient { |
| 76 | 76 | ResponseEntity<YiYanChatCompletionResponse> response = yiYanApi.chatCompletionEntity(request); |
| 77 | 77 | // 获取结果封装 ChatResponse |
| 78 | 78 | YiYanChatCompletionResponse chatCompletion = response.getBody(); |
| 79 | - // TODO @fan:为空时,参考 OpenAiChatClient 的封装; | |
| 80 | - // TODO @fan:chatResponseMetadata,参考 OpenAiChatResponseMetadata.from(completionEntity.getBody()) | |
| 81 | - return new ChatResponse(List.of(new Generation(chatCompletion.getResult()))); | |
| 79 | + if (chatCompletion == null) { | |
| 80 | + log.warn("No chat completion returned for prompt: {}", prompt); | |
| 81 | + return new ChatResponse(List.of()); | |
| 82 | + } else { | |
| 83 | + // TODO @fan:chatResponseMetadata,参考 OpenAiChatResponseMetadata.from(completionEntity.getBody()) | |
| 84 | + return new ChatResponse(List.of(new Generation(chatCompletion.getResult()))); | |
| 85 | + } | |
| 82 | 86 | }); |
| 83 | 87 | } |
| 84 | 88 | |
| 85 | 89 | @Override |
| 86 | 90 | public Flux<ChatResponse> stream(Prompt prompt) { |
| 87 | 91 | YiYanChatCompletionRequest request = this.createRequest(prompt, true); |
| 88 | - // TODO done @fan:return this.retryTemplate.execute(ctx -> { | |
| 89 | - return retryTemplate.execute(ctx -> { | |
| 92 | + return this.retryTemplate.execute(ctx -> { | |
| 90 | 93 | // 调用 callWithFunctionSupport 发送请求 |
| 91 | 94 | Flux<YiYanChatCompletionResponse> response = this.yiYanApi.chatCompletionStream(request); |
| 92 | 95 | return response.map(chunk -> { |
| 93 | -// System.err.println("---".concat(chunk.getResult())); | |
| 94 | 96 | // TODO @fan:ChatResponseMetadata chatResponseMetadata |
| 95 | 97 | return new ChatResponse(List.of(new Generation(chunk.getResult()))); |
| 96 | 98 | }); | ... | ... |