server: Jinja chat template rendering via minijinja

Load the model's chat_template.jinja (or tokenizer_config.json
chat_template field) at startup and render it with minijinja instead of
hardcoded per-model prompt builders.

Custom Jinja functions: strftime_now (date formatting), raise_exception
(template validation errors).  Falls back to Qwen3 ChatML template if
no Jinja template is found.

Removes the hardcoded build_prompt_gpt_oss() — the model's own template
now drives prompt formatting, matching llama.cpp's behavior exactly.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Gahow Wang
2026-05-31 13:23:18 +08:00
parent 4368e79695
commit 1d0ec32e8d
5 changed files with 175 additions and 66 deletions

28
Cargo.lock generated
View File

@@ -408,12 +408,28 @@ version = "2.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79"
[[package]]
name = "memo-map"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "38d1115007560874e373613744c6fba374c17688327a71c1476d1a5954cc857b"
[[package]]
name = "mime"
version = "0.3.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a"
[[package]]
name = "minijinja"
version = "2.20.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2929e494b2280e1e18959bb2e121da03347ae896896fdfaceaab43c88a02803f"
dependencies = [
"memo-map",
"serde",
]
[[package]]
name = "mio"
version = "1.2.0"
@@ -1097,6 +1113,14 @@ dependencies = [
"rand 0.9.4",
]
[[package]]
name = "xserv-distributed"
version = "0.1.0"
dependencies = [
"half",
"xserv-cuda",
]
[[package]]
name = "xserv-kernels"
version = "0.1.0"
@@ -1112,12 +1136,14 @@ name = "xserv-model"
version = "0.1.0"
dependencies = [
"half",
"libc",
"rand 0.8.6",
"safetensors",
"serde",
"serde_json",
"smallvec",
"xserv-cuda",
"xserv-distributed",
"xserv-kernels",
"xserv-tensor",
"xserv-tokenizer",
@@ -1129,12 +1155,14 @@ version = "0.1.0"
dependencies = [
"axum",
"half",
"minijinja",
"serde",
"serde_json",
"tokio",
"tokio-stream",
"uuid",
"xserv-cuda",
"xserv-distributed",
"xserv-kernels",
"xserv-model",
"xserv-tensor",