Unverified Commit cceeb8e3 authored by Neelay Shah's avatar Neelay Shah Committed by GitHub
Browse files

fix: add chat_template_kwargs alias for compatibility (#5112)


Co-authored-by: default avatarClaude <noreply@anthropic.com>
parent 2fa3627a
......@@ -2191,8 +2191,7 @@ mod tests {
"model": "test-model",
"add_special_tokens": true,
"documents": ["doc1"],
"chat_template": "custom",
"chat_template_kwargs": {"key": "val"}
"chat_template": "custom"
}"#;
let request: NvCreateChatCompletionRequest = serde_json::from_str(json).unwrap();
......@@ -2205,11 +2204,6 @@ mod tests {
);
assert!(request.unsupported_fields.contains_key("documents"));
assert!(request.unsupported_fields.contains_key("chat_template"));
assert!(
request
.unsupported_fields
.contains_key("chat_template_kwargs")
);
let result = validate_chat_completion_fields_generic(&request);
assert!(result.is_err());
......@@ -2221,7 +2215,6 @@ mod tests {
assert!(msg.contains("add_special_tokens"));
assert!(msg.contains("documents"));
assert!(msg.contains("chat_template"));
assert!(msg.contains("chat_template_kwargs"));
}
}
......
......@@ -44,7 +44,12 @@ pub struct NvCreateChatCompletionRequest {
pub nvext: Option<NvExt>,
/// Extra args to pass to the chat template rendering context
#[serde(default, skip_serializing_if = "Option::is_none")]
/// Also accepts "chat_template_kwargs" as an alias for compatibility
#[serde(
default,
skip_serializing_if = "Option::is_none",
alias = "chat_template_kwargs"
)]
pub chat_template_args: Option<std::collections::HashMap<String, serde_json::Value>>,
/// Runtime media decoding parameters.
......
// SPDX-FileCopyrightText: Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
use dynamo_llm::protocols::openai::chat_completions::NvCreateChatCompletionRequest;
#[test]
fn test_both_fields_fails() {
// Test that when both are present, serde will fail with duplicate field error
// This test documents that behavior
let json_with_both = r#"{
"model": "test-model",
"messages": [],
"chat_template_args": {
"enable_thinking": true
},
"chat_template_kwargs": {
"enable_thinking": false
}
}"#;
// This will fail with duplicate field error
let result: Result<NvCreateChatCompletionRequest, _> = serde_json::from_str(json_with_both);
assert!(result.is_err());
}
#[test]
fn test_chat_template_kwargs_alias() {
// Test that chat_template_kwargs is accepted as an alias for chat_template_args
let json_with_kwargs = r#"{
"model": "test-model",
"messages": [],
"chat_template_kwargs": {
"enable_thinking": false
}
}"#;
let request: NvCreateChatCompletionRequest = serde_json::from_str(json_with_kwargs).unwrap();
assert!(request.chat_template_args.is_some());
assert_eq!(
request.chat_template_args.unwrap().get("enable_thinking"),
Some(&serde_json::json!(false))
);
}
#[test]
fn test_chat_template_args() {
// Test that chat_template_args still works as the primary field name
let json_with_args = r#"{
"model": "test-model",
"messages": [],
"chat_template_args": {
"enable_thinking": true
}
}"#;
let request: NvCreateChatCompletionRequest = serde_json::from_str(json_with_args).unwrap();
assert!(request.chat_template_args.is_some());
assert_eq!(
request.chat_template_args.unwrap().get("enable_thinking"),
Some(&serde_json::json!(true))
);
}
// TODO: Add template rendering test that verifies chat_template_args/chat_template_kwargs
// values are actually passed to the Jinja template context during rendering.
// This would require setting up PromptFormatter with ChatTemplate/ContextMixins.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment