Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ itertools = "0.14.0"
libc = "0.2.177"
llm-multimodal = { git = "https://github.com/smg-project/llm-multimodal", rev = "15adba5e025d8636ba4a334fb379b1371f6196a1", default-features = false, features = ["native-tls"] }
mimalloc = "0.1.52"
minijinja = { version = "2.22", features = ["unstable_machinery", "json", "builtins", "loader", "loop_controls", "preserve_order"] }
minijinja-contrib = { version = "2.22", features = ["pycompat"] }
minijinja = { version = "2.24", features = ["unstable_machinery", "json", "builtins", "loader", "loop_controls", "preserve_order"] }
minijinja-contrib = { version = "2.24", features = ["pycompat"] }
native-tls-vendored = { package = "native-tls", version = "0.2.18", features = ["vendored"] }
ndarray = { version = "0.17", features = ["serde"] }
openai-harmony = { package = "oss-harmony", git = "https://github.com/oss-harmony/harmony", tag = "v0.0.11", default-features = false }
Expand Down
66 changes: 66 additions & 0 deletions rust/src/chat/src/renderer/hf/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ struct TemplateToolDefinition {
name: String,
description: Option<String>,
parameters: JsonValue,
#[serde(skip_serializing_if = "Option::is_none")]
strict: Option<bool>,
}

Expand Down Expand Up @@ -1280,6 +1281,71 @@ mod tests {
assert_eq!(rendered, "get_weather|city");
}

#[test]
fn chat_template_preserves_openai_tool_field_order() {
let mut request = sample_request(vec![ChatMessage::text(ChatRole::User, "hello")]);
let tools = vec![ChatTool {
name: "get_weather".to_string(),
description: Some("Get weather".to_string()),
parameters: serde_json::json!({"type": "object"}),
strict: None,
}];
request.tool_context = crate::request::ResolvedToolContext::new(
&request.messages,
tools,
Some(ChatToolChoice::Auto),
true,
)
.expect("tool context should resolve");

let rendered = render(
Some("{% for key, value in tools[0].function.items() %}{{ key }}|{% endfor %}"),
&request,
)
.unwrap();

assert_eq!(rendered, "name|description|parameters|");
}

#[test]
fn chat_template_preserves_python_optional_tool_fields() {
let mut request = sample_request(vec![ChatMessage::text(ChatRole::User, "hello")]);
let tools = vec![
ChatTool {
name: "without_strict".to_string(),
description: None,
parameters: Value::Null,
strict: None,
},
ChatTool {
name: "with_strict".to_string(),
description: Some("description".to_string()),
parameters: serde_json::json!({"type": "object"}),
strict: Some(false),
},
];
request.tool_context = crate::request::ResolvedToolContext::new(
&request.messages,
tools,
Some(ChatToolChoice::Auto),
true,
)
.expect("tool context should resolve");

let rendered = render(
Some(
"{% for tool in tools %}{% for key, value in tool.function.items() %}{{ key }}={{ value|tojson }}|{% endfor %};{% endfor %}",
),
&request,
)
.unwrap();

assert_eq!(
rendered,
"name=\"without_strict\"|description=null|parameters=null|;name=\"with_strict\"|description=\"description\"|parameters={\"type\": \"object\"}|strict=false|;"
);
}

#[test]
fn chat_template_exposes_assistant_tool_calls_and_tool_messages() {
let request = sample_request(vec![
Expand Down
20 changes: 20 additions & 0 deletions rust/src/chat/src/renderer/hf/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,26 @@ mod tests {
assert_eq!(result, "[]");
}

#[test]
fn test_midchain_dotted_integer_lookup() {
let template = CompiledChatTemplate::new(
"{{ values.0.name }}".to_string(),
ChatTemplateContentFormatOption::Auto,
)
.unwrap();
let mut kwargs = HashMap::new();
kwargs.insert("values".to_string(), serde_json::json!([{"name": "first"}]));

let result = template
.apply(TemplateContext {
template_kwargs: Some(&kwargs),
..Default::default()
})
.unwrap();

assert_eq!(result, "first");
}

#[test]
fn test_chat_template_state_invalid_template() {
let result = CompiledChatTemplate::new(
Expand Down
14 changes: 14 additions & 0 deletions rust/src/chat/tests/roundtrip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,19 @@ impl RoundtripCase {
}
}

/// GLM-5.2 XML-like argument format with `<think>` reasoning tags.
fn glm52() -> Self {
Self {
model_id: "zai-org/GLM-5.2-FP8",
assistant_stop_suffix: "",
tool_call_parser: ParserSelection::Auto,
reasoning_parser: ParserSelection::Auto,
thinking_behavior: ThinkingBehavior::Toggleable { default: true },
json_fmt: compact_json_fmt(),
sort_json_keys: false,
}
}

/// Gemma4 channel reasoning with custom function-call arguments.
fn gemma4() -> Self {
Self {
Expand Down Expand Up @@ -324,6 +337,7 @@ roundtrip_tests! {
deepseek_v32 => [tool_call_mix],
glm45 => [reasoning_and_content, tool_call_mix],
glm47 => [reasoning_and_content, tool_call_mix],
glm52 => [reasoning_and_content, tool_call_mix],
seed_oss => [reasoning_and_content, tool_call_mix],
step3p5 => [reasoning_and_content],
nemotron_v3 => [reasoning_and_content],
Expand Down
Loading