Skip to content

Conversation

@bmahabirbu
Copy link
Collaborator

@bmahabirbu bmahabirbu commented Sep 18, 2025

Summary by Sourcery

Add a --default-template flag to skip loading model-specific chat template files and use the runtime's default chat template instead, wiring this option through the CLI, service command factory, model container generation, and documentation.

New Features:

  • Introduce --default-template CLI option for run and serve commands
  • Apply default_template flag to skips adding model-specific chat-template-file in llama serve and container config generation
  • Honor default_template flag in daemon command factory when building llama serve commands

Enhancements:

  • Refactor chat template path handling to conditionally include template based on default_template flag
  • Unify chat template paths into a single tuple or None in container config generation

Documentation:

  • Document --default-template option in ramalama-run and ramalama-serve man pages

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Summary of Changes

Hello @bmahabirbu, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the ramalama tool by adding a --default-template flag to the run and serve commands. This new option provides users with greater control over how chat templates are applied, allowing them to choose the runtime's default template instead of any model-specific ones. This is particularly useful for models that may not have an embedded template or when a generic template is preferred, streamlining the model interaction process.

Highlights

  • New Feature Flag: Introduced a new command-line flag, --default-template, for the ramalama run and ramalama serve commands.
  • Chat Template Control: This flag allows users to explicitly opt out of using model-specific chat template files, instead relying on the runtime's built-in default template handling.
  • Conditional Template Application: The logic for preparing and applying chat templates in both direct execution and container configuration generation has been updated to respect the presence of this new flag.
  • Documentation Update: The man pages for ramalama-run and ramalama-serve have been updated to include the description of the new --default-template flag.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Sep 18, 2025

Reviewer's Guide

Introduces a new --default-template flag that, when enabled, bypasses model-specific chat template file handling across runtime commands, container config generation, and daemon service invocations by conditionally skipping template path retrieval and passing None; argument parsing and documentation are updated accordingly.

File-Level Changes

Change Details Files
Gate chat template file inclusion in llama_serve based on default_template flag
  • Extract args.default_template into use_default_template
  • Wrap chat_template_path retrieval and exec_args append in "if not use_default_template"
ramalama/model.py
Refactor generate_container_config to conditionally prepare chat_template_paths
  • Check args.default_template to set chat_template_src/dest to None or call _get_chat_template_path
  • Build chat_template_paths tuple or None
  • Replace direct chat_template_src_path/chat_template_dest_path in generate calls
ramalama/model.py
Apply default-template gating in service command factory
  • Fetch default_template from request_args
  • Wrap chat_template_path lookup and cmd append in "if not use_default_template"
ramalama/daemon/service/command_factory.py
Add --default-template parser option for run and serve commands
  • Add parser.add_argument for --default-template with store_true action
  • Scope flag to run and serve command contexts
ramalama/cli.py
Document the new --default-template option in man pages
  • Add description of default-template flag in ramalama-run.1.md
  • Add description of default-template flag in ramalama-serve.1.md
docs/ramalama-run.1.md
docs/ramalama-serve.1.md

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!

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 there - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location> `ramalama/daemon/service/command_factory.py:86-90` </location>
<code_context>
-            if chat_template_path:
-                cmd += ["--chat-template-file", chat_template_path]
+            # Add chat template unless using default template
+            use_default_template = self.request_args.get("default_template", False)
+            if not use_default_template:
+                chat_template_path = self.model._get_chat_template_path(False, False, False)
+                if chat_template_path:
</code_context>

<issue_to_address>
**suggestion (bug_risk):** Type coercion for 'default_template' from request_args may be needed.

Explicitly convert 'default_template' to a boolean to prevent logic errors from string values like 'false' or '0'.

```suggestion
            raw_default_template = self.request_args.get("default_template", False)
            # Coerce to boolean: treat 'false', '0', '', None as False, everything else as True
            if isinstance(raw_default_template, str):
                use_default_template = raw_default_template.lower() in ("true", "1", "yes")
            else:
                use_default_template = bool(raw_default_template)
            if not use_default_template:
                chat_template_path = self.model._get_chat_template_path(False, False, False)
                if chat_template_path:
                    cmd += ["--chat-template-file", chat_template_path]
```
</issue_to_address>

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 +86 to +90
use_default_template = self.request_args.get("default_template", False)
if not use_default_template:
chat_template_path = self.model._get_chat_template_path(False, False, False)
if chat_template_path:
cmd += ["--chat-template-file", chat_template_path]
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): Type coercion for 'default_template' from request_args may be needed.

