patch: Apply patch for advisories/GHSA-56xg-wfcc-g829

Signed-off-by: teleprint-me <77757836+teleprint-me@users.noreply.github.com>
This commit is contained in:
teleprint-me 2024-05-13 13:10:44 -04:00
parent f8bb223924
commit da96fdd15f
No known key found for this signature in database
GPG key ID: B0D11345E65C4D48

View file

@ -11,6 +11,7 @@ import sys
from pathlib import Path from pathlib import Path
import jinja2 import jinja2
import jinja2.sandbox
# Necessary to load the local gguf package # Necessary to load the local gguf package
if "NO_LOCAL_GGUF" not in os.environ and (Path(__file__).parent.parent.parent / 'gguf-py').exists(): if "NO_LOCAL_GGUF" not in os.environ and (Path(__file__).parent.parent.parent / 'gguf-py').exists():
@ -46,7 +47,10 @@ def get_chat_template(model_file: str) -> str:
def render_chat_template( def render_chat_template(
chat_template: str, bos_token: str, eos_token: str, render_template: bool = False chat_template: str,
bos_token: str,
eos_token: str,
render_template: bool = False,
) -> str: ) -> str:
""" """
Display the chat template to standard output, optionally formatting it using Jinja2. Display the chat template to standard output, optionally formatting it using Jinja2.
@ -59,8 +63,8 @@ def render_chat_template(
if render_template: if render_template:
# Render the formatted template using Jinja2 with a context that includes 'bos_token' and 'eos_token' # Render the formatted template using Jinja2 with a context that includes 'bos_token' and 'eos_token'
env = jinja2.Environment( env = jinja2.sandbox.ImmutableSandboxedEnvironment(
loader=jinja2.BaseLoader(), trim_blocks=True, lstrip_blocks=True trim_blocks=True, lstrip_blocks=True
) )
template = env.from_string(chat_template) template = env.from_string(chat_template)
@ -131,9 +135,12 @@ def main():
chat_template = get_chat_template(args.model_file) chat_template = get_chat_template(args.model_file)
rendered_template = render_chat_template( rendered_template = render_chat_template(
chat_template, args.bos, args.eos, render_template=args.render_template chat_template,
args.bos,
args.eos,
render_template=args.render_template,
) )
print(rendered_template) print(rendered_template) # noqa: NP100
if __name__ == "__main__": if __name__ == "__main__":