okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge f-q4-intake (37e91bfdb): tools/qwen4_intake.py, the tokenizer refuses an unknown pre-tokenizer, the server's tool-call parser follows the chat template (serve/toolformat.py), packaging/make_model_release.py dry run (Qwen4 prep)97a50dc24

main
2.0 KiB42 linesraw
1"""Which tool-call spelling a chat template documents, read from the template's text.
2
3No imports from the rest of the server: tools/qwen4_intake.py and serve/frontend.py share this one function, so the report
4that says "this model writes XML calls" and the parser the server picks cannot disagree.
5
6    xml   `<tool_call>` around `<function=NAME>` and `<parameter=NAME>` blocks (Qwen3.6, Qwen3.8-Flash-Next: every template Strata ships)
7    json  `<tool_call>` around a JSON object `{"name": ..., "arguments": {...}}` (Qwen3, Hermes)
8    dsml  DeepSeek-V4's `<|DSML|...>` blocks
9    none  the template has no tool section
10    other the template documents tools in a form this module does not know
11"""
12from __future__ import annotations
13
14import re
15
16_DSML = "|DSML|"          # the full-width bars DeepSeek's template writes
17_XML_OPEN = re.compile(r"<function=[^>]*>")
18
19
20def tool_format(source: str) -> str:
21    """The tool-call form `source` (a chat template's Jinja text) tells the model to write."""
22    if not isinstance(source, str) or not source:
23        return "none"
24    if _DSML in source:
25        return "dsml"
26    has_call = "<tool_call>" in source
27    if has_call and _XML_OPEN.search(source) and "<parameter=" in source:
28        return "xml"
29    if has_call and ("tools" in source) and ('"name"' in source or "'name'" in source or "| tojson" in source or "|tojson" in source):
30        return "json"
31    if "tools" not in source and not has_call:
32        return "none"
33    return "other"
34
35
36def thinking_tags(source: str) -> dict:
37    """The reasoning tags the template mentions: whether it writes `<think>` itself (into the generation prompt) and takes an
38    `enable_thinking` switch."""
39    src = source if isinstance(source, str) else ""
40    return {"has_think_tags": "<think>" in src and "</think>" in src,
41            "enable_thinking_switch": "enable_thinking" in src,
42            "generation_prompt_opens_think": bool(re.search(r"add_generation_prompt.*?<think>", src, re.S))}