okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
97a50dc24
main
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 6xml `<tool_call>` around `<function=NAME>` and `<parameter=NAME>` blocks (Qwen3.6, Qwen3.8-Flash-Next: every template Strata ships) 7json `<tool_call>` around a JSON object `{"name": ..., "arguments": {...}}` (Qwen3, Hermes) 8dsml DeepSeek-V4's `<|DSML|...>` blocks 9none the template has no tool section 10other 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.""" 22if not isinstance (source ,str )or not source : 23return "none" 24if _DSML in source : 25return "dsml" 26has_call = "<tool_call>" in source 27if has_call and _XML_OPEN .search (source )and "<parameter=" in source : 28return "xml" 29if has_call and ("tools" in source )and ('"name"' in source or "'name'" in source or "| tojson" in source or "|tojson" in source ): 30return "json" 31if "tools" not in source and not has_call : 32return "none" 33return "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.""" 39src = source if isinstance (source ,str )else "" 40return {"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 ))}