mirror of
https://gitcode.com/ageerle/ruoyi-ai.git
synced 2026-11-14 23:10:41 +00:00
fix: return model keys in admin details and allow clearing
This commit is contained in:
@@ -13,6 +13,7 @@ import org.ruoyi.common.chat.domain.bo.chat.ChatModelSelectQuery;
|
||||
import org.ruoyi.common.chat.domain.bo.chat.ModelBatchKeyBo;
|
||||
import org.ruoyi.common.chat.domain.vo.chat.ChatModelSelectVo;
|
||||
import org.ruoyi.common.chat.domain.vo.chat.ChatModelVo;
|
||||
import org.ruoyi.common.chat.domain.vo.chat.ChatModelDetailVo;
|
||||
import org.ruoyi.common.core.utils.StringUtils;
|
||||
import org.ruoyi.enums.ChatModeType;
|
||||
import org.ruoyi.enums.ModelType;
|
||||
@@ -105,9 +106,9 @@ public class ChatModelController extends BaseController {
|
||||
*/
|
||||
@SaCheckPermission("system:model:query")
|
||||
@GetMapping("/{id}")
|
||||
public R<ChatModelVo> getInfo(@NotNull(message = "主键不能为空")
|
||||
public R<ChatModelDetailVo> getInfo(@NotNull(message = "主键不能为空")
|
||||
@PathVariable Long id) {
|
||||
return R.ok(chatModelService.queryById(id));
|
||||
return R.ok(ChatModelDetailVo.from(chatModelService.queryById(id)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -147,10 +147,6 @@ public class ChatModelServiceImpl implements IChatModelService {
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Boolean updateByBo(ChatModelBo bo) {
|
||||
ChatModel update = toEntity(bo);
|
||||
// 编辑表单不回显密钥;留空时保留数据库中的原值。
|
||||
if ("".equals(update.getApiKey())) {
|
||||
update.setApiKey(null);
|
||||
}
|
||||
ChatModel current = selectByIdForUpdate(update.getId());
|
||||
if (current == null) {
|
||||
return false;
|
||||
|
||||
@@ -9,7 +9,7 @@ import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.NullAndEmptySource;
|
||||
import org.junit.jupiter.params.provider.NullSource;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.ruoyi.common.chat.domain.bo.chat.ChatModelBo;
|
||||
@@ -47,7 +47,7 @@ class ChatModelApiKeyTest {
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {"sk-new-key", " env:LITERAL_VALUE ", "env:ATLAS_API_KEY"})
|
||||
@ValueSource(strings = {"", " ", "任意内容/key:123", "sk-new-key", " env:LITERAL_VALUE ", "env:ATLAS_API_KEY"})
|
||||
void editReplacesAnOldReferenceWithExactlyTheSuppliedValue(String key) {
|
||||
when(mapper.selectOne(any())).thenReturn(currentModel());
|
||||
when(mapper.updateById(any(ChatModel.class))).thenReturn(1);
|
||||
@@ -58,7 +58,7 @@ class ChatModelApiKeyTest {
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@NullAndEmptySource
|
||||
@NullSource
|
||||
void editWithoutANewKeyDoesNotOverwriteTheExistingKey(String key) {
|
||||
when(mapper.selectOne(any())).thenReturn(currentModel());
|
||||
when(mapper.updateById(any(ChatModel.class))).thenReturn(1);
|
||||
|
||||
Reference in New Issue
Block a user