From 8b2dcaf910d94c936f1f1db899e8b8e14f141131 Mon Sep 17 00:00:00 2001 From: cherishsince Date: Sat, 27 Apr 2024 16:59:15 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BC=98=E5=8C=96=E3=80=91=E8=AE=AF?= =?UTF-8?q?=E9=A3=9E=E6=98=9F=E7=81=AB=E5=85=BC=E5=AE=B9=20system=E3=80=81?= =?UTF-8?q?assistant=E3=80=81user?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ai/chatxinghuo/XingHuoChatClient.java | 11 +++++++---- .../ai/chat/XingHuoChatClientTests.java | 17 +++++++++++++++-- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/chatxinghuo/XingHuoChatClient.java b/yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/chatxinghuo/XingHuoChatClient.java index 849a70d75c..c257203b10 100644 --- a/yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/chatxinghuo/XingHuoChatClient.java +++ b/yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/chatxinghuo/XingHuoChatClient.java @@ -117,12 +117,15 @@ public class XingHuoChatClient implements ChatClient, StreamingChatClient { chatParameter.setDomain(xingHuoOptions.getChatModel().getValue()); XingHuoChatCompletionRequest.Parameter parameter = new XingHuoChatCompletionRequest.Parameter().setChat(chatParameter); // 创建 payload text 信息 - XingHuoChatCompletionRequest.Payload.Message.Text text = new XingHuoChatCompletionRequest.Payload.Message.Text(); - text.setRole(XingHuoChatCompletionRequest.Payload.Message.Text.Role.USER.getName()); - text.setContent(prompt.getContents()); + List texts = prompt.getInstructions().stream().map(message -> { + XingHuoChatCompletionRequest.Payload.Message.Text text = new XingHuoChatCompletionRequest.Payload.Message.Text(); + text.setContent(message.getContent()); + text.setRole(message.getMessageType().getValue()); + return text; + }).collect(Collectors.toList()); // 创建 payload XingHuoChatCompletionRequest.Payload payload = new XingHuoChatCompletionRequest.Payload() - .setMessage(new XingHuoChatCompletionRequest.Payload.Message().setText(List.of(text))); + .setMessage(new XingHuoChatCompletionRequest.Payload.Message().setText(texts)); // 创建 request return new XingHuoChatCompletionRequest() .setHeader(header) diff --git a/yudao-module-ai/yudao-spring-boot-starter-ai/src/test/java/cn/iocoder/yudao/framework/ai/chat/XingHuoChatClientTests.java b/yudao-module-ai/yudao-spring-boot-starter-ai/src/test/java/cn/iocoder/yudao/framework/ai/chat/XingHuoChatClientTests.java index 2340ad9a36..ee32b67179 100644 --- a/yudao-module-ai/yudao-spring-boot-starter-ai/src/test/java/cn/iocoder/yudao/framework/ai/chat/XingHuoChatClientTests.java +++ b/yudao-module-ai/yudao-spring-boot-starter-ai/src/test/java/cn/iocoder/yudao/framework/ai/chat/XingHuoChatClientTests.java @@ -1,5 +1,8 @@ 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.chatxinghuo.XingHuoChatClient; import cn.iocoder.yudao.framework.ai.chatxinghuo.XingHuoChatModel; @@ -9,6 +12,8 @@ import org.junit.Before; import org.junit.Test; import reactor.core.publisher.Flux; +import java.util.ArrayList; +import java.util.List; import java.util.Scanner; import java.util.function.Consumer; @@ -37,13 +42,21 @@ public class XingHuoChatClientTests { @Test public void callTest() { - ChatResponse call = xingHuoChatClient.call(new Prompt("java和go那个性能更好!")); + List messages = new ArrayList<>(); + messages.add(new SystemMessage("你是一个优质的文言文作者,用文言文描述着各城市的人文风景。")); + messages.add(new UserMessage("长沙怎么样?")); + + ChatResponse call = xingHuoChatClient.call(new Prompt(messages)); System.err.println(call.getResult()); } @Test public void streamTest() { - Flux stream = xingHuoChatClient.stream(new Prompt("java和go那个性能更好!")); + List messages = new ArrayList<>(); + messages.add(new SystemMessage("你是一个优质的文言文作者,用文言文描述着各城市的人文风景。")); + messages.add(new UserMessage("长沙怎么样?")); + + Flux stream = xingHuoChatClient.stream(new Prompt(messages)); stream.subscribe(new Consumer() { @Override public void accept(ChatResponse chatResponse) {