feat: Add support for builtin models in the application

- Introduced `is_builtin` property in the model configuration to identify builtin models.
- Updated frontend components to display a tag for builtin models in the ModelSelector and ModelSettings.
- Enhanced the ModelEditorDialog to prevent editing and deletion of builtin models.
- Implemented logic in the backend to hide sensitive information for builtin models and restrict their modification.
- Added informative UI elements to clarify the nature of builtin models in the settings and editor views.
This commit is contained in:
wizardchen
2025-11-14 12:09:52 +08:00
parent a1fb794650
commit bb6dff80b5
13 changed files with 571 additions and 49 deletions
+1
View File
@@ -19,6 +19,7 @@ export interface ModelConfig {
parameter_size?: string; // Ollama模型参数大小 (e.g., "7B", "13B", "70B")
};
is_default?: boolean;
is_builtin?: boolean;
status?: string;
created_at?: string;
updated_at?: string;
+78 -20
View File
@@ -781,12 +781,12 @@ const handleCancel = () => {
left: 0;
right: 0;
bottom: 0;
background: rgba(0, 0, 0, 0.5);
background: rgba(0, 0, 0, 0.45);
display: flex;
align-items: center;
justify-content: center;
z-index: 1000;
backdrop-filter: blur(4px);
backdrop-filter: blur(6px);
overflow: hidden; // 防止背景滚动
}
@@ -798,7 +798,7 @@ const handleCancel = () => {
max-height: 85vh;
background: #fff;
border-radius: 12px;
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
box-shadow: 0 12px 48px rgba(0, 0, 0, 0.15), 0 0 0 1px rgba(0, 0, 0, 0.05);
display: flex;
flex-direction: column;
overflow: hidden;
@@ -813,41 +813,43 @@ const handleCancel = () => {
height: 32px;
border: none;
background: #f5f5f5;
border-radius: 6px;
border-radius: 8px;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
color: #666;
transition: all 0.2s ease;
transition: background-color 0.2s ease, color 0.2s ease;
z-index: 10;
&:hover {
background: #e5e5e5;
color: #000;
background: rgba(7, 192, 95, 0.1);
color: #07C05F;
}
}
// 标题区域
.modal-header {
padding: 24px 32px 20px;
border-bottom: 1px solid #e5e5e5;
padding: 28px 32px 20px;
border-bottom: 1px solid #f0f0f0;
flex-shrink: 0;
background: linear-gradient(to bottom, #ffffff 0%, #fafafa 100%);
}
.modal-title {
margin: 0 0 8px 0;
font-family: "PingFang SC";
font-size: 18px;
font-size: 20px;
font-weight: 600;
color: #000000e6;
color: #1a1a1a;
letter-spacing: -0.3px;
}
.modal-desc {
margin: 0;
font-family: "PingFang SC";
font-size: 14px;
color: #00000066;
color: #666666;
line-height: 22px;
}
@@ -855,7 +857,8 @@ const handleCancel = () => {
.modal-body {
flex: 1;
overflow-y: auto;
padding: 24px 32px;
padding: 28px 32px;
background: #ffffff;
// 自定义滚动条
&::-webkit-scrollbar {
@@ -870,9 +873,10 @@ const handleCancel = () => {
&::-webkit-scrollbar-thumb {
background: #d0d0d0;
border-radius: 3px;
transition: background 0.2s;
&:hover {
background: #b0b0b0;
background: #07C05F;
}
}
@@ -894,16 +898,18 @@ const handleCancel = () => {
.form-label {
display: block;
margin-bottom: 8px;
margin-bottom: 10px;
font-family: "PingFang SC";
font-size: 14px;
font-weight: 500;
color: #000000e6;
color: #333333;
letter-spacing: -0.2px;
&.required::after {
content: '*';
color: #FA5151;
margin-left: 4px;
font-weight: 600;
}
}
@@ -914,26 +920,53 @@ const handleCancel = () => {
:deep(.t-input-number) {
width: 100%;
font-size: 14px;
transition: all 0.2s ease;
.t-input__inner,
input {
font-size: 14px;
border-radius: 6px;
transition: all 0.2s ease;
}
&:hover .t-input__inner,
&:hover input {
border-color: #07C05F;
}
&.t-is-focused .t-input__inner,
&.t-is-focused input {
border-color: #07C05F;
box-shadow: 0 0 0 2px rgba(7, 192, 95, 0.1);
}
}
// 单选按钮组
:deep(.t-radio-group) {
display: flex;
gap: 16px;
gap: 20px;
.t-radio {
margin-right: 0;
font-size: 14px;
transition: all 0.2s ease;
&:hover {
.t-radio__label {
color: #07C05F;
}
}
}
.t-radio__label {
font-size: 14px;
color: #000000e6;
color: #333333;
transition: color 0.2s ease;
}
.t-radio__input:checked + .t-radio__label {
color: #07C05F;
font-weight: 500;
}
}
@@ -949,12 +982,37 @@ const handleCancel = () => {
// 底部按钮区域
.modal-footer {
padding: 16px 32px;
border-top: 1px solid #e5e5e5;
padding: 20px 32px;
border-top: 1px solid #f0f0f0;
display: flex;
justify-content: flex-end;
gap: 12px;
flex-shrink: 0;
background: #fafafa;
:deep(.t-button) {
min-width: 88px;
height: 36px;
font-weight: 500;
border-radius: 6px;
&.t-button--theme-primary {
background: #07C05F;
border-color: #07C05F;
&:hover {
background: #06b04d;
border-color: #06b04d;
}
}
&.t-button--variant-outline {
&:hover {
border-color: #07C05F;
color: #07C05F;
}
}
}
}
// 过渡动画
@@ -19,6 +19,7 @@
<div class="model-option">
<t-icon name="check-circle-filled" class="model-icon" />
<span class="model-name">{{ model.name }}</span>
<t-tag v-if="model.is_builtin" size="small" theme="primary">内置</t-tag>
<t-tag v-if="model.is_default" size="small" theme="success">{{ $t('model.defaultTag') }}</t-tag>
</div>
</t-option>
@@ -535,6 +535,16 @@ watch(() => props.visible, async (newVal) => {
}, 300)
}
})
// 监听全局设置弹窗关闭后刷新模型列表
watch(
() => uiStore.showSettingsModal,
async (visible, previous) => {
if (!visible && previous && props.visible) {
await loadAllModels()
}
}
)
</script>
<style scoped lang="less">
+171 -13
View File
@@ -3,6 +3,25 @@
<div class="section-header">
<h2>{{ $t('modelSettings.title') }}</h2>
<p class="section-description">{{ $t('modelSettings.description') }}</p>
<!-- 内置模型说明 -->
<div class="builtin-models-info">
<div class="info-box">
<div class="info-header">
<t-icon name="info-circle" class="info-icon" />
<span class="info-title">内置模型</span>
</div>
<div class="info-content">
<p>内置模型对所有租户可见,敏感信息会被隐藏,且不可编辑或删除。</p>
<p class="doc-link">
<t-icon name="link" class="link-icon" />
<a href="https://github.com/Tencent/WeKnora/blob/main/docs/BUILTIN_MODELS.md" target="_blank" rel="noopener noreferrer">
查看内置模型管理指南
</a>
</p>
</div>
</div>
</div>
</div>
<!-- 对话模型 -->
@@ -12,19 +31,20 @@
<h3>{{ $t('modelSettings.chat.title') }}</h3>
<p>{{ $t('modelSettings.chat.desc') }}</p>
</div>
<t-button size="small" theme="primary" @click="openAddDialog('chat')">
<t-button size="small" theme="primary" @click="openAddDialog('chat')" class="add-model-btn">
<template #icon>
<t-icon name="add" />
<t-icon name="add" class="add-icon" />
</template>
{{ $t('modelSettings.actions.addModel') }}
</t-button>
</div>
<div v-if="chatModels.length > 0" class="model-list-container">
<div v-for="model in chatModels" :key="model.id" class="model-card">
<div v-for="model in chatModels" :key="model.id" class="model-card" :class="{ 'builtin-model': model.isBuiltin }">
<div class="model-info">
<div class="model-name">
{{ model.name }}
<t-tag v-if="model.isBuiltin" theme="primary" size="small">内置</t-tag>
<t-tag v-if="model.isDefault" theme="success" size="small">{{ $t('common.default') }}</t-tag>
</div>
<div class="model-meta">
@@ -61,19 +81,20 @@
<h3>{{ $t('modelSettings.embedding.title') }}</h3>
<p>{{ $t('modelSettings.embedding.desc') }}</p>
</div>
<t-button size="small" theme="primary" @click="openAddDialog('embedding')">
<t-button size="small" theme="primary" @click="openAddDialog('embedding')" class="add-model-btn">
<template #icon>
<t-icon name="add" />
<t-icon name="add" class="add-icon" />
</template>
{{ $t('modelSettings.actions.addModel') }}
</t-button>
</div>
<div v-if="embeddingModels.length > 0" class="model-list-container">
<div v-for="model in embeddingModels" :key="model.id" class="model-card">
<div v-for="model in embeddingModels" :key="model.id" class="model-card" :class="{ 'builtin-model': model.isBuiltin }">
<div class="model-info">
<div class="model-name">
{{ model.name }}
<t-tag v-if="model.isBuiltin" theme="primary" size="small">内置</t-tag>
<t-tag v-if="model.isDefault" theme="success" size="small">{{ $t('common.default') }}</t-tag>
</div>
<div class="model-meta">
@@ -111,19 +132,20 @@
<h3>{{ $t('modelSettings.rerank.title') }}</h3>
<p>{{ $t('modelSettings.rerank.desc') }}</p>
</div>
<t-button size="small" theme="primary" @click="openAddDialog('rerank')">
<t-button size="small" theme="primary" @click="openAddDialog('rerank')" class="add-model-btn">
<template #icon>
<t-icon name="add" />
<t-icon name="add" class="add-icon" />
</template>
{{ $t('modelSettings.actions.addModel') }}
</t-button>
</div>
<div v-if="rerankModels.length > 0" class="model-list-container">
<div v-for="model in rerankModels" :key="model.id" class="model-card">
<div v-for="model in rerankModels" :key="model.id" class="model-card" :class="{ 'builtin-model': model.isBuiltin }">
<div class="model-info">
<div class="model-name">
{{ model.name }}
<t-tag v-if="model.isBuiltin" theme="primary" size="small">内置</t-tag>
<t-tag v-if="model.isDefault" theme="success" size="small">{{ $t('common.default') }}</t-tag>
</div>
<div class="model-meta">
@@ -160,19 +182,20 @@
<h3>{{ $t('modelSettings.vllm.title') }}</h3>
<p>{{ $t('modelSettings.vllm.desc') }}</p>
</div>
<t-button size="small" theme="primary" @click="openAddDialog('vllm')">
<t-button size="small" theme="primary" @click="openAddDialog('vllm')" class="add-model-btn">
<template #icon>
<t-icon name="add" />
<t-icon name="add" class="add-icon" />
</template>
{{ $t('modelSettings.actions.addModel') }}
</t-button>
</div>
<div v-if="vllmModels.length > 0" class="model-list-container">
<div v-for="model in vllmModels" :key="model.id" class="model-card">
<div v-for="model in vllmModels" :key="model.id" class="model-card" :class="{ 'builtin-model': model.isBuiltin }">
<div class="model-info">
<div class="model-name">
{{ model.name }}
<t-tag v-if="model.isBuiltin" theme="primary" size="small">内置</t-tag>
<t-tag v-if="model.isDefault" theme="success" size="small">{{ $t('common.default') }}</t-tag>
</div>
<div class="model-meta">
@@ -272,7 +295,8 @@ function convertToLegacyFormat(model: ModelConfig) {
baseUrl: model.parameters.base_url || '',
apiKey: model.parameters.api_key || '',
dimension: model.parameters.embedding_parameters?.dimension,
isDefault: model.is_default || false
isDefault: model.is_default || false,
isBuiltin: model.is_builtin || false
}
}
@@ -330,6 +354,11 @@ const openAddDialog = (type: 'chat' | 'embedding' | 'rerank' | 'vllm') => {
// 编辑模型
const editModel = (type: 'chat' | 'embedding' | 'rerank' | 'vllm', model: any) => {
// 内置模型不能编辑
if (model.isBuiltin) {
MessagePlugin.warning('内置模型不能编辑')
return
}
currentModelType.value = type
editingModel.value = { ...model }
showDialog.value = true
@@ -412,6 +441,13 @@ const handleModelSave = async (modelData: any) => {
// 删除模型
const deleteModel = async (type: 'chat' | 'embedding' | 'rerank' | 'vllm', modelId: string) => {
// 检查是否是内置模型
const model = allModels.value.find(m => m.id === modelId)
if (model?.is_builtin) {
MessagePlugin.warning('内置模型不能删除')
return
}
try {
await deleteModelAPI(modelId)
MessagePlugin.success(t('modelSettings.toasts.deleted'))
@@ -441,6 +477,18 @@ const setDefault = async (type: 'chat' | 'embedding' | 'rerank' | 'vllm', modelI
const getModelOptions = (type: 'chat' | 'embedding' | 'rerank' | 'vllm', model: any) => {
const options: any[] = []
// 内置模型不能编辑和删除,只能设为默认
if (model.isBuiltin) {
// 如果不是默认模型,显示"设为默认"选项
if (!model.isDefault) {
options.push({
content: t('modelSettings.actions.setDefault'),
value: `set-default-${type}-${model.id}`
})
}
return options
}
// 如果不是默认模型,显示"设为默认"选项
if (!model.isDefault) {
options.push({
@@ -556,7 +604,20 @@ onMounted(() => {
line-height: 1.5;
}
}
}
// 添加模型按钮样式优化
:deep(.add-model-btn) {
display: inline-flex;
align-items: center;
gap: 6px;
font-weight: 500;
.add-icon {
font-size: 16px;
width: 16px;
height: 16px;
}
}
.model-list-container {
@@ -585,6 +646,39 @@ onMounted(() => {
border-color: #07C05F;
background: #ffffff;
}
// 内置模型置灰样式
&.builtin-model {
opacity: 0.7;
background: #f5f5f5;
border-color: #d9d9d9;
cursor: not-allowed;
&:hover {
border-color: #d9d9d9;
background: #f5f5f5;
opacity: 0.8;
}
.model-info {
.model-name {
color: #999999;
}
.model-meta {
color: #999999;
.source-tag {
background: #e5e5e5;
color: #999999;
}
}
}
.model-actions {
opacity: 0.6;
}
}
}
.model-info {
@@ -661,4 +755,68 @@ onMounted(() => {
margin: 0 0 16px 0;
}
}
.builtin-models-info {
margin-top: 20px;
.info-box {
background: #f8f9fa;
border: 1px solid #e5e7eb;
border-left: 3px solid #07C05F;
border-radius: 4px;
padding: 12px 16px;
}
.info-header {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 8px;
.info-icon {
font-size: 16px;
color: #07C05F;
}
.info-title {
font-size: 14px;
font-weight: 500;
color: #333333;
}
}
.info-content {
font-size: 13px;
line-height: 1.6;
color: #666666;
p {
margin: 0 0 8px 0;
&.doc-link {
margin-top: 8px;
display: flex;
align-items: center;
gap: 6px;
.link-icon {
font-size: 14px;
color: #07C05F;
}
a {
color: #07C05F;
text-decoration: none;
font-weight: 500;
transition: color 0.2s;
&:hover {
color: #06b04d;
text-decoration: underline;
}
}
}
}
}
}
</style>