【todo】百度文言一心,解决 todo,删除 doOnComplete、增加 retryTemplate

This commit is contained in:
cherishsince 2024-05-20 13:44:50 +08:00
parent e0d8ac74a4
commit 3a10fedddb

View File

@ -85,22 +85,20 @@ public class YiYanChatClient implements ChatClient, StreamingChatClient {
@Override @Override
public Flux<ChatResponse> stream(Prompt prompt) { public Flux<ChatResponse> stream(Prompt prompt) {
YiYanChatCompletionRequest request = this.createRequest(prompt, true); YiYanChatCompletionRequest request = this.createRequest(prompt, true);
// TODO @fanreturn this.retryTemplate.execute(ctx -> { // TODO done @fanreturn this.retryTemplate.execute(ctx -> {
return retryTemplate.execute(ctx -> {
// 调用 callWithFunctionSupport 发送请求 // 调用 callWithFunctionSupport 发送请求
Flux<YiYanChatCompletionResponse> response = this.yiYanApi.chatCompletionStream(request); Flux<YiYanChatCompletionResponse> response = this.yiYanApi.chatCompletionStream(request);
// TODO @fan下面的 doOnComplete 是不是可以删除哈
response.doOnComplete(new Runnable() {
@Override
public void run() {
String a = ";";
}
});
return response.map(chunk -> { return response.map(chunk -> {
// System.err.println("---".concat(chunk.getResult()));
// TODO @fanChatResponseMetadata chatResponseMetadata // TODO @fanChatResponseMetadata chatResponseMetadata
return new ChatResponse(List.of(new Generation(chunk.getResult()))); return new ChatResponse(List.of(new Generation(chunk.getResult())));
}); });
});
} }
private YiYanChatCompletionRequest createRequest(Prompt prompt, boolean stream) { private YiYanChatCompletionRequest createRequest(Prompt prompt, boolean stream) {
// 参考 https://cloud.baidu.com/doc/WENXINWORKSHOP/s/clntwmv7t 文档system 是独立字段 // 参考 https://cloud.baidu.com/doc/WENXINWORKSHOP/s/clntwmv7t 文档system 是独立字段
// 1.1 获取 user assistant // 1.1 获取 user assistant