From b454f40a9a1787b2b5659cd2cb00819d983185df Mon Sep 17 00:00:00 2001 From: Patrick Peng Date: Fri, 10 May 2024 12:47:56 +0800 Subject: [PATCH] Merge pull request from GHSA-56xg-wfcc-g829 Co-authored-by: Andrei --- llama_cpp/llama_chat_format.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/llama_cpp/llama_chat_format.py b/llama_cpp/llama_chat_format.py index 84de989..e0c59c9 100644 --- a/llama_cpp/llama_chat_format.py +++ b/llama_cpp/llama_chat_format.py @@ -11,6 +11,7 @@ from contextlib import ExitStack from typing import Any, Dict, Iterator, List, Literal, Optional, Tuple, Union, Protocol, cast import jinja2 +from jinja2.sandbox import ImmutableSandboxedEnvironment import numpy as np import numpy.typing as npt @@ -191,7 +192,7 @@ class Jinja2ChatFormatter(ChatFormatter): self.add_generation_prompt = add_generation_prompt self.stop_token_ids = set(stop_token_ids) if stop_token_ids is not None else None - self._environment = jinja2.Environment( + self._environment = ImmutableSandboxedEnvironment( loader=jinja2.BaseLoader(), trim_blocks=True, lstrip_blocks=True,