【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 -> {
// 调用 callWithFunctionSupport 发送请求 return retryTemplate.execute(ctx -> {
Flux<YiYanChatCompletionResponse> response = this.yiYanApi.chatCompletionStream(request); // 调用 callWithFunctionSupport 发送请求
// TODO @fan下面的 doOnComplete 是不是可以删除哈 Flux<YiYanChatCompletionResponse> response = this.yiYanApi.chatCompletionStream(request);
response.doOnComplete(new Runnable() { return response.map(chunk -> {
@Override // System.err.println("---".concat(chunk.getResult()));
public void run() { // TODO @fanChatResponseMetadata chatResponseMetadata
String a = ";"; return new ChatResponse(List.of(new Generation(chunk.getResult())));
} });
});
return response.map(chunk -> {
// TODO @fanChatResponseMetadata chatResponseMetadata
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