Skip to content

Route chat template kwargs through tokenizer options - #1108

Open
jennyf19 wants to merge 6 commits into
microsoft:mainfrom
jennyf19:feature/chat-template-kwargs-update-options
Open

Route chat template kwargs through tokenizer options#1108
jennyf19 wants to merge 6 commits into
microsoft:mainfrom
jennyf19:feature/chat-template-kwargs-update-options

Conversation

@jennyf19

Copy link
Copy Markdown
Contributor

No description provided.

Jenny Ferries 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
@jennyf19
jennyf19 requested a review from a team as a code owner August 23, 2026 01:20
Copilot AI lite review requested due to automatic review settings August 23, 2026 01:20
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_kwargs to 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_kwargs via OrtxUpdateTokenizerOptions / 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 thread include/ortx_tokenizer.h
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 thread shared/api/c_api_tokenizer.cc Outdated
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 {};
Jenny Ferries 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
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.

2 participants