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

Parse https://ollama.com/library/ syntax #648

Merged
merged 1 commit into from
Feb 10, 2025
Merged

Parse https://ollama.com/library/ syntax #648

merged 1 commit into from
Feb 10, 2025

Conversation

ericcurtin
Copy link
Collaborator

@ericcurtin ericcurtin commented Jan 29, 2025

People search for ollama models using the web ui, this change allows one to copy the url from the browser and for it to be compatible with ramalama run.

Summary by Sourcery

New Features:

  • Added support for parsing Ollama model URLs copied from the web UI.

Copy link
Contributor

sourcery-ai bot commented Jan 29, 2025

Reviewer's Guide by Sourcery

This pull request introduces support for parsing Ollama model URLs from the ollama.com/library domain, enhancing the compatibility of llama-run with web UI searches. It also refactors the way model prefixes are handled, using a new rm_until_substring function to remove prefixes from model strings.

Class diagram showing model handling classes

classDiagram
    class Model {
        <<abstract>>
        +String model
        +String type
    }

    class Huggingface {
        +String type
        +__init__(model)
    }

    class Ollama {
        +String type
        +__init__(model)
        +_local(args)
    }

    class OCI {
        +String type
        +__init__(model, conman)
    }

    class URL {
        +String type
        +__init__(model)
    }

    Model <|-- Huggingface
    Model <|-- Ollama
    Model <|-- OCI
    Model <|-- URL

    note for Model "Base class for all model types"
    note for Ollama "Now supports ollama.com/library URLs"
Loading

File-Level Changes

Change Details Files
Added support for parsing Ollama model URLs from ollama.com/library.
  • Added a condition to check if the model starts with https://ollama.com/library/.
  • Modified the conditional logic to prioritize local file paths and URLs over Ollama models.
  • The default case now handles ollama:// or no prefix.
ramalama/cli.py
Refactored model prefix handling using rm_until_substring.
  • Introduced a new rm_until_substring function in ramalama/common.py to remove prefixes from model strings.
  • Replaced multiple removeprefix calls with rm_until_substring in ramalama/oci.py.
  • Replaced multiple removeprefix calls with rm_until_substring in ramalama/url.py.
  • Replaced multiple removeprefix calls with rm_until_substring in ramalama/huggingface.py.
  • Replaced multiple removeprefix calls with rm_until_substring in ramalama/ollama.py.
ramalama/oci.py
ramalama/url.py
ramalama/huggingface.py
ramalama/ollama.py
ramalama/common.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. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the 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 exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

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

@ericcurtin
Copy link
Collaborator Author

@swarajpande5 PTAL

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @ericcurtin - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Critical bug in rm_until_substring: The function returns only one character after the substring instead of the remainder of the string. Change return string[index + len(substring)] to return string[index + len(substring):]
Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines 248 to 251
def rm_until_substring(string, substring):
index = string.find(substring)
if index != -1:
return string[index + len(substring)]
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (bug_risk): Bug: Function returns only one character after the substring instead of the entire remaining string

The array indexing should be removed to return the full remaining string: return string[index + len(substring):]

ramalama/common.py Outdated Show resolved Hide resolved
@ericcurtin ericcurtin force-pushed the ollama-com-proto branch 5 times, most recently from 7fa046b to e0c3f04 Compare January 29, 2025 11:22
ramalama/cli.py Outdated Show resolved Hide resolved
ramalama/cli.py Outdated Show resolved Hide resolved
ramalama/common.py Outdated Show resolved Hide resolved
@ericcurtin ericcurtin force-pushed the ollama-com-proto branch 2 times, most recently from e15ffdf to d100ba4 Compare January 30, 2025 15:51
@ericcurtin ericcurtin force-pushed the ollama-com-proto branch 2 times, most recently from 66d084e to dda3e6f Compare February 9, 2025 22:07
@ericcurtin
Copy link
Collaborator Author

This is ready @rhatdan @swarajpande5

model = model.removeprefix("huggingface://")
model = model.removeprefix("hf://")
model = model.removeprefix("hf.co/")
model = rm_until_substring(model, "hf.co/")
Copy link
Member

Choose a reason for hiding this comment

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

Why are you dropping hugginface://?

Copy link
Collaborator Author

@ericcurtin ericcurtin Feb 10, 2025

Choose a reason for hiding this comment

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

It's not dropped, at this point of the code, we have already verified/validated the start of the protocol is fine, so we do a more generic:

model = rm_until_substring(model, "://")

Copy link
Member

Choose a reason for hiding this comment

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

Right thanks.

Just need tests.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

if model.startswith("huggingface://") or model.startswith("hf://") or model.startswith("hf.co/"):

@rhatdan
Copy link
Member

rhatdan commented Feb 10, 2025

Please add tests.

@ericcurtin
Copy link
Collaborator Author

Added test, also took the opportunity to change the test from tinyllama to smollm, has a much smaller pull size, will accelerate the test

@rhatdan
Copy link
Member

rhatdan commented Feb 10, 2025

LGTM, Merge once test pass.

People search for ollama models using the web ui, this change
allows one to copy the url from the browser and for it to be
compatible with ramalama run.

Also pull smaller models "smollm" to accelerate the builds.

Signed-off-by: Eric Curtin <[email protected]>
@rhatdan rhatdan merged commit a28d9f4 into main Feb 10, 2025
12 of 16 checks passed
@ericcurtin ericcurtin deleted the ollama-com-proto branch February 10, 2025 17:09
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