From 24681c81c09022f584a57006f2534b5f74723414 Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期二, 30 六月 2026 09:27:31 +0800
Subject: [PATCH] 初始化项目
---
yudao-module-ai/src/test/java/cn/iocoder/yudao/module/ai/framework/ai/core/model/chat/ZhiPuAiChatModelTests.java | 45 ++++++++++++++++++++++++++++++---------------
1 files changed, 30 insertions(+), 15 deletions(-)
diff --git a/yudao-module-ai/src/test/java/cn/iocoder/yudao/module/ai/framework/ai/core/model/chat/ZhiPuAiChatModelTests.java b/yudao-module-ai/src/test/java/cn/iocoder/yudao/module/ai/framework/ai/core/model/chat/ZhiPuAiChatModelTests.java
index 18c3179..1abaa43 100644
--- a/yudao-module-ai/src/test/java/cn/iocoder/yudao/module/ai/framework/ai/core/model/chat/ZhiPuAiChatModelTests.java
+++ b/yudao-module-ai/src/test/java/cn/iocoder/yudao/module/ai/framework/ai/core/model/chat/ZhiPuAiChatModelTests.java
@@ -1,5 +1,7 @@
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.zhipu.ZhiPuChatModel;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.ai.chat.messages.Message;
@@ -7,31 +9,43 @@
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.zhipuai.ZhiPuAiChatModel;
-import org.springframework.ai.zhipuai.ZhiPuAiChatOptions;
-import org.springframework.ai.zhipuai.api.ZhiPuAiApi;
+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 ZhiPuAiChatModel} 鐨勯泦鎴愭祴璇�
+ * {@link ZhiPuChatModel} 鐨勯泦鎴愭祴璇�
*
* @author 鑺嬮亾婧愮爜
*/
public class ZhiPuAiChatModelTests {
- private final ZhiPuAiChatModel chatModel = new ZhiPuAiChatModel(
- ZhiPuAiApi.builder().apiKey("2f35fb6ca4ea41fab898729b7fac086c.6ESSfPcCkxaKEUlR").build(), // 瀵嗛挜
- ZhiPuAiChatOptions.builder()
- .model(ZhiPuAiApi.ChatModel.GLM_4.getName()) // 妯″瀷
+ private static final String API_KEY = SystemUtil.get("ZHIPU_API_KEY",
+ "sk-xxxx"); // 鎸夐渶鏀规垚浣犵殑鏅鸿氨 API Key
+ private static final String MODEL = SystemUtil.get("ZHIPU_MODEL",
+ ZhiPuChatModel.MODEL_DEFAULT);
+
+ private final ZhiPuChatModel chatModel = new ZhiPuChatModel(DeepSeekChatModel.builder()
+ .deepSeekApi(DeepSeekApi.builder()
+ .baseUrl(ZhiPuChatModel.BASE_URL)
+ .apiKey(API_KEY)
+ .build())
+ .options(DeepSeekChatOptions.builder()
+ .model(MODEL)
.build()
- );
+ ).build());
@Test
@Disabled
public void testCall() {
+ validateApiKey(API_KEY);
// 鍑嗗鍙傛暟
List<Message> messages = new ArrayList<>();
messages.add(new SystemMessage("浣犳槸涓�涓紭璐ㄧ殑鏂囪█鏂囦綔鑰咃紝鐢ㄦ枃瑷�鏂囨弿杩扮潃鍚勫煄甯傜殑浜烘枃椋庢櫙銆�"));
@@ -41,12 +55,13 @@
ChatResponse response = chatModel.call(new Prompt(messages));
// 鎵撳嵃缁撴灉
System.out.println(response);
- System.out.println(response.getResult().getOutput());
+ 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("浣犳槸涓�涓紭璐ㄧ殑鏂囪█鏂囦綔鑰咃紝鐢ㄦ枃瑷�鏂囨弿杩扮潃鍚勫煄甯傜殑浜烘枃椋庢櫙銆�"));
@@ -57,19 +72,19 @@
// 鎵撳嵃缁撴灉
flux.doOnNext(response -> {
// System.out.println(response);
- System.out.println(response.getResult().getOutput());
+ System.out.println(Objects.requireNonNull(response.getResult()).getOutput());
}).then().block();
}
- // TODO @鑺嬭壙锛氭殏鏃舵病瑙f瀽 reasoning_content 缁撴灉锛岄渶瑕佺瓑瀹樻柟淇
@Test
@Disabled
public void testStream_thinking() {
+ validateApiKey(API_KEY);
// 鍑嗗鍙傛暟
List<Message> messages = new ArrayList<>();
messages.add(new UserMessage("璇︾粏鍒嗘瀽涓嬶紝濡備綍璁捐涓�涓數鍟嗙郴缁燂紵"));
- ZhiPuAiChatOptions options = ZhiPuAiChatOptions.builder()
- .model("GLM-4.5")
+ DeepSeekChatOptions options = DeepSeekChatOptions.builder()
+ .model(MODEL)
.build();
// 璋冪敤
@@ -77,7 +92,7 @@
// 鎵撳嵃缁撴灉
flux.doOnNext(response -> {
// System.out.println(response);
- System.out.println(response.getResult().getOutput());
+ System.out.println(Objects.requireNonNull(response.getResult()).getOutput());
}).then().block();
}
--
Gitblit v1.9.3