Commit 3b7b81829d4d31d6387068eb48fe01123a94245b
1 parent
f582c9cf
【代码重构】AI:使用 alibaba ai 替代 tongyi 的实现
Showing
2 changed files
with
18 additions
and
32 deletions
yudao-module-ai/yudao-spring-boot-starter-ai/src/test/java/cn/iocoder/yudao/framework/ai/chat/TongYiChatModelTests.java
| 1 | package cn.iocoder.yudao.framework.ai.chat; | 1 | package cn.iocoder.yudao.framework.ai.chat; |
| 2 | 2 | ||
| 3 | -import cn.hutool.core.util.ReflectUtil; | ||
| 4 | -import com.alibaba.cloud.ai.tongyi.chat.TongYiChatModel; | ||
| 5 | -import com.alibaba.cloud.ai.tongyi.chat.TongYiChatOptions; | ||
| 6 | -import com.alibaba.dashscope.aigc.generation.Generation; | ||
| 7 | -import com.alibaba.dashscope.common.MessageManager; | ||
| 8 | -import com.alibaba.dashscope.utils.Constants; | ||
| 9 | -import org.junit.jupiter.api.BeforeEach; | 3 | +import com.alibaba.cloud.ai.dashscope.api.DashScopeApi; |
| 4 | +import com.alibaba.cloud.ai.dashscope.chat.DashScopeChatModel; | ||
| 5 | +import com.alibaba.cloud.ai.dashscope.chat.DashScopeChatOptions; | ||
| 10 | import org.junit.jupiter.api.Disabled; | 6 | import org.junit.jupiter.api.Disabled; |
| 11 | import org.junit.jupiter.api.Test; | 7 | import org.junit.jupiter.api.Test; |
| 12 | import org.springframework.ai.chat.messages.Message; | 8 | import org.springframework.ai.chat.messages.Message; |
| @@ -20,25 +16,15 @@ import java.util.ArrayList; | @@ -20,25 +16,15 @@ import java.util.ArrayList; | ||
| 20 | import java.util.List; | 16 | import java.util.List; |
| 21 | 17 | ||
| 22 | /** | 18 | /** |
| 23 | - * {@link TongYiChatModel} 集成测试类 | 19 | + * {@link DashScopeChatModel} 集成测试类 |
| 24 | * | 20 | * |
| 25 | * @author fansili | 21 | * @author fansili |
| 26 | */ | 22 | */ |
| 27 | public class TongYiChatModelTests { | 23 | public class TongYiChatModelTests { |
| 28 | 24 | ||
| 29 | - private final Generation generation = new Generation(); | ||
| 30 | - private final TongYiChatModel chatModel = new TongYiChatModel(generation, | ||
| 31 | - TongYiChatOptions.builder().withModel("qwen1.5-72b-chat").build()); | ||
| 32 | - | ||
| 33 | - static { | ||
| 34 | - Constants.apiKey = "sk-Zsd81gZYg7"; | ||
| 35 | - } | ||
| 36 | - | ||
| 37 | - @BeforeEach | ||
| 38 | - public void before() { | ||
| 39 | - // 防止 TongYiChatModel 调用空指针 | ||
| 40 | - ReflectUtil.setFieldValue(chatModel, "msgManager", new MessageManager()); | ||
| 41 | - } | 25 | + private final DashScopeChatModel chatModel = new DashScopeChatModel( |
| 26 | + new DashScopeApi("sk-7d903764249848cfa912733146da12d1"), | ||
| 27 | + DashScopeChatOptions.builder().withModel("qwen1.5-72b-chat").build()); | ||
| 42 | 28 | ||
| 43 | @Test | 29 | @Test |
| 44 | @Disabled | 30 | @Disabled |
yudao-module-ai/yudao-spring-boot-starter-ai/src/test/java/cn/iocoder/yudao/framework/ai/chat/XingHuoChatModelTests.java
| @@ -23,18 +23,18 @@ import java.util.List; | @@ -23,18 +23,18 @@ import java.util.List; | ||
| 23 | */ | 23 | */ |
| 24 | public class XingHuoChatModelTests { | 24 | public class XingHuoChatModelTests { |
| 25 | 25 | ||
| 26 | - private static final OpenAiChatModel openAiChatModel = OpenAiChatModel.builder() | ||
| 27 | - .openAiApi(OpenAiApi.builder() | ||
| 28 | - .baseUrl(XingHuoChatModel.BASE_URL) | ||
| 29 | - .apiKey("75b161ed2aef4719b275d6e7f2a4d4cd:YWYxYWI2MTA4ODI2NGZlYTQyNjAzZTcz") // appKey:secretKey | ||
| 30 | - .build()) | ||
| 31 | - .defaultOptions(OpenAiChatOptions.builder() | ||
| 32 | - .model("generalv3.5") // 模型 | ||
| 33 | - .temperature(0.7) | ||
| 34 | - .build()) | ||
| 35 | - .build(); | 26 | + private static final OpenAiChatModel openAiChatModel = OpenAiChatModel.builder() |
| 27 | + .openAiApi(OpenAiApi.builder() | ||
| 28 | + .baseUrl(XingHuoChatModel.BASE_URL) | ||
| 29 | + .apiKey("75b161ed2aef4719b275d6e7f2a4d4cd:YWYxYWI2MTA4ODI2NGZlYTQyNjAzZTcz") // appKey:secretKey | ||
| 30 | + .build()) | ||
| 31 | + .defaultOptions(OpenAiChatOptions.builder() | ||
| 32 | + .model("generalv3.5") // 模型 | ||
| 33 | + .temperature(0.7) | ||
| 34 | + .build()) | ||
| 35 | + .build(); | ||
| 36 | 36 | ||
| 37 | - private final XingHuoChatModel chatModel = new XingHuoChatModel(openAiChatModel); | 37 | + private final XingHuoChatModel chatModel = new XingHuoChatModel(openAiChatModel); |
| 38 | 38 | ||
| 39 | @Test | 39 | @Test |
| 40 | @Disabled | 40 | @Disabled |