-
Notifications
You must be signed in to change notification settings - Fork 272
feat: added new flag default-template for models to use tools #1946
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
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Brian <[email protected]>
There was a problem hiding this 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 theramalama runandramalama servecommands. - 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-runandramalama-servehave been updated to include the description of the new--default-templateflag.
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
-
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. ↩
Reviewer's GuideIntroduces 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
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this 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>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| 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] |
There was a problem hiding this comment.
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'.
| 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] |
There was a problem hiding this 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.
| # 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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
| # 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) |
|
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 |
|
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. |
|
A friendly reminder that this PR had no activity for 30 days. |
|
@bmahabirbu Should this PR be closed or are you still working on it? |
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:
Enhancements:
Documentation: