mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2025-01-31 17:40:05 +08:00
【解决todo】排查文心一言,集成到 chat flux 返回 null 终端问题(优化部分代码,未解决问题)
This commit is contained in:
parent
dcab49bb78
commit
39ecc7a037
@ -3,8 +3,8 @@ package cn.iocoder.yudao.framework.ai.core.model.yiyan;
|
|||||||
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
import cn.iocoder.yudao.framework.ai.core.exception.ChatException;
|
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.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.YiYanChatCompletionRequest;
|
||||||
|
import cn.iocoder.yudao.framework.ai.core.model.yiyan.api.YiYanChatCompletionResponse;
|
||||||
import cn.iocoder.yudao.framework.ai.core.model.yiyan.exception.YiYanApiException;
|
import cn.iocoder.yudao.framework.ai.core.model.yiyan.exception.YiYanApiException;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.ai.chat.ChatClient;
|
import org.springframework.ai.chat.ChatClient;
|
||||||
@ -76,21 +76,23 @@ public class YiYanChatClient implements ChatClient, StreamingChatClient {
|
|||||||
ResponseEntity<YiYanChatCompletionResponse> response = yiYanApi.chatCompletionEntity(request);
|
ResponseEntity<YiYanChatCompletionResponse> response = yiYanApi.chatCompletionEntity(request);
|
||||||
// 获取结果封装 ChatResponse
|
// 获取结果封装 ChatResponse
|
||||||
YiYanChatCompletionResponse chatCompletion = response.getBody();
|
YiYanChatCompletionResponse chatCompletion = response.getBody();
|
||||||
// TODO @fan:为空时,参考 OpenAiChatClient 的封装;
|
if (chatCompletion == null) {
|
||||||
// TODO @fan:chatResponseMetadata,参考 OpenAiChatResponseMetadata.from(completionEntity.getBody())
|
log.warn("No chat completion returned for prompt: {}", prompt);
|
||||||
return new ChatResponse(List.of(new Generation(chatCompletion.getResult())));
|
return new ChatResponse(List.of());
|
||||||
|
} else {
|
||||||
|
// TODO @fan:chatResponseMetadata,参考 OpenAiChatResponseMetadata.from(completionEntity.getBody())
|
||||||
|
return new ChatResponse(List.of(new Generation(chatCompletion.getResult())));
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@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 done @fan:return this.retryTemplate.execute(ctx -> {
|
return this.retryTemplate.execute(ctx -> {
|
||||||
return retryTemplate.execute(ctx -> {
|
|
||||||
// 调用 callWithFunctionSupport 发送请求
|
// 调用 callWithFunctionSupport 发送请求
|
||||||
Flux<YiYanChatCompletionResponse> response = this.yiYanApi.chatCompletionStream(request);
|
Flux<YiYanChatCompletionResponse> response = this.yiYanApi.chatCompletionStream(request);
|
||||||
return response.map(chunk -> {
|
return response.map(chunk -> {
|
||||||
// System.err.println("---".concat(chunk.getResult()));
|
|
||||||
// TODO @fan:ChatResponseMetadata chatResponseMetadata
|
// TODO @fan:ChatResponseMetadata chatResponseMetadata
|
||||||
return new ChatResponse(List.of(new Generation(chunk.getResult())));
|
return new ChatResponse(List.of(new Generation(chunk.getResult())));
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user