|
@@ -18,6 +18,7 @@ import lombok.extern.slf4j.Slf4j; |
|
@@ -18,6 +18,7 @@ import lombok.extern.slf4j.Slf4j; |
|
18
|
import org.jeecg.common.system.base.controller.JeecgController;
|
18
|
import org.jeecg.common.system.base.controller.JeecgController;
|
|
19
|
import org.jeecg.modules.airag.app.entity.AiragButton;
|
19
|
import org.jeecg.modules.airag.app.entity.AiragButton;
|
|
20
|
import org.jeecg.modules.airag.app.service.IAiragButtonService;
|
20
|
import org.jeecg.modules.airag.app.service.IAiragButtonService;
|
|
|
|
21
|
+import org.jeecg.modules.airag.app.service.RedisChatSetService;
|
|
21
|
import org.jeecg.modules.airag.llm.entity.AiragKnowledge;
|
22
|
import org.jeecg.modules.airag.llm.entity.AiragKnowledge;
|
|
22
|
import org.jeecg.modules.airag.llm.entity.AiragModel;
|
23
|
import org.jeecg.modules.airag.llm.entity.AiragModel;
|
|
23
|
import org.jeecg.modules.airag.llm.service.IAiragKnowledgeService;
|
24
|
import org.jeecg.modules.airag.llm.service.IAiragKnowledgeService;
|
|
@@ -52,7 +53,8 @@ public class AiragChatsettingController extends JeecgController<AiragChatsetting |
|
@@ -52,7 +53,8 @@ public class AiragChatsettingController extends JeecgController<AiragChatsetting |
|
52
|
|
53
|
|
|
53
|
@Autowired
|
54
|
@Autowired
|
|
54
|
private IAiragButtonService airagButtonService;
|
55
|
private IAiragButtonService airagButtonService;
|
|
55
|
-
|
56
|
+ @Autowired
|
|
|
|
57
|
+ private RedisChatSetService redisChatSetService;
|
|
56
|
/**
|
58
|
/**
|
|
57
|
* 获取字段数据
|
59
|
* 获取字段数据
|
|
58
|
*
|
60
|
*
|
|
@@ -65,18 +67,26 @@ public class AiragChatsettingController extends JeecgController<AiragChatsetting |
|
@@ -65,18 +67,26 @@ public class AiragChatsettingController extends JeecgController<AiragChatsetting |
|
65
|
public Result<Map<String, Object>> getConfigData(AiragChatsetting airagChatsetting) {
|
67
|
public Result<Map<String, Object>> getConfigData(AiragChatsetting airagChatsetting) {
|
|
66
|
Map<String, Object> result = new HashMap<>();
|
68
|
Map<String, Object> result = new HashMap<>();
|
|
67
|
|
69
|
|
|
68
|
- // 获取配置数据(只取第一条)
|
|
|
|
69
|
- AiragChatsetting airagChatsettingConfig = airagChatsettingService.getOne(new QueryWrapper<>());
|
70
|
+ // 先从Redis获取配置数据
|
|
|
|
71
|
+ AiragChatsetting airagChatsettingConfig = redisChatSetService.getChatSetting();
|
|
|
|
72
|
+
|
|
|
|
73
|
+ // 如果Redis中没有,则从数据库查询并存入Redis
|
|
70
|
if (airagChatsettingConfig == null) {
|
74
|
if (airagChatsettingConfig == null) {
|
|
|
|
75
|
+ airagChatsettingConfig = airagChatsettingService.getOne(new QueryWrapper<>());
|
|
|
|
76
|
+ if (airagChatsettingConfig != null) {
|
|
|
|
77
|
+ // 存入Redis
|
|
|
|
78
|
+ redisChatSetService.saveChatSetting(airagChatsettingConfig);
|
|
|
|
79
|
+ } else {
|
|
71
|
airagChatsettingConfig = new AiragChatsetting();
|
80
|
airagChatsettingConfig = new AiragChatsetting();
|
|
72
|
}
|
81
|
}
|
|
|
|
82
|
+ }
|
|
73
|
|
83
|
|
|
74
|
// 处理按钮ID为数组
|
84
|
// 处理按钮ID为数组
|
|
75
|
if (StringUtils.isNotBlank(airagChatsettingConfig.getButtonId())) {
|
85
|
if (StringUtils.isNotBlank(airagChatsettingConfig.getButtonId())) {
|
|
76
|
airagChatsettingConfig.setButtonIds(Arrays.asList(airagChatsettingConfig.getButtonId().split(",")));
|
86
|
airagChatsettingConfig.setButtonIds(Arrays.asList(airagChatsettingConfig.getButtonId().split(",")));
|
|
77
|
}
|
87
|
}
|
|
78
|
|
88
|
|
|
79
|
- // 直接查询选项数据
|
89
|
+
|
|
80
|
result.put("airagChatsettingConfig", airagChatsettingConfig);
|
90
|
result.put("airagChatsettingConfig", airagChatsettingConfig);
|
|
81
|
result.put("embeddingOptions", getModelOptions("EMBED"));
|
91
|
result.put("embeddingOptions", getModelOptions("EMBED"));
|
|
82
|
result.put("llmOptions", getModelOptions("LLM"));
|
92
|
result.put("llmOptions", getModelOptions("LLM"));
|
|
@@ -160,18 +170,18 @@ public class AiragChatsettingController extends JeecgController<AiragChatsetting |
|
@@ -160,18 +170,18 @@ public class AiragChatsettingController extends JeecgController<AiragChatsetting |
|
160
|
config.setButtonId(null);
|
170
|
config.setButtonId(null);
|
|
161
|
}
|
171
|
}
|
|
162
|
|
172
|
|
|
163
|
- if(StringUtils.isNotBlank(config.getId())){
|
173
|
+ // 数据库操作
|
|
|
|
174
|
+ if(StringUtils.isNotBlank(config.getId())) {
|
|
164
|
airagChatsettingService.updateById(config);
|
175
|
airagChatsettingService.updateById(config);
|
|
165
|
- return Result.OK("更新成功!");
|
|
|
|
166
|
- }else{
|
|
|
|
167
|
- if(airagChatsettingService.list().isEmpty()){
|
|
|
|
168
|
- return Result.OK("只需要一条配置信息");
|
|
|
|
169
|
- }
|
176
|
+ } else {
|
|
170
|
config.setId(UUID.randomUUID().toString());
|
177
|
config.setId(UUID.randomUUID().toString());
|
|
171
|
airagChatsettingService.save(config);
|
178
|
airagChatsettingService.save(config);
|
|
172
|
- return Result.OK("创建成功!");
|
|
|
|
173
|
}
|
179
|
}
|
|
174
|
|
180
|
|
|
|
|
181
|
+ // 更新Redis缓存(无论新增还是修改都同步)
|
|
|
|
182
|
+ redisChatSetService.saveChatSetting(config);
|
|
|
|
183
|
+
|
|
|
|
184
|
+ return Result.OK(StringUtils.isNotBlank(config.getId()) ? "更新成功!" : "创建成功!");
|
|
175
|
}
|
185
|
}
|
|
176
|
|
186
|
|
|
177
|
} |
187
|
} |