"""The one prompt format used for training, evaluation, the GGUF chat template and the runners. ChatML (tokens already in the Qwen3.5 vocab). The system prompt is fixed; if a caller sends its own system message the template uses that instead. Audio mode: the user turn starts with llama.cpp's media marker (mtmd puts the audio embeddings there) followed by a short instruction. Text mode: the user turn is the transcript to clean. """ from __future__ import annotations MARKER = "<__media__>" SYSTEM = ("Write clean text of this speech or transcript: drop fillers, repeats and false starts, fix punctuation. " "Never answer or add anything.") INSTRUCTIONS = ["", "Transcribe.", "Transcribe and clean.", "Transcribe this audio.", "Clean transcript, please.", "Write down what is said."] IM_START, IM_END = "<|im_start|>", "<|im_end|>" # Jinja template stored in the tokenizer / GGUF (llama.cpp --jinja). Renders exactly like render_prefix + suffix. CHAT_TEMPLATE = ( "{%- if messages[0]['role'] == 'system' -%}" "{{- '<|im_start|>system\\n' + messages[0]['content'] + '<|im_end|>\\n' -}}" "{%- set rest = messages[1:] -%}" "{%- else -%}" "{{- '<|im_start|>system\\n" + SYSTEM.replace("'", "\\'") + "<|im_end|>\\n' -}}" "{%- set rest = messages -%}" "{%- endif -%}" "{%- for m in rest -%}" "{{- '<|im_start|>' + m['role'] + '\\n' + m['content'] + '<|im_end|>\\n' -}}" "{%- endfor -%}" "{%- if add_generation_prompt -%}{{- '<|im_start|>assistant\\n' -}}{%- endif -%}" ) def render(user: str) -> str: """Full prompt up to the assistant answer, for one user turn.""" return f"{IM_START}system\n{SYSTEM}{IM_END}\n{IM_START}user\n{user}{IM_END}\n{IM_START}assistant\n" def render_audio_parts(instruction: str = "") -> tuple[str, str]: """(text before the audio, text after the audio), split at the media marker like mtmd does.""" pre, post = render(MARKER + instruction).split(MARKER) return pre, post