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.
Comment on lines
411
to
415
| json context_values = json::object(); | ||
| if (template_kwargs) { | ||
| if (*template_kwargs == '\0') { | ||
| throw std::runtime_error("template_kwargs must be a JSON object or null."); | ||
| } | ||
| auto parsed_kwargs = json::parse(minja::normalize_newlines(template_kwargs), nullptr, | ||
| const auto template_kwargs = options_map.find("chat_template_kwargs"); | ||
| if (template_kwargs != options_map.end()) { | ||
| auto parsed_kwargs = json::parse(minja::normalize_newlines(template_kwargs->second), nullptr, | ||
| /*allow_exceptions=*/false); |
Comment on lines
+90
to
+94
| * - `chat_template_kwargs` | ||
| * - Purpose: Adds typed values to the chat template context; | ||
| * - Values: A serialized JSON object, such as `{"enable_thinking":false}`; | ||
| * - Default: `{}`. Set the value to `{}` to clear previously configured values. | ||
| * |
Comment on lines
+74
to
+78
| if (key == "chat_template_kwargs") { | ||
| auto parsed_kwargs = nlohmann::json::parse(values[i], nullptr, /*allow_exceptions=*/false); | ||
| if (parsed_kwargs.is_discarded()) { | ||
| ReturnableStatus::last_error_message_ = "Invalid chat_template_kwargs JSON."; | ||
| return {}; |
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.
No description provided.