Route chat template kwargs through tokenizer options - #1108
Open
jennyf19 wants to merge 6 commits into
Open
Conversation
added 4 commits
August 22, 2026 16:17
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 317a4c59-c84b-4900-8dc4-01727a1a1b86
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 317a4c59-c84b-4900-8dc4-01727a1a1b86
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 317a4c59-c84b-4900-8dc4-01727a1a1b86
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 317a4c59-c84b-4900-8dc4-01727a1a1b86
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
There was a problem hiding this comment.
Pull request overview
Routes chat-template “template kwargs” through tokenizer options by introducing a chat_template_kwargs option, removing the dedicated per-call C API, and updating tests/docs accordingly.
Changes:
- Adds
chat_template_kwargsto tokenizer options (C API + docs) with JSON validation. - Updates chat template application to pull kwargs from tokenizer options rather than a per-call parameter.
- Refactors/extends tests to configure/clear
chat_template_kwargsviaOrtxUpdateTokenizerOptions/OrtxCreateTokenizerWithOptions.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| test/pp_api_test/test_tokenizer_chat.cc | Updates tests to configure chat template kwargs through tokenizer options and adds a “clear option” test. |
| shared/api/tokenizer_impl.h | Updates TokenizerImpl::ApplyChatTemplate signature to remove the explicit kwargs parameter. |
| shared/api/chat_template.cc | Reads chat_template_kwargs from options_map and updates related error messages. |
| shared/api/c_api_tokenizer.cc | Adds chat_template_kwargs as a valid option and validates it as a JSON object. Removes the OrtxApplyChatTemplateWithOptions implementation. |
| pyop/py_c_api.cc | Updates Python binding docstrings to mention chat_template_kwargs. |
| include/ortx_tokenizer.h | Documents chat_template_kwargs option and removes the OrtxApplyChatTemplateWithOptions declaration/docs. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
added 2 commits
August 22, 2026 18:48
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 317a4c59-c84b-4900-8dc4-01727a1a1b86
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 317a4c59-c84b-4900-8dc4-01727a1a1b86
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Route chat template kwargs through tokenizer options
Summary
chat_template_kwargsto the existing tokenizer option allowlistOrtxApplyChatTemplateconsume those configured valuesmessages,tools, andadd_generation_promptauthoritativeOrtxApplyChatTemplateWithOptionsas a per-call compatibility API{}as the way to clear previously configured template kwargsWhy
This is the cleaner follow-up to #1102 suggested during review of the dependent
GenAI change.
OrtxUpdateTokenizerOptionsalready provides a forward-compatible C surfacefor extending tokenizer behavior. Routing template kwargs through it avoids
requiring callers to grow a parallel family of
WithOptionsentry points whilepreserving the per-call API added in #1102 for compatibility. Both paths retain
typed chat-template context such as:
{"enable_thinking": false, "reasoning_effort": "low", "level": 2}This is needed by microsoft/foundry-local#808 so Qwen 3 callers can disable
thinking before generation rather than spending a bounded completion entirely
inside the reasoning block.
Behavior
chat_template_kwargsmust be a JSON object.chat_template_kwargsto{}clears the custom context.OrtxApplyChatTemplateWithOptionsremains available for per-call overrides.add_special_tokensandskip_special_tokensbehavior is unchanged.Validation
Fork-only native validation passed:
https://github.com/jennyf19/onnxruntime-extensions/actions/runs/32611271986
The run validated the review-fix commit, built the C API/native test target,
and passed the complete C++ test suite.
The dependent source-only prototypes also pass:
No production dependency pins in the dependent repositories have been changed.