| | |
| | | package cn.iocoder.yudao.module.ai.framework.ai.core.model.chat; |
| | | |
| | | import cn.hutool.system.SystemUtil; |
| | | import org.junit.jupiter.api.Disabled; |
| | | import org.junit.jupiter.api.Test; |
| | | import org.springframework.ai.chat.messages.Message; |
| | |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | |
| | | import static cn.iocoder.yudao.module.ai.util.AiUtils.validateApiKey; |
| | | |
| | | /** |
| | | * {@link DeepSeekChatModel} 集成测试 |
| | |
| | | */ |
| | | public class DeepSeekChatModelTests { |
| | | |
| | | private static final String API_KEY = SystemUtil.get("DEEPSEEK_API_KEY", |
| | | "sk-xxxx"); |
| | | private static final String MODEL = SystemUtil.get("DEEPSEEK_MODEL", |
| | | "deepseek-v4-flash"); |
| | | |
| | | private final DeepSeekChatModel chatModel = DeepSeekChatModel.builder() |
| | | .deepSeekApi(DeepSeekApi.builder() |
| | | .apiKey("sk-eaf4172a057344dd9bc64b1f806b6axx") // apiKey |
| | | .apiKey(API_KEY) // apiKey |
| | | .build()) |
| | | .defaultOptions(DeepSeekChatOptions.builder() |
| | | .model("deepseek-chat") // 模型 |
| | | .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("你是一个优质的文言文作者,用文言文描述着各城市的人文风景。")); |
| | |
| | | @Test |
| | | @Disabled |
| | | public void testStream_thinking() { |
| | | validateApiKey(API_KEY); |
| | | // 准备参数 |
| | | List<Message> messages = new ArrayList<>(); |
| | | messages.add(new UserMessage("详细分析下,如何设计一个电商系统?")); |
| | | DeepSeekChatOptions options = DeepSeekChatOptions.builder() |
| | | .model("deepseek-reasoner") |
| | | .model(MODEL) |
| | | .build(); |
| | | |
| | | // 调用 |