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 ramalama run --keepalive option #789

Merged
merged 1 commit into from
Feb 12, 2025
Merged

Conversation

rhatdan
Copy link
Member

@rhatdan rhatdan commented Feb 11, 2025

Summary by Sourcery

Add a '--keepalive' option to the 'ramalama run' command to specify the duration for keeping a model loaded, update documentation and tests accordingly, and introduce an exit code for timeout scenarios.

New Features:

  • Introduce a '--keepalive' option to the 'ramalama run' command, allowing users to specify a duration to keep a model loaded.

Enhancements:

  • Add exit code 124 to indicate that the RamaLama command did not exit within the keepalive time.

Documentation:

  • Update documentation to include the new '--keepalive' option and its usage in the 'ramalama run' command.

Tests:

  • Add a new test case to verify the functionality of the '--keepalive' option in the 'ramalama run' command.

Copy link
Contributor

sourcery-ai bot commented Feb 11, 2025

Reviewer's Guide by Sourcery

This pull request introduces a new '--keepalive' option to allow models to remain loaded for a specified duration. The changes include updates to documentation, CLI parsing, model execution logic, and system tests, along with some code style improvements in related modules.

Sequence diagram for the new '--keepalive' command execution

sequenceDiagram
    actor U as User
    participant CLI as CLI Parser
    participant M as Model.run
    participant EM as execute_model

    U->>CLI: Execute command "ramalama run --keepalive 10m file:///tmp/mymodel"
    CLI-->>M: Parse args (including --keepalive)
    M->>M: Build prompt and determine model_path
    M->>M: Build exec_args via build_exec_args_run()
    alt If --keepalive is present
        M->>M: Prepend ["timeout", args.keepalive] to exec_args
    end
    M->>EM: Call execute_model(model_path, exec_args, args)
    EM-->>U: Run model with timeout enforced
Loading

Updated class diagram for Model with '--keepalive' support

classDiagram
    class Model {
      +run(args)
      +build_prompt(args)
      +get_model_path(args)
      +build_exec_args_run(args, model_path, prompt)
      +execute_model(model_path, exec_args, args)
    }
    note for Model "Updated run method: if args.keepalive is provided, prepend 'timeout' command to exec_args"
Loading

File-Level Changes

Change Details Files
Added '--keepalive' documentation and usage instructions
  • Updated the manual page to document the '--keepalive' option and its syntax
  • Provided an example usage that shows how to run a model for 10 minutes
  • Added new exit code documentation for timeout behavior due to keepalive
docs/ramalama-run.1.md
Integrated '--keepalive' functionality into model execution
  • Modified the execution logic to wrap the command with a 'timeout' when '--keepalive' is provided
  • Adjusted argument handling in model execution to incorporate the keepalive duration
ramalama/model.py
Enhanced CLI argument parsing to support '--keepalive'
  • Added a new argument '--keepalive' in the parser to accept a duration parameter
  • Updated help text in the CLI parser to document the new option
ramalama/cli.py
Added system test for '--keepalive' functionality
  • Introduced a new test case to ensure the model execution respects the keepalive timeout
  • Validated that the command exits with the expected exit code when exceeded
test/system/030-run.bats
Minor code style and formatting improvements
  • Normalized whitespace and formatting in the default_ollama_caches list
  • Aligned assignment spacing and replaced colon characters consistently
ramalama/ollama.py
ramalama/model.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

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 adding a default value for the --keepalive option to improve user experience and prevent potential errors if the user forgets to specify a duration.
  • Ensure that the new --keepalive option is clearly explained in the documentation, including examples of valid input formats and any constraints or limitations.
Here's what I looked at during the review
  • 🟡 General issues: 2 issues 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.

ramalama/cli.py Outdated
@@ -820,6 +820,7 @@ def run_parser(subparsers):
default="none",
help="set the network mode for the container",
)
parser.add_argument("--keepalive", help="Duration to keep a model loaded (e.g. 5m)")
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: Consider specifying a type for the '--keepalive' argument.

Explicitly assigning a type (e.g., string or a duration type) could help ensure consistent input formats and improve clarity for users of the CLI.

Suggested change
parser.add_argument("--keepalive", help="Duration to keep a model loaded (e.g. 5m)")
parser.add_argument("--keepalive", type=str, help="Duration to keep a model loaded (e.g. 5m)")

Comment on lines 71 to 77
@test "ramalama run --keepalive" {
run_ramalama 124 run --keepalive 1s tiny "Write a 1 line poem"
}
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 more test cases for the --keepalive option.

The current test only checks if the command runs with the --keepalive option. It would be beneficial to add more test cases to verify different durations and edge cases, such as very short durations, invalid duration formats, and ensuring the process terminates as expected after the specified duration.

Suggested change
@test "ramalama run --keepalive" {
run_ramalama 124 run --keepalive 1s tiny "Write a 1 line poem"
}
@test "ramalama run --keepalive" {
run_ramalama 124 run --keepalive 1s tiny "Write a 1 line poem"
}
@test "ramalama run --keepalive with 2s duration" {
run_ramalama 124 run --keepalive 2s tiny "Write a 1 line poem"
[ "$status" -eq 0 ]
}
@test "ramalama run --keepalive with very short duration (0.5s)" {
run_ramalama 124 run --keepalive 0.5s tiny "Write a 1 line poem"
[ "$status" -eq 0 ]
}
@test "ramalama run --keepalive with invalid duration format" {
run_ramalama 124 run --keepalive invalid tiny "Write a 1 line poem"
[ "$status" -ne 0 ]
}

@@ -70,9 +73,9 @@ ramalama run granite
>
```

Run command with local downloaoded model
Run command with local downloaoded model for 10 minutes
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (typo): Typo in 'downloaoded', should be 'downloaded'.

Suggested change
Run command with local downloaoded model for 10 minutes
Run command with local downloaded model for 10 minutes

@rhatdan rhatdan force-pushed the keepalive branch 4 times, most recently from ec8d360 to 544bd85 Compare February 11, 2025 21:01
@ericcurtin ericcurtin merged commit 96cd5a3 into containers:main Feb 12, 2025
17 checks passed
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