• Stefy Lanza (nextime / spora )'s avatar
    engine: render chat prompt with a plain (cached) Jinja env — fixes ~40s per request · 080ecff7
    Stefy Lanza (nextime / spora ) authored
    Root cause (from [timing] logs): chat "build" = 39.6s while prefill+first-token =
    0.31s. The ~40s is create_chat_completion rendering the chat template via
    llama-cpp-python's ImmutableSandboxedEnvironment, whose per-operation security
    checks make a heavy template (gemma-4's recursive / O(n^2) macros over a big
    Kilocode conversation) take tens of seconds — every request.
    
    Fix (generic for ALL gguf/llama.cpp models): render the prompt ourselves with a
    plain jinja2.Environment compiled ONCE from the model's tokenizer.chat_template
    (same trim/lstrip, IgnoreGenerationTags + loopcontrols extensions, tojson filter,
    same render vars), then tokenize with add_bos=False + special=True (matching
    llama-cpp's added_special handling — no double BOS) and generate via
    create_completion. Output is byte-identical to the sandboxed render (verified), but
    without the sandbox overhead. Plus a small per-message render cache and finer
    timing ([timing] chat render / tokenize / create_completion setup / first-token).
    Falls back to create_chat_completion if the model has no chat_template or rendering
    fails.
    Co-Authored-By: 's avatarClaude Opus 4.8 <noreply@anthropic.com>
    Claude-Session: https://claude.ai/code/session_011DDv7BchtZQWsnPG6Jm49m
    080ecff7
Name
Last commit
Last update
..
admin Loading commit data...
api Loading commit data...
backends Loading commit data...
broker Loading commit data...
frontproxy Loading commit data...
models Loading commit data...
openai Loading commit data...
pydantic Loading commit data...
queue Loading commit data...
tasks Loading commit data...
__init__.py Loading commit data...
cli.py Loading commit data...
config.py Loading commit data...
main.py Loading commit data...
platform_paths.py Loading commit data...
system_app.py Loading commit data...