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

Fix up handling of image selection on generate #856

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

Conversation

rhatdan
Copy link
Member

@rhatdan rhatdan commented Feb 19, 2025

Also fall back to trying OCI images on ramalama run and serve.

Summary by Sourcery

This pull request modifies the application to improve image selection and handling, particularly when using run and serve commands. It introduces a fallback mechanism to attempt using OCI images if the initial image type fails. Additionally, it refactors the Quadlet and Kube classes to receive the image as a parameter, ensuring correct image usage in container configurations.

Bug Fixes:

  • Fixes an issue where the application would not attempt to use OCI images when the initially specified image type failed, specifically in run and serve commands.

Enhancements:

  • Modifies the Quadlet and Kube classes to receive the image as a parameter during initialization, ensuring the correct image is used for container configuration.
  • Improves image handling by ensuring the correct image is used when generating container configurations.

Copy link
Contributor

sourcery-ai bot commented Feb 19, 2025

Reviewer's Guide by Sourcery

This pull request introduces fallback logic to use OCI images when the initial attempt to load a model fails. It also modifies the Quadlet and Kube classes to accept an image parameter during initialization. A system test was added to verify ramalama serve and ramalama stop commands work as expected.

Updated class diagram for Quadlet

classDiagram
  class Quadlet {
    -ai_image: str
    -model: str
    -args: dict
    -exec_args: list
    -image: str
    +__init__(model: str, image: str, args: dict, exec_args: list)
    +kube()
    +generate()
  }
  note for Quadlet "The image parameter was added to the constructor."
Loading

Updated class diagram for Kube

classDiagram
  class Kube {
    -ai_image: str
    -model: str
    -args: dict
    -exec_args: list
    -image: str
    +__init__(model: str, image: str, args: dict, exec_args: list)
    +gen_volumes()
  }
  note for Kube "The image parameter was added to the constructor."
Loading

File-Level Changes

Change Details Files
Added fallback logic to use OCI images if the initial attempt to use a model fails in run_cli and serve_cli functions.
  • Wrapped the initial model loading and execution in a try...except block.
  • In the except block, attempted to load the model as an OCI image.
  • Re-raised the original exception if the OCI image loading also fails.
ramalama/cli.py
Modified the Quadlet and Kube classes to accept an image parameter during initialization.
  • Updated the constructors of Quadlet and Kube to receive an image parameter.
  • The image parameter is now used to set the image in the quadlet generation.
  • The New class now sets the image before generating the container config.
ramalama/model.py
ramalama/quadlet.py
ramalama/kube.py
Added a system test to verify ramalama serve and ramalama stop commands work as expected.
  • Added a test case that starts a service using ramalama serve.
  • Added a test case that stops the service using ramalama stop.
test/system/055-convert.bats

Possibly linked issues


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

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 @rhatdan - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider consolidating the duplicated try-except blocks in run_cli and serve_cli into a single function.
  • It looks like the image attribute is being passed around to multiple classes; consider if there's a better way to manage this shared state.
Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟡 Testing: 1 issue found
  • 🟢 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 +848 to +851
except Exception:
raise e
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (bug_risk): Re-raising the original KeyError in the fallback may mask the actual OCI error.

If the OCI branch fails, its underlying error will be lost. Consider chaining the exceptions or re-raising the OCI error to better surface the true cause.

Suggested change
except Exception:
raise e
except Exception as oci_error:
raise oci_error from e

Comment on lines 49 to 50
run_ramalama serve -t ${cname} -d tiny ramalama/tiny
run_ramalama stop -t ${cname}
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (testing): Consider adding tests for the fallback behavior.

Since the PR description mentions a fallback to OCI images, it's important to verify this behavior with dedicated tests. Try serving/running a model that doesn't exist as a New model, but does exist as an OCI image, and confirm the fallback logic works as expected. This would involve testing the try...except blocks in run_cli and serve_cli.

@rhatdan rhatdan force-pushed the kube branch 6 times, most recently from 95364d4 to a706567 Compare February 21, 2025 16:28
Copy link
Collaborator

@ericcurtin ericcurtin left a comment

Choose a reason for hiding this comment

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

Haven't looked at why the tests are failing or anything but the code looks fine

Also fall back to trying OCI images on ramalama run and serve.

Signed-off-by: Daniel J Walsh <[email protected]>
@rhatdan
Copy link
Member Author

rhatdan commented Feb 21, 2025

The issue is an older version of podman, I believe in Ubuntu.

@ericcurtin
Copy link
Collaborator

The issue is an older version of podman, I believe in Ubuntu.

There's a super hacky "Upgrade to podman 5" stage in at least some of our builds. I think it was installing Ubuntu 24.10 podman on Ubuntu 24.04

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