| | |
| | | package cn.iocoder.yudao.module.ai.framework.ai.core.model.chat; |
| | | |
| | | import cn.hutool.system.SystemUtil; |
| | | import cn.iocoder.yudao.module.ai.framework.ai.core.model.xinghuo.XingHuoChatModel; |
| | | import org.junit.jupiter.api.Disabled; |
| | | import org.junit.jupiter.api.Test; |
| | |
| | | import org.springframework.ai.chat.messages.UserMessage; |
| | | import org.springframework.ai.chat.model.ChatResponse; |
| | | import org.springframework.ai.chat.prompt.Prompt; |
| | | import org.springframework.ai.deepseek.DeepSeekChatModel; |
| | | import org.springframework.ai.deepseek.DeepSeekChatOptions; |
| | | import org.springframework.ai.deepseek.api.DeepSeekApi; |
| | | import reactor.core.publisher.Flux; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | |
| | | import static cn.iocoder.yudao.module.ai.util.AiUtils.validateApiKey; |
| | | |
| | | /** |
| | | * {@link XingHuoChatModel} 集成测试 |
| | |
| | | */ |
| | | public class XingHuoChatModelTests { |
| | | |
| | | private final DeepSeekChatModel openAiChatModel = DeepSeekChatModel.builder() |
| | | .deepSeekApi(DeepSeekApi.builder() |
| | | .baseUrl(XingHuoChatModel.BASE_URL_V2) |
| | | .completionsPath(XingHuoChatModel.BASE_COMPLETIONS_PATH_V2) |
| | | .apiKey("75b161ed2aef4719b275d6e7f2a4d4cd:YWYxYWI2MTA4ODI2NGZlYTQyNjAzZTcz") // appKey:secretKey |
| | | .build()) |
| | | .defaultOptions(DeepSeekChatOptions.builder() |
| | | // .model("generalv3.5") // 模型 |
| | | .model("x1") // 模型 |
| | | private static final String API_KEY = SystemUtil.get("XINGHUO_API_KEY", |
| | | "sk-xxxx"); // 按需改成你的讯飞星火 API Key |
| | | private static final String MODEL = SystemUtil.get("XINGHUO_MODEL", |
| | | XingHuoChatModel.MODEL_DEFAULT); |
| | | |
| | | private final XingHuoChatModel chatModel = XingHuoChatModel.builder() |
| | | .apiKey(API_KEY) |
| | | .options(DeepSeekChatOptions.builder() |
| | | .model(MODEL) |
| | | .temperature(0.7) |
| | | .build()) |
| | | .build(); |
| | | |
| | | private final XingHuoChatModel chatModel = new XingHuoChatModel(openAiChatModel); |
| | | |
| | | @Test |
| | | @Disabled |
| | | public void testCall() { |
| | | validateApiKey(API_KEY); |
| | | // 准备参数 |
| | | List<Message> messages = new ArrayList<>(); |
| | | messages.add(new SystemMessage("你是一个优质的文言文作者,用文言文描述着各城市的人文风景。")); |
| | |
| | | @Test |
| | | @Disabled |
| | | public void testStream() { |
| | | validateApiKey(API_KEY); |
| | | // 准备参数 |
| | | List<Message> messages = new ArrayList<>(); |
| | | messages.add(new SystemMessage("你是一个优质的文言文作者,用文言文描述着各城市的人文风景。")); |
| | |
| | | @Test |
| | | @Disabled |
| | | public void testStream_thinking() { |
| | | validateApiKey(API_KEY); |
| | | // 准备参数 |
| | | List<Message> messages = new ArrayList<>(); |
| | | messages.add(new UserMessage("详细分析下,如何设计一个电商系统?")); |
| | | DeepSeekChatOptions options = DeepSeekChatOptions.builder() |
| | | .model("x1") |
| | | .model(MODEL) |
| | | .build(); |
| | | |
| | | // 调用 |
| | |
| | | // 打印结果 |
| | | flux.doOnNext(response -> { |
| | | // System.out.println(response); |
| | | System.out.println(response.getResult().getOutput()); |
| | | System.out.println(Objects.requireNonNull(response.getResult()).getOutput()); |
| | | }).then().block(); |
| | | } |
| | | |