mirror of
https://gitcode.com/ageerle/ruoyi-ai.git
synced 2026-03-14 05:03:43 +08:00
fix: 修复未登录无法使用联网插件
This commit is contained in:
@@ -106,7 +106,7 @@ public class KnowledgeController extends BaseController {
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo<KnowledgeInfoVo> list(KnowledgeInfoBo bo, PageQuery pageQuery) {
|
||||
if(!StpUtil.isLogin()){
|
||||
throw new SecurityException("请先去登录!");
|
||||
return null;
|
||||
}
|
||||
bo.setUid(LoginHelper.getUserId());
|
||||
return knowledgeInfoService.queryPageList(bo, pageQuery);
|
||||
|
||||
@@ -98,33 +98,36 @@ public class SseServiceImpl implements ISseService {
|
||||
SSEEventSourceListener openAIEventSourceListener = new SSEEventSourceListener(sseEmitter);
|
||||
// 获取对话消息列表
|
||||
List<Message> messages = chatRequest.getMessages();
|
||||
|
||||
try {
|
||||
String chatString = null;
|
||||
Object content = messages.get(messages.size() - 1).getContent();
|
||||
if (content instanceof List<?> listContent) {
|
||||
if (!listContent.isEmpty() && listContent.get(0) instanceof Content) {
|
||||
chatString = ((Content) listContent.get(0)).getText();
|
||||
}
|
||||
} else if (content instanceof String) {
|
||||
chatString = (String) content;
|
||||
}
|
||||
|
||||
String configValue = getKey("enabled");
|
||||
if (Boolean.parseBoolean(configValue)) {
|
||||
// 判断文本是否合规
|
||||
String type = textReview(chatString);
|
||||
// 审核状态 1 代表合法
|
||||
if (!"1".equals(type) && StringUtils.isNotEmpty(type)) {
|
||||
throw new BaseException("文本不合规,请修改!");
|
||||
}
|
||||
}
|
||||
|
||||
if (StpUtil.isLogin()) {
|
||||
LocalCache.CACHE.put("userId", getUserId());
|
||||
Object content = messages.get(messages.size() - 1).getContent();
|
||||
if (content instanceof List<?> listContent) {
|
||||
if (!listContent.isEmpty() && listContent.get(0) instanceof Content) {
|
||||
chatString = ((Content) listContent.get(0)).getText();
|
||||
}
|
||||
} else if (content instanceof String) {
|
||||
chatString = (String) content;
|
||||
}
|
||||
|
||||
ChatMessageBo chatMessageBo = new ChatMessageBo();
|
||||
chatMessageBo.setUserId(getUserId());
|
||||
chatMessageBo.setModelName(chatRequest.getModel());
|
||||
|
||||
chatMessageBo.setContent(chatString);
|
||||
String configValue = getKey("enabled");
|
||||
if (Boolean.parseBoolean(configValue)) {
|
||||
// 判断文本是否合规
|
||||
String type = textReview(chatString);
|
||||
// 审核状态 1 代表合法
|
||||
if (!"1".equals(type) && StringUtils.isNotEmpty(type)) {
|
||||
throw new BaseException("文本不合规,请修改!");
|
||||
}
|
||||
}
|
||||
|
||||
String model = chatRequest.getModel();
|
||||
// 如果是gpts系列模型
|
||||
if (chatRequest.getModel().startsWith("gpt-4-gizmo")) {
|
||||
@@ -137,7 +140,6 @@ public class SseServiceImpl implements ISseService {
|
||||
} else {
|
||||
openAiStreamClient = chatConfig.createOpenAiStreamClient(sysModel.getApiHost(), sysModel.getApiKey());
|
||||
// 模型设置默认提示词
|
||||
|
||||
if (StringUtils.isNotEmpty(sysModel.getSystemPrompt())) {
|
||||
Message sysMessage = Message.builder().content(sysModel.getSystemPrompt()).role(Message.Role.SYSTEM).build();
|
||||
messages.add(sysMessage);
|
||||
@@ -150,10 +152,10 @@ public class SseServiceImpl implements ISseService {
|
||||
}
|
||||
}
|
||||
}
|
||||
String configValue = configService.getConfigValue("zhipu", "key");
|
||||
String zhipuValue = configService.getConfigValue("zhipu", "key");
|
||||
// 添加联网信息
|
||||
if(StringUtils.isNotEmpty(configValue)){
|
||||
ClientV4 client = new ClientV4.Builder(configValue)
|
||||
ClientV4 client = new ClientV4.Builder(zhipuValue)
|
||||
.networkConfig(300, 100, 100, 100, TimeUnit.SECONDS)
|
||||
.connectionPool(new okhttp3.ConnectionPool(8, 1, TimeUnit.SECONDS))
|
||||
.build();
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package org.ruoyi.system.service.impl;
|
||||
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
@@ -65,6 +66,10 @@ public class SysNoticeServiceImpl implements ISysNoticeService {
|
||||
*/
|
||||
@Override
|
||||
public SysNotice getNotice(SysNoticeBo notice) {
|
||||
if(!StpUtil.isLogin()){
|
||||
return null;
|
||||
}
|
||||
|
||||
LambdaQueryWrapper<SysNoticeState> lqwState = Wrappers.lambdaQuery();
|
||||
Long userId = LoginHelper.getLoginUser().getUserId();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user