refactor: Remove default model handling from model settings and service
- Eliminated the 'isDefault' field from model settings and related service logic, simplifying model management. - Updated UI components to remove references to default models, ensuring a cleaner user experience. - Adjusted backend model creation and update processes to reflect the removal of default model selection logic.
This commit is contained in:
@@ -36,18 +36,6 @@ func NewModelService(repo interfaces.ModelRepository, ollamaService *ollama.Olla
|
||||
func (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) erro
|
||||
return 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 repository
|
||||
err = s.repo.Update(ctx, model)
|
||||
if err != nil {
|
||||
@@ -371,24 +346,5 @@ func (s *modelService) GetChatModel(ctx context.Context, modelId string) (chat.C
|
||||
return 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.
|
||||
|
||||
@@ -279,23 +279,18 @@ func (s *sessionService) GenerateTitle(ctx context.Context,
|
||||
modelID := session.SummaryModelID
|
||||
if 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 model
|
||||
models, 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 model
|
||||
for _, 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 == "" {
|
||||
|
||||
@@ -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.IsDefault
|
||||
model.Source = req.Source
|
||||
model.Type = req.Type
|
||||
|
||||
|
||||
Reference in New Issue
Block a user