feat(tenant): 新空间开箱即用:自动初始化默认模型配置
- 新增 TenantBootstrapService:建空间后自动创建「新手入门」知识库 (绑定内置默认对话/向量化模型)、预置欢迎文档(走标准上传管道)、 配置租户级检索重排模型;整体 fail-open 且幂等,不阻断主流程 - 挂钩 Register(普通注册与 OIDC 首登自动开户均覆盖)与手动创建 工作区接口,内置模型宿主租户(10000)跳过 - CreateKnowledgeBase / CreateAgent 空的必填模型字段自动落系统默认 (is_default 优先,否则该类型第一个 active),API 直调路径同样兜底 - 自动化编辑器模型选择预填系统默认对话模型
This commit is contained in:
1 parent
4b899a4647
commit
3a578153bb
11 files changed
+344
-13
No files matched your search
@@ -44,6 +44,10 @@ type customAgentService struct {
|
||||
tagRepo interfaces.KnowledgeTagRepository
|
||||
knowledgeRepo interfaces.KnowledgeRepository
|
||||
agentShareRepo interfaces.AgentShareRepository
|
||||
// modelService is optional (nil in some unit tests) and only used by
|
||||
// the create-time fallback that fills an empty Config.ModelID with the
|
||||
// tenant-visible default chat model (out-of-the-box experience).
|
||||
modelService interfaces.ModelService
|
||||
}
|
||||
|
||||
// NewCustomAgentService creates a new custom agent service
|
||||
@@ -56,6 +60,7 @@ func NewCustomAgentService(
|
||||
tagRepo interfaces.KnowledgeTagRepository,
|
||||
knowledgeRepo interfaces.KnowledgeRepository,
|
||||
agentShareRepo interfaces.AgentShareRepository,
|
||||
modelService interfaces.ModelService,
|
||||
) interfaces.CustomAgentService {
|
||||
return &customAgentService{
|
||||
repo: repo,
|
||||
@@ -66,6 +71,7 @@ func NewCustomAgentService(
|
||||
tagRepo: tagRepo,
|
||||
knowledgeRepo: knowledgeRepo,
|
||||
agentShareRepo: agentShareRepo,
|
||||
modelService: modelService,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,6 +116,17 @@ func (s *customAgentService) CreateAgent(ctx context.Context, agent *types.Custo
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 开箱即用兜底:主对话模型为空时自动落到系统默认(内置 is_default
|
||||
// 优先,否则该类型第一个 active)。fail-open:解析不到保持为空,
|
||||
// 运行时的 "chat model is not configured" 报错行为与现状一致。
|
||||
if strings.TrimSpace(agent.Config.ModelID) == "" && s.modelService != nil {
|
||||
if models, err := s.modelService.ListModels(ctx); err == nil {
|
||||
agent.Config.ModelID = PickDefaultModelID(models, types.ModelTypeKnowledgeQA)
|
||||
} else {
|
||||
logger.Warnf(ctx, "agent create: default model fallback lookup failed: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
logger.Infof(ctx, "Creating custom agent, ID: %s, tenant ID: %d, name: %s, agent_mode: %s",
|
||||
agent.ID, agent.TenantID, agent.Name, agent.Config.AgentMode)
|
||||
|
||||
|
||||
Reference in new issue
Block a user