Class Qwen3ChatTemplate
java.lang.Object
smile.llm.template.Qwen3ChatTemplate
- All Implemented Interfaces:
ChatTemplate
Java port of the Qwen3.5 / Qwen3.8
chat_template.jinja, byte for byte (the golden tests compare it with
transformers' rendering of the real templates).
The released templates differ in a few independent behaviours, which Qwen3ChatTemplate.Variant.detect(String) reads from the
checkpoint's own template text so every checkpoint renders like its reference:
- Qwen3.8 adds a reasoning-effort system turn (
reasoning_effort:xhighby default,low,medium= none) whenever thinking is on, and keeps the<think>block of earlier assistant turns unlesspreserve_thinkingis false; - Qwen3.5 splits a
<think>...</think>found in an assistant message's content, and prints an empty system turn for an empty system message; - small Qwen3.5 models think only when
enable_thinkingis true, the larger ones unless it is false.
<think>\n) or closes an empty one
(<think>\n\n</think>\n\n); the model then continues inside the block, so replies carry no opening tag.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordThe behaviours in which the released Qwen3.x templates differ. -
Constructor Summary
ConstructorsConstructorDescriptionQwen3.8 behaviour with an open assistant turn.Qwen3ChatTemplate(Qwen3ChatTemplate.Variant variant, boolean addGenerationPrompt) Creates the template of a checkpoint. -
Method Summary
Modifier and TypeMethodDescriptionencode(List<Message> dialog, ChatOptions options) Encodes dialog messages with optional tool-calling options.static StringencodeDialog(Message[] dialog, ChatOptions options) Encodes dialog to a prompt string (generation prompt open) with the Qwen3.8 behaviours.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ChatTemplate
encode
-
Constructor Details
-
Qwen3ChatTemplate
public Qwen3ChatTemplate()Qwen3.8 behaviour with an open assistant turn. -
Qwen3ChatTemplate
Creates the template of a checkpoint.- Parameters:
variant- the checkpoint's behaviours.addGenerationPrompt- whether to append the open assistant turn.
-
-
Method Details
-
encode
Description copied from interface:ChatTemplateEncodes dialog messages with optional tool-calling options.- Specified by:
encodein interfaceChatTemplate- Parameters:
dialog- ordered conversation turns.options- chat options; may benull.- Returns:
- prompt text including an open assistant turn when applicable.
-
encodeDialog
Encodes dialog to a prompt string (generation prompt open) with the Qwen3.8 behaviours.- Parameters:
dialog- conversation turns.options- chat options; may benull.- Returns:
- prompt text.
-