Commit 3a10fedddb66851242e0d7e018fbe0e1d0b8ae43
1 parent
e0d8ac74
【todo】百度文言一心,解决 todo,删除 doOnComplete、增加 retryTemplate
Showing
1 changed file
with
11 additions
and
13 deletions
yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/core/model/yiyan/YiYanChatClient.java
| ... | ... | @@ -85,22 +85,20 @@ public class YiYanChatClient implements ChatClient, StreamingChatClient { |
| 85 | 85 | @Override |
| 86 | 86 | public Flux<ChatResponse> stream(Prompt prompt) { |
| 87 | 87 | YiYanChatCompletionRequest request = this.createRequest(prompt, true); |
| 88 | - // TODO @fan:return this.retryTemplate.execute(ctx -> { | |
| 89 | - // 调用 callWithFunctionSupport 发送请求 | |
| 90 | - Flux<YiYanChatCompletionResponse> response = this.yiYanApi.chatCompletionStream(request); | |
| 91 | - // TODO @fan:下面的 doOnComplete 是不是可以删除哈? | |
| 92 | - response.doOnComplete(new Runnable() { | |
| 93 | - @Override | |
| 94 | - public void run() { | |
| 95 | - String a = ";"; | |
| 96 | - } | |
| 97 | - }); | |
| 98 | - return response.map(chunk -> { | |
| 99 | - // TODO @fan:ChatResponseMetadata chatResponseMetadata | |
| 100 | - return new ChatResponse(List.of(new Generation(chunk.getResult()))); | |
| 88 | + // TODO done @fan:return this.retryTemplate.execute(ctx -> { | |
| 89 | + return retryTemplate.execute(ctx -> { | |
| 90 | + // 调用 callWithFunctionSupport 发送请求 | |
| 91 | + Flux<YiYanChatCompletionResponse> response = this.yiYanApi.chatCompletionStream(request); | |
| 92 | + return response.map(chunk -> { | |
| 93 | +// System.err.println("---".concat(chunk.getResult())); | |
| 94 | + // TODO @fan:ChatResponseMetadata chatResponseMetadata | |
| 95 | + return new ChatResponse(List.of(new Generation(chunk.getResult()))); | |
| 96 | + }); | |
| 101 | 97 | }); |
| 102 | 98 | } |
| 103 | 99 | |
| 100 | + | |
| 101 | + | |
| 104 | 102 | private YiYanChatCompletionRequest createRequest(Prompt prompt, boolean stream) { |
| 105 | 103 | // 参考 https://cloud.baidu.com/doc/WENXINWORKSHOP/s/clntwmv7t 文档,system 是独立字段 |
| 106 | 104 | // 1.1 获取 user 和 assistant | ... | ... |