Explicitly convert 'default_template' to a boolean to prevent logic errors from string values like 'false' or '0'.

Suggested change
use_default_template = self.request_args.get("default_template", False)
if not use_default_template:
chat_template_path = self.model._get_chat_template_path(False, False, False)
if chat_template_path:
cmd += ["--chat-template-file", chat_template_path]
raw_default_template = self.request_args.get("default_template", False)
# Coerce to boolean: treat 'false', '0', '', None as False, everything else as True
if isinstance(raw_default_template, str):
use_default_template = raw_default_template.lower() in ("true", "1", "yes")
else:
use_default_template = bool(raw_default_template)
if not use_default_template:
chat_template_path = self.model._get_chat_template_path(False, False, False)
if chat_template_path:
cmd += ["--chat-template-file", chat_template_path]

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a new --default-template flag for the run and serve commands, allowing users to bypass model-specific chat templates in favor of the runtime's default. The implementation is solid, with corresponding updates to documentation, command-line argument parsing, and the underlying command generation logic. I have one suggestion to improve code conciseness in ramalama/model.py.

Comment on lines +749 to +759
# Get chat template paths unless using default template
use_default_template = getattr(args, 'default_template', False)
if use_default_template:
chat_template_src_path = None
chat_template_dest_path = None
else:
chat_template_src_path = self._get_chat_template_path(False, False, args.dryrun)
chat_template_dest_path = self._get_chat_template_path(True, True, args.dryrun)

# Prepare chat template paths tuple or None
chat_template_paths = None if chat_template_src_path is None else (chat_template_src_path, chat_template_dest_path)
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This logic for determining chat_template_paths can be simplified for better readability and conciseness. You can initialize chat_template_paths to None and then update it inside a single if block. This avoids defining chat_template_src_path and chat_template_dest_path in a wider scope than necessary.

Suggested change
# Get chat template paths unless using default template
use_default_template = getattr(args, 'default_template', False)
if use_default_template:
chat_template_src_path = None
chat_template_dest_path = None
else:
chat_template_src_path = self._get_chat_template_path(False, False, args.dryrun)
chat_template_dest_path = self._get_chat_template_path(True, True, args.dryrun)
# Prepare chat template paths tuple or None
chat_template_paths = None if chat_template_src_path is None else (chat_template_src_path, chat_template_dest_path)
# Get chat template paths unless using default template
use_default_template = getattr(args, 'default_template', False)
chat_template_paths = None
if not use_default_template:
chat_template_src_path = self._get_chat_template_path(False, False, args.dryrun)
if chat_template_src_path is not None:
chat_template_dest_path = self._get_chat_template_path(True, True, args.dryrun)
chat_template_paths = (chat_template_src_path, chat_template_dest_path)

@rhatdan
Copy link
Member

rhatdan commented Sep 18, 2025

Would it make more sense to allow the user to specify a chat template --chat-templat /tmp/chat.template? And then have --chat-template none or --chat-template default?

@engelmi
Copy link
Member

engelmi commented Sep 19, 2025

Would it make more sense to allow the user to specify a chat template --chat-templat /tmp/chat.template? And then have --chat-template none or --chat-template default?

Yes, I think having a --chat-template-file <path> would be great and aligns with what llama-server does. This RamaLama CLI option would have the highest priority, followed by the extracted chat template and, finally, using the inference engines default template as a fallback. I think we discussed this at one point, but lost track of it.

@rhatdan
Copy link
Member

rhatdan commented Sep 22, 2025

When running within the container, the --chat-template option would have to volume mount the path into the container. This would complicate the use of quadlets and kube.yaml, but for now lets just add this and we would have to point out that this would need ot be handled within an image if a user put the AI into production. Potentially having the user ship the template within the container. --chat-template=none would just remove the --chat-template option from the inference engine.

@github-actions
Copy link

A friendly reminder that this PR had no activity for 30 days.

@rhatdan
Copy link
Member

rhatdan commented Nov 3, 2025

@bmahabirbu Should this PR be closed or are you still working on it?

@github-actions github-actions bot removed the stale-pr label Nov 4, 2025
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