Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for http, https and file pulls #463

Merged
merged 1 commit into from
Nov 22, 2024
Merged

Conversation

rhatdan
Copy link
Member

@rhatdan rhatdan commented Nov 18, 2024

RamaLama should be able to handle Models stored on web sites as well as previously pulled to the machine.

Summary by Sourcery

Add support for pulling models using http, https, and file URLs, enabling direct execution of models from web or local sources. Update documentation and add tests to cover the new functionality.

New Features:

  • Add support for pulling models using http, https, and file URLs, allowing models to be run directly from web sources or local files.

Enhancements:

  • Refactor the symlink creation process to use os.symlink directly instead of run_cmd.

Documentation:

  • Update documentation to include new URL syntax support for http, https, and file protocols, explaining how models can be pulled from these sources.

Tests:

  • Add system tests to verify the functionality of pulling models using file and https URLs, ensuring they can be listed and removed correctly.

Copy link
Contributor

sourcery-ai bot commented Nov 18, 2024

Reviewer's Guide by Sourcery

This PR adds support for handling models stored on websites (via http/https) and local files by implementing a new URL transport class and refactoring common model functionality. The implementation moves shared model methods from specific transport classes to the base Model class and introduces a new URL transport type that handles http, https, and file protocols.

Sequence diagram for pulling a model using URL transport

sequenceDiagram
    actor User
    participant CLI
    participant URL
    participant Common
    User->>CLI: run_ramalama pull <url>
    CLI->>URL: pull(args)
    URL->>Common: model_path(args)
    URL->>Common: check_valid_model_path(relative_target_path, model_path)
    alt Model is a file
        URL->>Common: os.symlink(model, target_path)
    else Model is a URL
        URL->>Common: download_file(url, target_path)
        URL->>Common: os.symlink(relative_target_path, model_path)
    end
    URL-->>CLI: return model_path
    CLI-->>User: Model pulled successfully
Loading

Class diagram for the new URL transport class

classDiagram
    class Model {
        +login(args)
        +logout(args)
        +pull(args)
        +push(source, args)
        +garbage_collection(args)
        +remove(args)
        +_image(args)
        +kube(model, args, exec_args)
        +path(args)
        +model_path(args)
        +exists(args)
        +check_valid_model_path(relative_target_path, model_path)
    }
    class URL {
        +type: String
        +directory: String
        +filename: String
        +pull(args)
    }
    Model <|-- URL
    note for URL "Handles http, https, and file protocols"
Loading

File-Level Changes

Change Details Files
Implemented new URL transport for handling http, https, and file protocols
  • Created new URL class that inherits from Model
  • Implemented pull method to handle both remote and local file downloads
  • Added symlink creation for file:// protocol
  • Added download functionality for http:// and https:// protocols
ramalama/url.py
Refactored common model functionality into base Model class
  • Moved path(), exists(), model_path(), and check_valid_model_path() methods to base class
  • Removed duplicate implementations from HuggingFace class
  • Added URL transport type to garbage collection paths
ramalama/model.py
ramalama/huggingface.py
Updated CLI and documentation to support new URL transports
  • Added URL transport handling in model creation logic
  • Modified list_models to handle file:/// URL format
  • Updated documentation with new URL transport types
  • Added system tests for file and https URLs
ramalama/cli.py
docs/ramalama.1.md
test/system/050-pull.bats
Improved symlink handling
  • Replaced run_cmd calls with direct os.symlink usage
  • Fixed HuggingFace transport type case consistency
ramalama/huggingface.py

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 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

@@ -112,8 +101,7 @@ def pull(self, args):
# Symlink is already correct, no need to update it
return model_path

run_cmd(["ln", "-sf", relative_target_path, model_path], debug=args.debug)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think I used ln -sf at the time, because os.symlink doesn't overwrite symlinks, so say if we had:

some_ollama_mode -> some_sha256

and we pulled an updated version of the model, so a new sha256, I'm not sure os.symlink overwrites in that case, I think it throws an exception

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok I will change to attempt to remove first and then create the symlink.

@ericcurtin
Copy link
Collaborator

@swarajpande5 PTAL

Summary by Sourcery

Add support for pulling models using http, https, and file URLs, enabling direct
 execution of models from web or local sources. Update documentation and add tes
ts to cover the new functionality.

New Features:

    Add support for pulling models using http, https, and file URLs, allowing mo
dels to be run directly from web sources or local files.

Enhancements:

    Refactor the symlink creation process to use os.symlink directly instead of
run_cmd.

Documentation:

    Update documentation to include new URL syntax support for http, https, and
file protocols, explaining how models can be pulled from these sources.

Tests:

    Add system tests to verify the functionality of pulling models using file an
d https URLs, ensuring they can be listed and removed correctly.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
@rhatdan rhatdan merged commit cffcdc5 into containers:main Nov 22, 2024
11 checks passed
@swarajpande5
Copy link
Contributor

@swarajpande5 PTAL

@ericcurtin Sorry, I was out of town for team meetup. I'll resume contributing to ramalama from November 25th.

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.

3 participants