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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

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
if model.startswith("oci://") or model.startswith("docker://"):
return OCI(model, args.engine)
if model.startswith("http://") or model.startswith("https://") or model.startswith("file://"):
elif (
Copy link
Member

Choose a reason for hiding this comment

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

No elif needed. Just if.

ramalama/cli.py Outdated
return URL(model)
elif model.startswith("oci://") or model.startswith("docker://"):
Copy link
Member

Choose a reason for hiding this comment

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

ditto

@@ -243,3 +243,12 @@ def get_env_vars():
# env_vars[gpu_type] = str(gpu_num)

return env_vars


def rm_until_substring(model, substring):
Copy link
Member

Choose a reason for hiding this comment

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

This should be a function in model.py part of the model class.

Copy link
Collaborator

Choose a reason for hiding this comment

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

+1 for the method.

break

self.type = urlparse(model).scheme
model = rm_until_substring(model, "://")
Copy link
Collaborator

Choose a reason for hiding this comment

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

this ramala/url.py could be in a separate patch. LGTM

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's only 30 lines of code we are changing here

return URL(model)
elif model.startswith("oci://") or model.startswith("docker://"):
return OCI(model, args.engine)
Copy link
Collaborator

Choose a reason for hiding this comment

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

My question is for this one, can we have util.py this seems very useful as generic.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm not against more refactoring in future PRs. What part exactly would go to utils this whole function?

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.

Signed-off-by: Eric Curtin <[email protected]>
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