Commit 8b2dcaf910d94c936f1f1db899e8b8e14f141131
1 parent
63c5f905
【优化】讯飞星火兼容 system、assistant、user
Showing
2 changed files
with
22 additions
and
6 deletions
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 { | @@ -117,12 +117,15 @@ public class XingHuoChatClient implements ChatClient, StreamingChatClient { | ||
| 117 | chatParameter.setDomain(xingHuoOptions.getChatModel().getValue()); | 117 | chatParameter.setDomain(xingHuoOptions.getChatModel().getValue()); |
| 118 | XingHuoChatCompletionRequest.Parameter parameter = new XingHuoChatCompletionRequest.Parameter().setChat(chatParameter); | 118 | XingHuoChatCompletionRequest.Parameter parameter = new XingHuoChatCompletionRequest.Parameter().setChat(chatParameter); |
| 119 | // 创建 payload text 信息 | 119 | // 创建 payload text 信息 |
| 120 | - XingHuoChatCompletionRequest.Payload.Message.Text text = new XingHuoChatCompletionRequest.Payload.Message.Text(); | ||
| 121 | - text.setRole(XingHuoChatCompletionRequest.Payload.Message.Text.Role.USER.getName()); | ||
| 122 | - text.setContent(prompt.getContents()); | 120 | + List<XingHuoChatCompletionRequest.Payload.Message.Text> texts = prompt.getInstructions().stream().map(message -> { |
| 121 | + XingHuoChatCompletionRequest.Payload.Message.Text text = new XingHuoChatCompletionRequest.Payload.Message.Text(); | ||
| 122 | + text.setContent(message.getContent()); | ||
| 123 | + text.setRole(message.getMessageType().getValue()); | ||
| 124 | + return text; | ||
| 125 | + }).collect(Collectors.toList()); | ||
| 123 | // 创建 payload | 126 | // 创建 payload |
| 124 | XingHuoChatCompletionRequest.Payload payload = new XingHuoChatCompletionRequest.Payload() | 127 | XingHuoChatCompletionRequest.Payload payload = new XingHuoChatCompletionRequest.Payload() |
| 125 | - .setMessage(new XingHuoChatCompletionRequest.Payload.Message().setText(List.of(text))); | 128 | + .setMessage(new XingHuoChatCompletionRequest.Payload.Message().setText(texts)); |
| 126 | // 创建 request | 129 | // 创建 request |
| 127 | return new XingHuoChatCompletionRequest() | 130 | return new XingHuoChatCompletionRequest() |
| 128 | .setHeader(header) | 131 | .setHeader(header) |
yudao-module-ai/yudao-spring-boot-starter-ai/src/test/java/cn/iocoder/yudao/framework/ai/chat/XingHuoChatClientTests.java
| 1 | package cn.iocoder.yudao.framework.ai.chat; | 1 | package cn.iocoder.yudao.framework.ai.chat; |
| 2 | 2 | ||
| 3 | +import cn.iocoder.yudao.framework.ai.chat.messages.Message; | ||
| 4 | +import cn.iocoder.yudao.framework.ai.chat.messages.SystemMessage; | ||
| 5 | +import cn.iocoder.yudao.framework.ai.chat.messages.UserMessage; | ||
| 3 | import cn.iocoder.yudao.framework.ai.chat.prompt.Prompt; | 6 | import cn.iocoder.yudao.framework.ai.chat.prompt.Prompt; |
| 4 | import cn.iocoder.yudao.framework.ai.chatxinghuo.XingHuoChatClient; | 7 | import cn.iocoder.yudao.framework.ai.chatxinghuo.XingHuoChatClient; |
| 5 | import cn.iocoder.yudao.framework.ai.chatxinghuo.XingHuoChatModel; | 8 | import cn.iocoder.yudao.framework.ai.chatxinghuo.XingHuoChatModel; |
| @@ -9,6 +12,8 @@ import org.junit.Before; | @@ -9,6 +12,8 @@ import org.junit.Before; | ||
| 9 | import org.junit.Test; | 12 | import org.junit.Test; |
| 10 | import reactor.core.publisher.Flux; | 13 | import reactor.core.publisher.Flux; |
| 11 | 14 | ||
| 15 | +import java.util.ArrayList; | ||
| 16 | +import java.util.List; | ||
| 12 | import java.util.Scanner; | 17 | import java.util.Scanner; |
| 13 | import java.util.function.Consumer; | 18 | import java.util.function.Consumer; |
| 14 | 19 | ||
| @@ -37,13 +42,21 @@ public class XingHuoChatClientTests { | @@ -37,13 +42,21 @@ public class XingHuoChatClientTests { | ||
| 37 | 42 | ||
| 38 | @Test | 43 | @Test |
| 39 | public void callTest() { | 44 | public void callTest() { |
| 40 | - ChatResponse call = xingHuoChatClient.call(new Prompt("java和go那个性能更好!")); | 45 | + List<Message> messages = new ArrayList<>(); |
| 46 | + messages.add(new SystemMessage("你是一个优质的文言文作者,用文言文描述着各城市的人文风景。")); | ||
| 47 | + messages.add(new UserMessage("长沙怎么样?")); | ||
| 48 | + | ||
| 49 | + ChatResponse call = xingHuoChatClient.call(new Prompt(messages)); | ||
| 41 | System.err.println(call.getResult()); | 50 | System.err.println(call.getResult()); |
| 42 | } | 51 | } |
| 43 | 52 | ||
| 44 | @Test | 53 | @Test |
| 45 | public void streamTest() { | 54 | public void streamTest() { |
| 46 | - Flux<ChatResponse> stream = xingHuoChatClient.stream(new Prompt("java和go那个性能更好!")); | 55 | + List<Message> messages = new ArrayList<>(); |
| 56 | + messages.add(new SystemMessage("你是一个优质的文言文作者,用文言文描述着各城市的人文风景。")); | ||
| 57 | + messages.add(new UserMessage("长沙怎么样?")); | ||
| 58 | + | ||
| 59 | + Flux<ChatResponse> stream = xingHuoChatClient.stream(new Prompt(messages)); | ||
| 47 | stream.subscribe(new Consumer<ChatResponse>() { | 60 | stream.subscribe(new Consumer<ChatResponse>() { |
| 48 | @Override | 61 | @Override |
| 49 | public void accept(ChatResponse chatResponse) { | 62 | public void accept(ChatResponse chatResponse) { |