【代码重构】AI:使用 alibaba ai 替代 tongyi 的实现
This commit is contained in:
parent
f582c9cfa3
commit
3b7b81829d
|
@ -1,12 +1,8 @@
|
||||||
package cn.iocoder.yudao.framework.ai.chat;
|
package cn.iocoder.yudao.framework.ai.chat;
|
||||||
|
|
||||||
import cn.hutool.core.util.ReflectUtil;
|
import com.alibaba.cloud.ai.dashscope.api.DashScopeApi;
|
||||||
import com.alibaba.cloud.ai.tongyi.chat.TongYiChatModel;
|
import com.alibaba.cloud.ai.dashscope.chat.DashScopeChatModel;
|
||||||
import com.alibaba.cloud.ai.tongyi.chat.TongYiChatOptions;
|
import com.alibaba.cloud.ai.dashscope.chat.DashScopeChatOptions;
|
||||||
import com.alibaba.dashscope.aigc.generation.Generation;
|
|
||||||
import com.alibaba.dashscope.common.MessageManager;
|
|
||||||
import com.alibaba.dashscope.utils.Constants;
|
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
|
||||||
import org.junit.jupiter.api.Disabled;
|
import org.junit.jupiter.api.Disabled;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.ai.chat.messages.Message;
|
import org.springframework.ai.chat.messages.Message;
|
||||||
|
@ -20,25 +16,15 @@ import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link TongYiChatModel} 集成测试类
|
* {@link DashScopeChatModel} 集成测试类
|
||||||
*
|
*
|
||||||
* @author fansili
|
* @author fansili
|
||||||
*/
|
*/
|
||||||
public class TongYiChatModelTests {
|
public class TongYiChatModelTests {
|
||||||
|
|
||||||
private final Generation generation = new Generation();
|
private final DashScopeChatModel chatModel = new DashScopeChatModel(
|
||||||
private final TongYiChatModel chatModel = new TongYiChatModel(generation,
|
new DashScopeApi("sk-7d903764249848cfa912733146da12d1"),
|
||||||
TongYiChatOptions.builder().withModel("qwen1.5-72b-chat").build());
|
DashScopeChatOptions.builder().withModel("qwen1.5-72b-chat").build());
|
||||||
|
|
||||||
static {
|
|
||||||
Constants.apiKey = "sk-Zsd81gZYg7";
|
|
||||||
}
|
|
||||||
|
|
||||||
@BeforeEach
|
|
||||||
public void before() {
|
|
||||||
// 防止 TongYiChatModel 调用空指针
|
|
||||||
ReflectUtil.setFieldValue(chatModel, "msgManager", new MessageManager());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Disabled
|
@Disabled
|
||||||
|
|
|
@ -23,18 +23,18 @@ import java.util.List;
|
||||||
*/
|
*/
|
||||||
public class XingHuoChatModelTests {
|
public class XingHuoChatModelTests {
|
||||||
|
|
||||||
private static final OpenAiChatModel openAiChatModel = OpenAiChatModel.builder()
|
private static final OpenAiChatModel openAiChatModel = OpenAiChatModel.builder()
|
||||||
.openAiApi(OpenAiApi.builder()
|
.openAiApi(OpenAiApi.builder()
|
||||||
.baseUrl(XingHuoChatModel.BASE_URL)
|
.baseUrl(XingHuoChatModel.BASE_URL)
|
||||||
.apiKey("75b161ed2aef4719b275d6e7f2a4d4cd:YWYxYWI2MTA4ODI2NGZlYTQyNjAzZTcz") // appKey:secretKey
|
.apiKey("75b161ed2aef4719b275d6e7f2a4d4cd:YWYxYWI2MTA4ODI2NGZlYTQyNjAzZTcz") // appKey:secretKey
|
||||||
.build())
|
.build())
|
||||||
.defaultOptions(OpenAiChatOptions.builder()
|
.defaultOptions(OpenAiChatOptions.builder()
|
||||||
.model("generalv3.5") // 模型
|
.model("generalv3.5") // 模型
|
||||||
.temperature(0.7)
|
.temperature(0.7)
|
||||||
.build())
|
.build())
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
private final XingHuoChatModel chatModel = new XingHuoChatModel(openAiChatModel);
|
private final XingHuoChatModel chatModel = new XingHuoChatModel(openAiChatModel);
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Disabled
|
@Disabled
|
||||||
|
|
Loading…
Reference in New Issue