| | |
| | | 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.doubao.DouBaoChatModel; |
| | | import org.junit.jupiter.api.Disabled; |
| | | import org.junit.jupiter.api.Test; |
| | |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | |
| | | import static cn.iocoder.yudao.module.ai.util.AiUtils.validateApiKey; |
| | | |
| | | /** |
| | | * {@link DouBaoChatModel} 集成测试 |
| | |
| | | */ |
| | | public class DouBaoChatModelTests { |
| | | |
| | | /** |
| | | * 相比 OpenAIChatModel 来说,DeepSeekChatModel 可以兼容豆包的 thinking 能力! |
| | | */ |
| | | private static final String API_KEY = SystemUtil.get("DOUBAO_API_KEY", |
| | | "sk-xxxx"); // 按需改成你的豆包 API Key |
| | | private static final String MODEL = SystemUtil.get("DOUBAO_MODEL", |
| | | DouBaoChatModel.MODEL_DEFAULT); |
| | | |
| | | private final DeepSeekChatModel openAiChatModel = DeepSeekChatModel.builder() |
| | | .deepSeekApi(DeepSeekApi.builder() |
| | | .baseUrl(DouBaoChatModel.BASE_URL) |
| | | .completionsPath(DouBaoChatModel.COMPLETE_PATH) |
| | | .apiKey("5c1b5747-26d2-4ebd-a4e0-dd0e8d8b4272") // apiKey |
| | | .apiKey(API_KEY) |
| | | .build()) |
| | | .defaultOptions(DeepSeekChatOptions.builder() |
| | | .model("doubao-1-5-lite-32k-250115") // 模型(doubao) |
| | | // .model("doubao-seed-1-6-thinking-250715") // 模型(doubao) |
| | | // .model("deepseek-r1-250120") // 模型(deepseek) |
| | | .options(DeepSeekChatOptions.builder() |
| | | .model(MODEL) |
| | | .temperature(0.7) |
| | | .build()) |
| | | .build(); |
| | |
| | | @Test |
| | | @Disabled |
| | | public void testCall() { |
| | | validateApiKey(API_KEY); |
| | | // 准备参数 |
| | | List<Message> messages = new ArrayList<>(); |
| | | messages.add(new SystemMessage("你是一个优质的文言文作者,用文言文描述着各城市的人文风景。")); |
| | |
| | | ChatResponse response = chatModel.call(new Prompt(messages)); |
| | | // 打印结果 |
| | | System.out.println(response); |
| | | System.out.println(Objects.requireNonNull(response.getResult()).getOutput()); |
| | | } |
| | | |
| | | @Test |
| | | @Disabled |
| | | public void testStream() { |
| | | validateApiKey(API_KEY); |
| | | // 准备参数 |
| | | List<Message> messages = new ArrayList<>(); |
| | | messages.add(new SystemMessage("你是一个优质的文言文作者,用文言文描述着各城市的人文风景。")); |
| | |
| | | // 调用 |
| | | Flux<ChatResponse> flux = chatModel.stream(new Prompt(messages)); |
| | | // 打印结果 |
| | | flux.doOnNext(System.out::println).then().block(); |
| | | flux.doOnNext(response -> { |
| | | // System.out.println(response); |
| | | System.out.println(Objects.requireNonNull(response.getResult()).getOutput()); |
| | | }).then().block(); |
| | | } |
| | | |
| | | @Test |
| | | @Disabled |
| | | public void testStream_thinking() { |
| | | validateApiKey(API_KEY); |
| | | // 准备参数 |
| | | List<Message> messages = new ArrayList<>(); |
| | | messages.add(new UserMessage("详细分析下,如何设计一个电商系统?")); |
| | | DeepSeekChatOptions options = DeepSeekChatOptions.builder() |
| | | .model("doubao-seed-1-6-thinking-250715") |
| | | .build(); |
| | | |
| | | // 调用 |
| | | Flux<ChatResponse> flux = chatModel.stream(new Prompt(messages, options)); |
| | | Flux<ChatResponse> flux = chatModel.stream(new Prompt(messages)); |
| | | // 打印结果 |
| | | flux.doOnNext(response -> { |
| | | // System.out.println(response); |
| | | System.out.println(response.getResult().getOutput()); |
| | | System.out.println(Objects.requireNonNull(response.getResult()).getOutput()); |
| | | }).then().block(); |
| | | } |
| | | |