mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2025-01-19 03:30:06 +08:00
【优化】讯飞星火兼容 system、assistant、user
This commit is contained in:
parent
63c5f90596
commit
8b2dcaf910
@ -117,12 +117,15 @@ public class XingHuoChatClient implements ChatClient, StreamingChatClient {
|
|||||||
chatParameter.setDomain(xingHuoOptions.getChatModel().getValue());
|
chatParameter.setDomain(xingHuoOptions.getChatModel().getValue());
|
||||||
XingHuoChatCompletionRequest.Parameter parameter = new XingHuoChatCompletionRequest.Parameter().setChat(chatParameter);
|
XingHuoChatCompletionRequest.Parameter parameter = new XingHuoChatCompletionRequest.Parameter().setChat(chatParameter);
|
||||||
// 创建 payload text 信息
|
// 创建 payload text 信息
|
||||||
XingHuoChatCompletionRequest.Payload.Message.Text text = new XingHuoChatCompletionRequest.Payload.Message.Text();
|
List<XingHuoChatCompletionRequest.Payload.Message.Text> texts = prompt.getInstructions().stream().map(message -> {
|
||||||
text.setRole(XingHuoChatCompletionRequest.Payload.Message.Text.Role.USER.getName());
|
XingHuoChatCompletionRequest.Payload.Message.Text text = new XingHuoChatCompletionRequest.Payload.Message.Text();
|
||||||
text.setContent(prompt.getContents());
|
text.setContent(message.getContent());
|
||||||
|
text.setRole(message.getMessageType().getValue());
|
||||||
|
return text;
|
||||||
|
}).collect(Collectors.toList());
|
||||||
// 创建 payload
|
// 创建 payload
|
||||||
XingHuoChatCompletionRequest.Payload payload = new XingHuoChatCompletionRequest.Payload()
|
XingHuoChatCompletionRequest.Payload payload = new XingHuoChatCompletionRequest.Payload()
|
||||||
.setMessage(new XingHuoChatCompletionRequest.Payload.Message().setText(List.of(text)));
|
.setMessage(new XingHuoChatCompletionRequest.Payload.Message().setText(texts));
|
||||||
// 创建 request
|
// 创建 request
|
||||||
return new XingHuoChatCompletionRequest()
|
return new XingHuoChatCompletionRequest()
|
||||||
.setHeader(header)
|
.setHeader(header)
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
package cn.iocoder.yudao.framework.ai.chat;
|
package cn.iocoder.yudao.framework.ai.chat;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.framework.ai.chat.messages.Message;
|
||||||
|
import cn.iocoder.yudao.framework.ai.chat.messages.SystemMessage;
|
||||||
|
import cn.iocoder.yudao.framework.ai.chat.messages.UserMessage;
|
||||||
import cn.iocoder.yudao.framework.ai.chat.prompt.Prompt;
|
import cn.iocoder.yudao.framework.ai.chat.prompt.Prompt;
|
||||||
import cn.iocoder.yudao.framework.ai.chatxinghuo.XingHuoChatClient;
|
import cn.iocoder.yudao.framework.ai.chatxinghuo.XingHuoChatClient;
|
||||||
import cn.iocoder.yudao.framework.ai.chatxinghuo.XingHuoChatModel;
|
import cn.iocoder.yudao.framework.ai.chatxinghuo.XingHuoChatModel;
|
||||||
@ -9,6 +12,8 @@ import org.junit.Before;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import reactor.core.publisher.Flux;
|
import reactor.core.publisher.Flux;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
@ -37,13 +42,21 @@ public class XingHuoChatClientTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void callTest() {
|
public void callTest() {
|
||||||
ChatResponse call = xingHuoChatClient.call(new Prompt("java和go那个性能更好!"));
|
List<Message> messages = new ArrayList<>();
|
||||||
|
messages.add(new SystemMessage("你是一个优质的文言文作者,用文言文描述着各城市的人文风景。"));
|
||||||
|
messages.add(new UserMessage("长沙怎么样?"));
|
||||||
|
|
||||||
|
ChatResponse call = xingHuoChatClient.call(new Prompt(messages));
|
||||||
System.err.println(call.getResult());
|
System.err.println(call.getResult());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void streamTest() {
|
public void streamTest() {
|
||||||
Flux<ChatResponse> stream = xingHuoChatClient.stream(new Prompt("java和go那个性能更好!"));
|
List<Message> messages = new ArrayList<>();
|
||||||
|
messages.add(new SystemMessage("你是一个优质的文言文作者,用文言文描述着各城市的人文风景。"));
|
||||||
|
messages.add(new UserMessage("长沙怎么样?"));
|
||||||
|
|
||||||
|
Flux<ChatResponse> stream = xingHuoChatClient.stream(new Prompt(messages));
|
||||||
stream.subscribe(new Consumer<ChatResponse>() {
|
stream.subscribe(new Consumer<ChatResponse>() {
|
||||||
@Override
|
@Override
|
||||||
public void accept(ChatResponse chatResponse) {
|
public void accept(ChatResponse chatResponse) {
|
||||||
|
Loading…
Reference in New Issue
Block a user