Skip to content

Conversation

@ashtonmeuser
Copy link

This adds a static pruneModels(in:excluding:) method to DownloadModel.

Addresses #63.

This allows for maintaining a single canonical model in an app via:

let model = LLMSession.DownloadModel.llama(
    id: "Qwen/Qwen2.5-1.5B-Instruct-GGUF",
    model: "qwen2.5-1.5b-instruct-q4_k_m.gguf",
)

LLMSession.DownloadModel.pruneModels(excluding: [model])

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @ashtonmeuser, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a new capability to efficiently manage downloaded language models by allowing applications to prune (delete) models that are no longer needed. This is achieved through a new static method that can remove all models in a given directory except for a specified set, ensuring that only desired models are retained and storage is optimized. This feature directly addresses the need for better storage management for downloaded models.

Highlights

  • Model Pruning Functionality: Introduced a static pruneModels(in:excluding:) method within LLMSession.DownloadModel to enable the removal of downloaded models, excluding specified ones, directly addressing issue Expose a way to manage downloaded models #63.
  • Directory Cleanup Utility: Added a recursive removeEmptyFolders() extension to URL to efficiently clean up empty directories after model pruning operations.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a useful feature for pruning downloaded models to manage storage. The implementation is mostly solid, with a new pruneModels static method on LLMSession.DownloadModel and a helper removeEmptyFolders extension on URL.

My review includes a few suggestions to improve performance, correctness, and error handling:

  • Using a Set for excluded models to speed up lookups.
  • Ensuring all model types with a path are handled correctly during pruning.
  • Improving error propagation by avoiding try? where it can mask issues.

These changes will make the pruning feature more robust and efficient.

Copy link
Owner

@tattn tattn left a comment

Choose a reason for hiding this comment

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

@ashtonmeuser Thank you for this PR!
After reviewing it, I think the interface looks good 😄
Once the review points are addressed, I’d like to go ahead and merge it.

If possible, it would also be great to add some tests.

Comment on lines +20 to +21
let excludingURLsNormalized: Set<URL> = Set(excludingURLs.map { $0.resolvingSymlinksInPath().standardizedFileURL
})
Copy link
Author

@ashtonmeuser ashtonmeuser Sep 25, 2025

Choose a reason for hiding this comment

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

URL normalization done in FileManager.removeAllItems. Could be done outside instead.

}
}

if removingEmptyDirectories { try removeEmptyDirectories(in: url) }
Copy link
Author

Choose a reason for hiding this comment

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

Added argument to optionally skip pruning empty directories.

Comment on lines +311 to +315
switch model {
case let model as LLMSession.DownloadModel: model.modelPath
case let model as LLMSession.LocalModel: model.modelPath
default: nil
}
Copy link
Author

Choose a reason for hiding this comment

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

It might make sense for these models (DownloadModel and LocalModel) to share a protocol to avoid weird cases like this. Especially given that they share so much in common it's a bit odd for them to be siblings with redefined properties e.g. modelPath.

Copy link
Owner

Choose a reason for hiding this comment

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

You’re absolutely right. I’d like to refactor this in the future.

@ashtonmeuser
Copy link
Author

@ashtonmeuser Thank you for this PR! After reviewing it, I think the interface looks good 😄 Once the review points are addressed, I’d like to go ahead and merge it.

If possible, it would also be great to add some tests.

Comments addressed. I'm having some troubles running the tests locally but will continue trying in order to add tests.

@tattn
Copy link
Owner

tattn commented Sep 26, 2025

APIs and logic look good to me. Thank you so much for addressing the review comments! 😄
I’ll go ahead and merge this after the tests are added. Please let me know if any troubles remain unresolved.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants