From f8bb2239249937bb58eeb99d130959dff719e6b7 Mon Sep 17 00:00:00 2001 From: teleprint-me <77757836+teleprint-me@users.noreply.github.com> Date: Sun, 12 May 2024 21:17:04 -0400 Subject: [PATCH] refactor: Remove rename from display to render and return result instead of printing --- gguf-py/scripts/gguf-template.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/gguf-py/scripts/gguf-template.py b/gguf-py/scripts/gguf-template.py index aa042db77..764a76b8f 100644 --- a/gguf-py/scripts/gguf-template.py +++ b/gguf-py/scripts/gguf-template.py @@ -45,9 +45,9 @@ def get_chat_template(model_file: str) -> str: return "" -def display_chat_template( +def render_chat_template( chat_template: str, bos_token: str, eos_token: str, render_template: bool = False -): +) -> str: """ Display the chat template to standard output, optionally formatting it using Jinja2. @@ -86,10 +86,10 @@ def display_chat_template( eos_token=eos_token, ) - print(formatted_template) + return formatted_template else: # Display the raw template - print(chat_template) + return chat_template # Example usage: @@ -130,9 +130,10 @@ def main(): logging.basicConfig(level=logging.INFO) chat_template = get_chat_template(args.model_file) - display_chat_template( + rendered_template = render_chat_template( chat_template, args.bos, args.eos, render_template=args.render_template ) + print(rendered_template) if __name__ == "__main__":