Skip to content

Conversation

@martacarbone
Copy link
Contributor

Motivation

This PR adds a deletion endpoint for models.

To ensure safety, a model is removed only if it is not in use by a running application and is not referenced by any other models.

Change description

Additional Notes

Reviewer checklist

  • PR addresses a single concern.
  • PR title and description are properly filled.
  • Changes will be merged in main.
  • Changes are covered by tests.
  • Logging is meaningful in case of troubleshooting.
@per1234 per1234 added the enhancement New feature or request label Jan 28, 2026
idProvider, cfg)

if err != nil {
return nil, errors.New("error retrieving applications.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i would retutn the internal err

Comment on lines +84 to +86
render.EncodeResponse(w, http.StatusNotFound, models.ErrorResponse{Details: err.Error()})
case errors.Is(err, orchestrator.ErrConflict):
render.EncodeResponse(w, http.StatusConflict, models.ErrorResponse{Details: err.Error()})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return an errorResponse also here to have json formatted

}

if res.IsPreinstalled {
return fmt.Errorf("model %s is a pre-installed model: %w", id, ErrConflict)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would return a sentinel error only

Suggested change
return fmt.Errorf("model %s is a pre-installed model: %w", id, ErrConflict)
return ErrCannotRemoveModel
return nil
}

func isModelReferencedInApp(ctx context.Context, dockerClient command.Cli, cfg config.Configuration, idProvider *app.IDProvider, modelId string) ([]string, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would return the list of apps that have at least one reference to that model.
It is possible that an app has multiple bricks pointing to the same model

Comment on lines +111 to +113
if running != nil {
sb.WriteString(fmt.Sprintf("The model %s is in use by the %s app. Stop the application before removing the model", id, running.Name))
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could separate the error.
-if running => return the error that the mode is used by a running app.
-if multiple references => return error that a model is referenced by apps.

return fmt.Errorf("%s: %w", sb.String(), ErrConflict)
}

if res.ModelFolderPath == nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should never happen, because every pre-installed must have a path.

We could log the warning but do not raise an error.

)

func AIModelDelete(ctx context.Context, dockerClient command.Cli, cfg config.Configuration, modelsIndex *modelsindex.ModelsIndex, id string, idProvider *app.IDProvider, force bool) (err error) {
res, found := modelsIndex.GetModelByID(id)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would move the removal of the model inside the models-index.go since it will be used also by the CLI command.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

3 participants