containers / ramalama

The goal of RamaLama is to make working with AI boring.
MIT License
272 stars 47 forks source link

Attempt to remove OCI Image if removing as Ollama or Huggingface fails #432

Closed rhatdan closed 2 weeks ago

rhatdan commented 2 weeks ago

Summary by Sourcery

Implement a fallback mechanism to remove a model as an OCI Image if removal as Ollama or Huggingface fails, and update the system test accordingly.

Bug Fixes:

Tests:

sourcery-ai[bot] commented 2 weeks ago

Reviewer's Guide by Sourcery

This PR enhances the model removal functionality by adding a fallback mechanism. If removing a model as an Ollama or Huggingface model fails, the system will attempt to remove it as an OCI container image before raising the original error.

Sequence diagram for model removal process

sequenceDiagram
    participant User
    participant CLI as Ramalama CLI
    participant Model as Model
    participant OCI as OCI Image

    User->>CLI: Request to remove model
    CLI->>Model: Attempt to remove as Ollama/Huggingface
    alt Removal successful
        Model-->>CLI: Model removed
    else Removal fails
        CLI->>OCI: Attempt to remove as OCI Image
        alt OCI removal successful
            OCI-->>CLI: OCI Image removed
        else OCI removal fails
            CLI-->>User: Raise original error
        end
    end

File-Level Changes

Change Details Files
Added fallback logic for model removal
  • Wrapped model removal in try-except block
  • Added fallback attempt to remove as OCI container image
  • Original error is re-raised if both attempts fail
ramalama/cli.py
Updated system test for model removal
  • Modified model removal test to use simplified registry path format
test/system/050-pull.bats

Tips and commands #### Interacting with Sourcery - **Trigger a new review:** Comment `@sourcery-ai review` on the pull request. - **Continue discussions:** Reply directly to Sourcery's review comments. - **Generate a GitHub issue from a review comment:** Ask Sourcery to create an issue from a review comment by replying to it. - **Generate a pull request title:** Write `@sourcery-ai` anywhere in the pull request title to generate a title at any time. - **Generate a pull request summary:** Write `@sourcery-ai summary` anywhere in the pull request body to generate a PR summary at any time. You can also use this command to specify where the summary should be inserted. #### Customizing Your Experience Access your [dashboard](https://app.sourcery.ai) to: - Enable or disable review features such as the Sourcery-generated pull request summary, the reviewer's guide, and others. - Change the review language. - Add, remove or edit custom review instructions. - Adjust other review settings. #### Getting Help - [Contact our support team](mailto:support@sourcery.ai) for questions or feedback. - Visit our [documentation](https://docs.sourcery.ai) for detailed guides and information. - Keep in touch with the Sourcery team by following us on [X/Twitter](https://x.com/SourceryAI), [LinkedIn](https://www.linkedin.com/company/sourcery-ai/) or [GitHub](https://github.com/sourcery-ai).