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 == "" {
|
||||
|
||||
Reference in New Issue
Block a user