Skip to content

Commit

Permalink
Add proper jinja2 error (huggingface#35533)
Browse files Browse the repository at this point in the history
* Cleanup jinja2 imports

* Raise a proper error if Jinja is missing

* make fixup
  • Loading branch information
Rocketknight1 authored and bursteratom committed Jan 28, 2025
1 parent 8ed8e77 commit 4b1d062
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/transformers/utils/chat_template_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,11 @@ def _render_with_assistant_indices(

@lru_cache
def _compile_jinja_template(chat_template):
if not is_jinja_available():
raise ImportError(
"apply_chat_template requires jinja2 to be installed. Please install it using `pip install jinja2`."
)

class AssistantTracker(Extension):
# This extension is used to track the indices of assistant-generated tokens in the rendered chat
tags = {"generation"}
Expand Down

0 comments on commit 4b1d062

Please sign in to comment.