From 6a5d5bcd47539242f5e689355dc4d57ad3973224 Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Wed, 10 Apr 2024 21:26:50 -0700 Subject: [PATCH] fix use ImmutableSandboxedEnvironment --- litellm/llms/prompt_templates/factory.py | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/litellm/llms/prompt_templates/factory.py b/litellm/llms/prompt_templates/factory.py index 26b86a085e3..f137c90f65d 100644 --- a/litellm/llms/prompt_templates/factory.py +++ b/litellm/llms/prompt_templates/factory.py @@ -221,7 +221,7 @@ def phind_codellama_pt(messages): def hf_chat_template(model: str, messages: list, chat_template: Optional[Any] = None): # Define Jinja2 environment with autoescaping disabled - env = ImmutableSandboxedEnvironment(trim_blocks=True, lstrip_blocks=True) + env = ImmutableSandboxedEnvironment() def raise_exception(message): raise Exception(f"Error message - {message}") @@ -259,13 +259,6 @@ def hf_chat_template(model: str, messages: list, chat_template: Optional[Any] = eos_token = tokenizer_config["eos_token"] chat_template = tokenizer_config["chat_template"] - # Render the chat_template safely - rendered_template = env.from_string(chat_template).render(messages=messages) - - # Now you can use the rendered_template in your application - # For example, return it or process further - return rendered_template - try: template = env.from_string(chat_template) except Exception as e: