Browse Source

将接口中参数调整为变量设置到nacos配置中

zhaojinyu 1 month ago
parent
commit
228b0aac04

+ 15 - 7
base-modules/service-ai/service-ai-biz/src/main/java/com/usky/ai/controller/web/AiChatController.java

@@ -2,7 +2,6 @@ package com.usky.ai.controller.web;
 
 import com.alibaba.dashscope.aigc.generation.Generation;
 import com.alibaba.dashscope.aigc.generation.GenerationParam;
-import com.alibaba.dashscope.aigc.generation.GenerationResult;
 import com.alibaba.dashscope.common.Message;
 import com.alibaba.dashscope.common.Role;
 import com.alibaba.dashscope.exception.ApiException;
@@ -38,6 +37,15 @@ public class AiChatController {
     @Value("${ai.api.key}")
     private String apiKey;
 
+    @Value("${airole}")
+    private String aiRole;
+
+    @Value("${aliTyqw.model}")
+    private String tyqwModel;
+
+    @Value("${aliDpsk.model}")
+    private String dpskModel;
+
     @Resource
     private Generation generation;
 
@@ -103,7 +111,7 @@ public class AiChatController {
         Message roleDefinition = Message.builder()
                 .role(Role.SYSTEM.getValue()) // 使用系统角色
 //                .content("你是一个名为'永天小天Ai'的智能助手,擅长幽默和简洁的回答。") // 定义角色的行为和风格
-                .content("你是一个名为'小天Ai'的智能助手,擅长解答编程和技术问题。回答时请保持专业、清晰且简洁。") // 定义角色的行为和风格
+                .content(aiRole) // 定义角色的行为和风格
                 .build();
         messages.add(0, roleDefinition); // 将角色定义插入到对话历史的开头
 
@@ -116,7 +124,7 @@ public class AiChatController {
 
         // 构建模型调用参数
         GenerationParam param = GenerationParam.builder()
-                .model("qwen-turbo")
+                .model(tyqwModel)
                 .messages(messages)
                 .resultFormat(GenerationParam.ResultFormat.MESSAGE)
                 .apiKey(apiKey)
@@ -142,7 +150,7 @@ public class AiChatController {
 
                         // 流式接口调用完成后,将完整回答存入数据库
                         AiQuestion aiQuestion = new AiQuestion();
-                        aiQuestion.setModel("qwen-turbo");
+                        aiQuestion.setModel(tyqwModel);
                         aiQuestion.setSessionId(finalSessionId);
                         aiQuestion.setUserId(userId);
                         aiQuestion.setUserName(userName);
@@ -217,7 +225,7 @@ public class AiChatController {
         Message roleDefinition = Message.builder()
                 .role(Role.SYSTEM.getValue()) // 使用系统角色
 //                .content("你是一个名为'永天小天Ai'的智能助手,擅长幽默和简洁的回答。") // 定义角色的行为和风格
-                .content("你是一个名为'小天Ai'的智能助手,擅长解答编程和技术问题。回答时请保持专业、清晰且简洁。") // 定义角色的行为和风格
+                .content(aiRole) // 定义角色的行为和风格
                 .build();
         messages.add(0, roleDefinition); // 将角色定义插入到对话历史的开头
 
@@ -230,7 +238,7 @@ public class AiChatController {
 
         // 构建模型调用参数
         GenerationParam param = GenerationParam.builder()
-                .model("deepseek-v3")
+                .model(dpskModel)
                 .messages(messages)
                 .resultFormat(GenerationParam.ResultFormat.MESSAGE)
                 .apiKey(apiKey)
@@ -256,7 +264,7 @@ public class AiChatController {
 
                         // 流式接口调用完成后,将完整回答存入数据库
                         AiQuestion aiQuestion = new AiQuestion();
-                        aiQuestion.setModel("qwen-turbo");
+                        aiQuestion.setModel(dpskModel);
                         aiQuestion.setSessionId(finalSessionId);
                         aiQuestion.setUserId(userId);
                         aiQuestion.setUserName(userName);