Skip to content

Commit

Permalink
Add proper jinja2 error (#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 Jan 16, 2025
1 parent 3292e96 commit 1302c32
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 1302c32

Please sign in to comment.