| | |
| | | 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.siliconflow.SiliconFlowApiConstants; |
| | | import cn.iocoder.yudao.module.ai.framework.ai.core.model.siliconflow.SiliconFlowChatModel; |
| | | import org.junit.jupiter.api.Disabled; |
| | |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | |
| | | import static cn.iocoder.yudao.module.ai.util.AiUtils.validateApiKey; |
| | | |
| | | /** |
| | | * {@link SiliconFlowChatModel} 集成测试 |
| | |
| | | */ |
| | | public class SiliconFlowChatModelTests { |
| | | |
| | | private static final String API_KEY = SystemUtil.get("SILICONFLOW_API_KEY", |
| | | "sk-xxxx"); // 按需改成你的 SiliconFlow API Key |
| | | private static final String MODEL = SystemUtil.get("SILICONFLOW_MODEL", |
| | | SiliconFlowApiConstants.MODEL_DEFAULT); |
| | | |
| | | private final DeepSeekChatModel openAiChatModel = DeepSeekChatModel.builder() |
| | | .deepSeekApi(DeepSeekApi.builder() |
| | | .baseUrl(SiliconFlowApiConstants.DEFAULT_BASE_URL) |
| | | .apiKey("sk-epsakfenqnyzoxhmbucsxlhkdqlcbnimslqoivkshalvdozz") // apiKey |
| | | .apiKey(API_KEY) |
| | | .build()) |
| | | .defaultOptions(DeepSeekChatOptions.builder() |
| | | .model(SiliconFlowApiConstants.MODEL_DEFAULT) // 模型 |
| | | // .model("deepseek-ai/DeepSeek-R1") // 模型(deepseek-ai/DeepSeek-R1)可用赠费 |
| | | // .model("Pro/deepseek-ai/DeepSeek-R1") // 模型(Pro/deepseek-ai/DeepSeek-R1)需要付费 |
| | | .options(DeepSeekChatOptions.builder() |
| | | .model(MODEL) // 模型 |
| | | // .model("deepseek-ai/DeepSeek-V4-Flash") // 模型 |
| | | // .model("moonshotai/Kimi-K2.7-Code") // 模型 |
| | | // .model("moonshotai/Kimi-K2.6") // 模型 |
| | | // .model("zai-org/GLM-5.2") // 模型 |
| | | .temperature(0.7) |
| | | .build()) |
| | | .build(); |
| | |
| | | @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("deepseek-ai/DeepSeek-R1") |
| | | .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(); |
| | | } |
| | | |