feat(onboarding): 注册引导确保企业培训默认库并补齐模型自动配置
空间引导(SeedTenantDefaults): - 按 Source 标记独立幂等确保「企业培训(课件)/(题库)」两个系统默认库, CASDOOR/OIDC 注册、平台注册、管理员建空间统一触发;与培训域上传链路 同源复用(不会重复建档),fail-open 不阻断注册主流程 模型自动配置(默认模型优先,否则该类型第一个 active): - 智能体创建后端兜底补齐 ReRank 模型,与主模型同口径(无可用重排模型留空) - 智能体/知识库编辑弹窗 applyDefaultModelsIfEmpty 改新建/编辑通用: 仅空字段补默认、绝不覆盖用户已选;存量空模型数据打开即可直接保存, 不再被「模型必填」卡住手动配置
This commit is contained in:
1 parent
6594f97e3c
commit
4112de0703
4 files changed
+74
-5
No files matched your search
@@ -3021,8 +3021,11 @@ const removeStarterSuggestion = (index: number) => {
|
||||
formData.value.config.question_suggestions.starters.items.splice(index, 1);
|
||||
};
|
||||
|
||||
// 模型自动配置(新建/编辑通用):默认模型优先,无默认取该类型第一个 active。
|
||||
// 仅在字段为空时补值,绝不覆盖用户已选;编辑态补默认可修复存量空模型智能体,
|
||||
// 免去「模型必填」手动配置(与后端 create 兜底同规则)。
|
||||
const applyDefaultModelsIfEmpty = () => {
|
||||
if (props.mode !== 'create' || !formData.value) return
|
||||
if (!formData.value) return
|
||||
const chatModelId = selectInitialModelId(allModels.value, 'KnowledgeQA')
|
||||
const rerankModelId = selectInitialModelId(allModels.value, 'Rerank')
|
||||
if (!formData.value.config.model_id && chatModelId) {
|
||||
@@ -3698,6 +3701,8 @@ watch(() => props.visible, async (val) => {
|
||||
// Display inherited defaults for all agents without persisting a copy.
|
||||
fillBuiltinAgentDefaults();
|
||||
void loadAgentIntegrationCounts(agentData.id);
|
||||
// 编辑态同样补默认模型(仅空字段):存量空模型智能体不再被「模型必填」卡住
|
||||
applyDefaultModelsIfEmpty()
|
||||
} else {
|
||||
// 创建新智能体,使用系统默认值
|
||||
storedToolNames.value = [];
|
||||
|
||||
@@ -889,8 +889,11 @@ const kbCreateNeedsEmbedding = computed(() => {
|
||||
return Boolean(s?.vectorEnabled || s?.keywordEnabled)
|
||||
})
|
||||
|
||||
// 模型自动配置(新建/编辑通用):默认模型优先,无默认取该类型第一个 active。
|
||||
// 仅在字段为空时补值,不覆盖用户已选;与后端 CreateKnowledgeBase 的默认兜底
|
||||
// 同规则,编辑态补默认可修复存量未绑模型的知识库。
|
||||
const applyDefaultModelsIfEmpty = () => {
|
||||
if (!formData.value || editorMode.value !== 'create') return
|
||||
if (!formData.value) return
|
||||
const chatModelId = selectInitialModelId(allModels.value, 'KnowledgeQA')
|
||||
const embeddingModelId = selectInitialModelId(allModels.value, 'Embedding')
|
||||
if (!formData.value.modelConfig.llmModelId && chatModelId) {
|
||||
@@ -1936,6 +1939,8 @@ watch(() => props.visible, async (newVal) => {
|
||||
// 根据模式加载数据
|
||||
if (props.mode === 'edit' && targetKbId) {
|
||||
await loadKBData(targetKbId, generation)
|
||||
// 编辑态同样补默认模型(仅空字段):存量未绑模型的知识库不再要求手动选择
|
||||
applyDefaultModelsIfEmpty()
|
||||
} else {
|
||||
// 创建模式:初始化空表单,并预填空间默认存储引擎
|
||||
formData.value = initFormData(props.initialType || 'document')
|
||||
|
||||
@@ -119,9 +119,16 @@ func (s *customAgentService) CreateAgent(ctx context.Context, agent *types.Custo
|
||||
// 开箱即用兜底:主对话模型为空时自动落到系统默认(内置 is_default
|
||||
// 优先,否则该类型第一个 active)。fail-open:解析不到保持为空,
|
||||
// 运行时的 "chat model is not configured" 报错行为与现状一致。
|
||||
if strings.TrimSpace(agent.Config.ModelID) == "" && s.modelService != nil {
|
||||
// ReRank 同口径兜底:无可用重排模型时保持为空(按需运行,不阻断)。
|
||||
if s.modelService != nil &&
|
||||
(strings.TrimSpace(agent.Config.ModelID) == "" || strings.TrimSpace(agent.Config.RerankModelID) == "") {
|
||||
if models, err := s.modelService.ListModels(ctx); err == nil {
|
||||
agent.Config.ModelID = PickDefaultModelID(models, types.ModelTypeKnowledgeQA)
|
||||
if strings.TrimSpace(agent.Config.ModelID) == "" {
|
||||
agent.Config.ModelID = PickDefaultModelID(models, types.ModelTypeKnowledgeQA)
|
||||
}
|
||||
if strings.TrimSpace(agent.Config.RerankModelID) == "" {
|
||||
agent.Config.RerankModelID = PickDefaultModelID(models, types.ModelTypeRerank)
|
||||
}
|
||||
} else {
|
||||
logger.Warnf(ctx, "agent create: default model fallback lookup failed: %v", err)
|
||||
}
|
||||
|
||||
@@ -20,7 +20,9 @@ import (
|
||||
// 1. 解析系统默认模型(内置模型 is_builtin=true 全租户可见,is_default 优先);
|
||||
// 2. 自动创建「新手入门」知识库,绑定默认对话/向量化模型;
|
||||
// 3. 在该库中预置一份欢迎文档(走标准上传管道,自动切片/向量化);
|
||||
// 4. 把租户级检索重排模型(retrieval_config.rerank_model_id)配成默认。
|
||||
// 4. 把租户级检索重排模型(retrieval_config.rerank_model_id)配成默认;
|
||||
// 5. 确保企业培训「课件/题库」两个系统默认知识库(CASDOOR/OIDC 自动注册
|
||||
// 用户进「知识库」页默认可见,与培训域共用同一对库)。
|
||||
//
|
||||
// 整体 fail-open:任何一步失败只记日志,绝不阻断注册/建租户主流程;
|
||||
// 且整体幂等——租户下已存在同名入门库时直接跳过。
|
||||
@@ -124,6 +126,12 @@ func (s *tenantBootstrapService) SeedTenantDefaults(ctx context.Context, tenant
|
||||
logger.Warnf(ctx, "tenant bootstrap: list KBs failed, skip seeding: tenant=%d err=%v", tenant.ID, err)
|
||||
return
|
||||
}
|
||||
|
||||
// 企业培训(课件)/(题库)系统默认库:按 Source 标记独立幂等确保(与培训域
|
||||
// ensureTrainingKnowledgeBases 同源),入门库已初始化的空间同样补齐 ——
|
||||
// CASDOOR/OIDC 自动注册的用户进「知识库」页即可见两个培训默认库。
|
||||
s.ensureTrainingKnowledgeBases(seedCtx, tenant.ID, kbs)
|
||||
|
||||
for _, kb := range kbs {
|
||||
if kb != nil && kb.Name == BootstrapKBName {
|
||||
logger.Infof(ctx, "tenant bootstrap: workspace already seeded, skip: tenant=%d", tenant.ID)
|
||||
@@ -184,6 +192,50 @@ func (s *tenantBootstrapService) SeedTenantDefaults(ctx context.Context, tenant
|
||||
}
|
||||
}
|
||||
|
||||
// ensureTrainingKnowledgeBases 确保「企业培训(课件)/(题库)」两个系统默认库
|
||||
// 存在(按 Source 标记去重,缺失即建,已存在跳过;模型由 CreateKnowledgeBase
|
||||
// 的默认兜底自动绑定)。与培训域 trainingService.ensureTrainingKnowledgeBases
|
||||
// 完全同源:后续培训上传/题库导入按同一 Source 标记复用这里的库,不会重复建档。
|
||||
// fail-open:单库失败仅记日志,不阻断注册/建租户主流程。
|
||||
func (s *tenantBootstrapService) ensureTrainingKnowledgeBases(ctx context.Context, tenantID uint64, existing []*types.KnowledgeBase) {
|
||||
if s.kbService == nil {
|
||||
return
|
||||
}
|
||||
hasSource := func(source string) bool {
|
||||
for _, kb := range existing {
|
||||
if kb != nil && kb.Source == source {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
seeds := []struct {
|
||||
source string
|
||||
name string
|
||||
description string
|
||||
}{
|
||||
{types.KnowledgeBaseSourceTrainingCourseware, trainingCoursewareKBName, trainingCoursewareKBDescription},
|
||||
{types.KnowledgeBaseSourceTrainingQuestionBank, trainingQuestionBankKBName, trainingQuestionBankKBDescription},
|
||||
}
|
||||
for _, seed := range seeds {
|
||||
if hasSource(seed.source) {
|
||||
continue
|
||||
}
|
||||
created, err := s.kbService.CreateKnowledgeBase(ctx, &types.KnowledgeBase{
|
||||
Name: seed.name,
|
||||
Description: seed.description,
|
||||
Source: seed.source,
|
||||
})
|
||||
if err != nil {
|
||||
logger.Warnf(ctx, "tenant bootstrap: ensure training KB failed: tenant=%d source=%s err=%v",
|
||||
tenantID, seed.source, err)
|
||||
continue
|
||||
}
|
||||
logger.Infof(ctx, "tenant bootstrap: training KB ensured: tenant=%d kb=%s source=%s",
|
||||
tenantID, created.ID, seed.source)
|
||||
}
|
||||
}
|
||||
|
||||
// PickDefaultModelID returns the tenant-visible default model of the given
|
||||
// type: the is_default row first, then the first active row. Empty string
|
||||
// when the deployment has no usable model of that type. Shared by the
|
||||
|
||||
Reference in new issue
Block a user