3.0 KiB
3.0 KiB
Autoresearch: dynamic-chat-templates
Objective
Implement a dynamic chat-template system that selects prompt rendering by model family
for local OpenAI-compatible POST /v1/chat/completions requests. The server should ship
useful built-in templates for common open-source families such as Qwen, Gemma, Llama,
and Kimi, while preserving a safe generic fallback for unknown models.
Metrics
- Primary: template_score (percent, higher is better)
- Secondary: passed_cases, failed_cases, total_cases
How to Run
./autoresearch.sh - runs targeted ignored tests for dynamic chat-template behavior and outputs METRIC name=number lines.
Files in Scope
crates/inference-server/src/compat.rs- prompt preparation, model catalog, template selection, family detection, and template-focused testscrates/inference-server/src/routes.rs- route-level integration if template selection needs model-aware wiringcrates/inference-server/src/main.rs- server boot wiring if template config/env support is neededcrates/api-contracts/src/chat.rs- request/response roles and content handling that templates consumeexperiments/bench_chat_templates.py- benchmark harness for the autoresearch loopautoresearch.sh- loop benchmark entrypoint and fast preflight
Off Limits
models/model binariesvendor/third-party sources and prebuilt llama binariesregistry/Python registry serviceui/frontend files- unrelated latency tuning or runtime/engine experiments unless they are required to support template selection correctly
Constraints
- No new external dependencies.
- Preserve OpenAI-compatible behavior already implemented.
- Regular test suite must stay green for keeps.
- Prefer explicit, maintainable template definitions over opaque heuristics.
- Unknown models must continue to work through a generic fallback template.
- The benchmark is test-driven: keep/discard follows the dynamic-template suite score first.
What's Been Tried
- Segment 1 switches the autoresearch target from latency to dynamic chat-template selection by model family.
- The current server still renders every prompt through one generic
System:/User:/Assistant:formatter incrates/inference-server/src/compat.rs. prepare_prompt()is the cleanest insertion point for dynamic templates because both blocking and streaming paths already consume its rendered string.ModelCatalogcurrently resolves aliases only; it has no model-family metadata or template registry yet.- The benchmark for this segment is a targeted ignored test suite that scores family detection/template rendering coverage for Qwen, Gemma, Llama, Kimi, and the generic fallback.
- Baseline run 7 scored only
20.0%because just the generic fallback path passed; Qwen, Gemma, Llama, and Kimi were still rendered through the old generic formatter. - Run 8 (
ceb83f2) added family detection plus built-in template selection insidecompat.rsand immediately raised coverage to100.0%(5/5 passing), making it the current best for segment 1.