Open-source LLM knowledge platform: turn raw documents into a queryable RAG, an autonomous reasoning agent, and a self-maintaining Wiki.
Go agentagenticaichatbotdsh-pluginembeddingsevaluationgenerative-aigolangknowledge-basellmmulti-tenantollamaopenaiquestion-answeringragrerankingsemantic-searchvector-searchwiki
refactor: Remove default model handling from model settings and service
wizardchen865987ed27a5
diff --git a/frontend/src/views/settings/ModelSettings.vue b/frontend/src/views/settings/ModelSettings.vueindex b918f1e3c..1270107c5 100644--- a/frontend/src/views/settings/ModelSettings.vue+++ b/frontend/src/views/settings/ModelSettings.vue@@ -45,7 +45,6 @@<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"><span class="source-tag">{{ model.source === 'local' ? 'Ollama' : $t('modelSettings.source.remote') }}</span>@@ -95,7 +94,6 @@<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"><span class="source-tag">{{ model.source === 'local' ? 'Ollama' : $t('modelSettings.source.remote') }}</span>@@ -146,7 +144,6 @@<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"><span class="source-tag">{{ model.source === 'local' ? 'Ollama' : $t('modelSettings.source.remote') }}</span>@@ -196,7 +193,6 @@<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"><span class="source-tag">{{ model.source === 'local' ? 'Ollama' : $t('modelSettings.source.openaiCompatible') }}</span>@@ -295,7 +291,6 @@ 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,isBuiltin: model.is_builtin || false}}@@ -316,12 +311,6 @@ function deduplicateModels(models: any[]) {})if (seen.has(signature)) {- // 如果已经存在相同的模型,优先保留默认模型- const existing = seen.get(signature)- if (model.isDefault && !existing.isDefault) {- seen.set(signature, model)- return true- }return false}@@ -417,8 +406,7 @@ const handleModelSave = async (modelData: any) => {truncate_prompt_tokens: 0}} : {})- },- is_default: modelData.isDefault || false+ }}if (editingModel.value && editingModel.value.id) {@@ -459,44 +447,15 @@ const deleteModel = async (type: 'chat' | 'embedding' | 'rerank' | 'vllm', model}}-// 设为默认-const setDefault = async (type: 'chat' | 'embedding' | 'rerank' | 'vllm', modelId: string) => {- try {- // 更新模型的 is_default 字段- await updateModelAPI(modelId, { is_default: true })- MessagePlugin.success(t('modelSettings.toasts.setDefault'))- // 重新加载模型列表- await loadModels()- } catch (error: any) {- console.error('设置默认模型失败:', error)- MessagePlugin.error(error.message || t('modelSettings.toasts.setDefaultFailed'))- }-}-// 获取模型操作菜单选项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({- content: t('modelSettings.actions.setDefault'),- value: `set-default-${type}-${model.id}`- })- }-// 编辑选项options.push({content: t('common.edit'),@@ -517,9 +476,7 @@ const getModelOptions = (type: 'chat' | 'embedding' | 'rerank' | 'vllm', model:const handleMenuAction = (data: { value: string }, type: 'chat' | 'embedding' | 'rerank' | 'vllm', model: any) => {const value = data.value- if (value.indexOf('set-default-') === 0) {- setDefault(type, model.id)- } else if (value.indexOf('edit-') === 0) {+ if (value.indexOf('edit-') === 0) {editModel(type, model)} else if (value.indexOf('delete-') === 0) {// 使用确认对话框进行确认diff --git a/internal/application/service/model.go b/internal/application/service/model.goindex 180f7cb23..6782e1e70 100644--- a/internal/application/service/model.go+++ b/internal/application/service/model.go@@ -36,18 +36,6 @@ func NewModelService(repo interfaces.ModelRepository, ollamaService *ollama.Ollafunc (s *modelService) CreateModel(ctx context.Context, model *types.Model) error {logger.Infof(ctx, "Creating model: %s, type: %s, source: %s", model.Name, model.Type, model.Source)- // If this model is set as default, unset other default models of the same type- if model.IsDefault {- logger.Infof(ctx, "Model is set as default, clearing other default models of type: %s", model.Type)- if err := s.clearOtherDefaultModels(ctx, model.TenantID, model.Type, ""); err != nil {- logger.ErrorWithFields(ctx, err, map[string]interface{}{- "model_type": model.Type,- "tenant_id": model.TenantID,- })- return err- }- }-// Handle remote models (e.g., OpenAI, Azure)if model.Source == types.ModelSourceRemote {logger.Info(ctx, "Remote model detected, setting status to active")@@ -192,19 +180,6 @@ func (s *modelService) UpdateModel(ctx context.Context, model *types.Model) erroreturn errors.New("builtin models cannot be updated")}- // If this model is set as default, unset other default models of the same type- if model.IsDefault {- logger.Infof(ctx, "Model is set as default, clearing other default models of type: %s", model.Type)- if err := s.clearOtherDefaultModels(ctx, model.TenantID, model.Type, model.ID); err != nil {- logger.ErrorWithFields(ctx, err, map[string]interface{}{- "model_type": model.Type,- "tenant_id": model.TenantID,- "model_id": model.ID,- })- return err- }- }-// Update model in repositoryerr = s.repo.Update(ctx, model)if err != nil {@@ -371,24 +346,5 @@ func (s *modelService) GetChatModel(ctx context.Context, modelId string) (chat.Creturn chatModel, nil}-// clearOtherDefaultModels sets IsDefault to false for all models of the same type-// except the one with the given ID (if excludeID is not empty)-// This ensures only one default model exists per type per tenant-// Uses batch update for better performance-func (s *modelService) clearOtherDefaultModels(ctx context.Context, tenantID uint, modelType types.ModelType, excludeID string) error {- logger.Infof(ctx, "Clearing other default models for type: %s, tenant: %d, exclude: %s", modelType, tenantID, excludeID)-- // Use batch update to clear default status for all models of this type (excluding the specified ID)- err := s.repo.ClearDefaultByType(ctx, tenantID, modelType, excludeID)- if err != nil {- logger.ErrorWithFields(ctx, err, map[string]interface{}{- "model_type": modelType,- "tenant_id": tenantID,- "exclude_id": excludeID,- })- return err- }-- logger.Infof(ctx, "Successfully cleared other default models for type: %s", modelType)- return nil-}+// Note: default model selection logic has been removed; models no longer+// maintain a per-type default flag at the service layer.diff --git a/internal/application/service/session.go b/internal/application/service/session.goindex 98e23ecf6..fdd31d7a9 100644--- a/internal/application/service/session.go+++ b/internal/application/service/session.go@@ -279,23 +279,18 @@ func (s *sessionService) GenerateTitle(ctx context.Context,modelID := session.SummaryModelIDif modelID == "" {logger.Info(ctx, "Session SummaryModelID is empty, trying to get default chat model")- // Try to get default KnowledgeQA model+ // Try to get an available KnowledgeQA modelmodels, err := s.modelService.ListModels(ctx)if err != nil {logger.ErrorWithFields(ctx, err, nil)return "", fmt.Errorf("failed to list models: %w", err)}- // Find default KnowledgeQA model or first KnowledgeQA model+ // Find first available KnowledgeQA modelfor _, model := range models {if model.Type == types.ModelTypeKnowledgeQA {- if model.IsDefault {- modelID = model.ID- logger.Infof(ctx, "Using default KnowledgeQA model: %s", modelID)- break- } else if modelID == "" {- modelID = model.ID- logger.Infof(ctx, "Using first available KnowledgeQA model: %s", modelID)- }+ modelID = model.ID+ logger.Infof(ctx, "Using first available KnowledgeQA model: %s", modelID)+ break}}if modelID == "" {diff --git a/internal/handler/model.go b/internal/handler/model.goindex db051fd13..464662487 100644--- a/internal/handler/model.go+++ b/internal/handler/model.go@@ -50,7 +50,6 @@ func hideSensitiveInfo(model *types.Model) *types.Model {EmbeddingParameters: model.Parameters.EmbeddingParameters,ParameterSize: model.Parameters.ParameterSize,},- IsDefault: model.IsDefault,IsBuiltin: model.IsBuiltin,Status: model.Status,CreatedAt: model.CreatedAt,@@ -66,7 +65,6 @@ type CreateModelRequest struct {Source types.ModelSource `json:"source" binding:"required"`Description string `json:"description"`Parameters types.ModelParameters `json:"parameters" binding:"required"`- IsDefault bool `json:"is_default"`}// CreateModel handles the HTTP request to create a new model@@ -103,7 +101,6 @@ func (h *ModelHandler) CreateModel(c *gin.Context) {Source: req.Source,Description: req.Description,Parameters: req.Parameters,- IsDefault: req.IsDefault,}if err := h.service.CreateModel(ctx, model); err != nil {@@ -214,7 +211,6 @@ type UpdateModelRequest struct {Name string `json:"name"`Description string `json:"description"`Parameters types.ModelParameters `json:"parameters"`- IsDefault bool `json:"is_default"`Source types.ModelSource `json:"source"`Type types.ModelType `json:"type"`}@@ -264,7 +260,6 @@ func (h *ModelHandler) UpdateModel(c *gin.Context) {if req.Parameters != (types.ModelParameters{}) {model.Parameters = req.Parameters}- model.IsDefault = req.IsDefaultmodel.Source = req.Sourcemodel.Type = req.Type