Skip to content

fix: match Transformers tojson in chat template rendering#1486

Merged
abetlen merged 9 commits into
abetlen:mainfrom
CISC:tojson-unicode
Jun 1, 2026
Merged

fix: match Transformers tojson in chat template rendering#1486
abetlen merged 9 commits into
abetlen:mainfrom
CISC:tojson-unicode

Conversation

@CISC
Copy link
Copy Markdown
Contributor

@CISC CISC commented May 26, 2024

Updates this PR to only carry the remaining chat-template compatibility gap against current main:

  • Override Jinja's tojson filter to match Transformers behavior (ensure_ascii=False by default and no HTML escaping).
  • Keep the existing generation-tag and loopcontrols extensions intact.
  • Add the matching changelog entry.

@CISC
Copy link
Copy Markdown
Contributor Author

CISC commented Jun 20, 2024

Since the merging of a similar patch to transformers and the formalizing of tools (see references in #1336) there are starting to pop up a lot more models using tojson in their chat templates.

@CISC
Copy link
Copy Markdown
Contributor Author

CISC commented Aug 1, 2024

@abetlen Llama 3.1 is the latest model to use tojson, would be nice to have matching behaviour as transformers.

@CISC CISC changed the title Render chat template tojson filter as unicode Chat template rendering extensions to match transformers Aug 15, 2024
@CISC
Copy link
Copy Markdown
Contributor Author

CISC commented Aug 15, 2024

@abetlen Even more transformers changes incoming, see updated OP.

@CISC
Copy link
Copy Markdown
Contributor Author

CISC commented Oct 8, 2024

@abetlen It would be really nice to have this merged soon, it's starting to cause issues with quite a few templates not to have this in place.

Additionally this is a requirement for implementing inverse templates (which I'd like to do, as soon as it's merged in transformers, since it will be super useful for universal function calling and parsing).

@serhii-nakon
Copy link
Copy Markdown

Hello I support to merge it. I have issues with Mistral models (devstral too)

@CISC
Copy link
Copy Markdown
Contributor Author

CISC commented Aug 8, 2025

@abetlen I see strftime_now support was finally added, unfortunately that is not enough, PTAL.

CISC referenced this pull request in LostRuins/koboldcpp Nov 7, 2025
@abetlen abetlen changed the title Chat template rendering extensions to match transformers fix: match Transformers tojson chat-template behavior Jun 1, 2026
@abetlen abetlen changed the title fix: match Transformers tojson chat-template behavior fix: match Transformers tojson in chat template rendering Jun 1, 2026
@abetlen abetlen merged commit 84bc143 into abetlen:main Jun 1, 2026
15 checks passed
@CISC CISC deleted the tojson-unicode branch June 1, 2026 06:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants