HyperSynapse-SAS-Chat-Templates / patch_regular_mode.py
SolsticeAI's picture
feat: sync v3.0 soft-spectrum and integrate regular/vanilla templates across all families
06d4b67 verified
Raw History Blame Contribute Delete
3.54 kB
#!/usr/bin/env python3
"""
Solstice AI: Rigorous regular / vanilla mode integration across all templates.
When regular=true or [regular] is present:
- Suppresses reasoning instructions
- Suppresses terse directives
- Suppresses forced <think> blocks
- Strips [regular] tags from prompt
- Outputs 100% pure vanilla format matching upstream standards
"""
import os
import jinja2
BASE_DIR = "/Users/shreyangondaliya/solstice_quants/HyperSynapse-SAS-Chat-Templates/templates"
# 1. Update qwen.jinja
with open(os.path.join(BASE_DIR, "qwen.jinja"), "r", encoding="utf-8") as f:
qwen = f.read()
# Make sure is_explicit_regular is defined near top of resolver
if "is_explicit_regular" not in qwen:
qwen = qwen.replace(
"{%- set _kwarg_effort = ",
"""{%- set is_explicit_regular = (regular is defined and regular) or (mode is defined and mode in ('regular', 'vanilla', 'standard', 'default', 'clean')) %}
{%- set _kwarg_effort = """
)
# Fix user message emission to strip control tags
qwen = qwen.replace(
"{{- '<|im_start|>user\\n' + content + '<|im_end|>\\n' }}",
"{{- '<|im_start|>user\\n' + strip_control_tags(content) + '<|im_end|>\\n' }}"
)
# Fix terse mode opt-out when regular
qwen = qwen.replace(
"{%- set _terse_on = terse if terse is defined else true %}",
"{%- set _terse_on = terse if terse is defined else (not is_explicit_regular) %}"
)
# Fix generation prompt for pure regular mode
old_gen = """ {%- if not ns_state.thinking %}
{{- '<think>\\n\\n</think>\\n\\n' }}
{%- else %}
{{- '<think>\\n' }}
{%- endif %}"""
new_gen = """ {%- if is_explicit_regular %}
{#- Pure regular mode: no think block -#}
{%- elif not ns_state.thinking %}
{{- '<think>\\n\\n</think>\\n\\n' }}
{%- else %}
{{- '<think>\\n' }}
{%- endif %}"""
qwen = qwen.replace(old_gen, new_gen)
with open(os.path.join(BASE_DIR, "qwen.jinja"), "w", encoding="utf-8") as f:
f.write(qwen)
# Universal is standard ChatML based on qwen
with open(os.path.join(BASE_DIR, "universal.jinja"), "w", encoding="utf-8") as f:
f.write(qwen)
# 2. Update deepseek.jinja
with open(os.path.join(BASE_DIR, "deepseek.jinja"), "r", encoding="utf-8") as f:
ds = f.read()
if "is_explicit_regular" not in ds:
ds = ds.replace(
"{%- set _kwarg_effort = ",
"""{%- set is_explicit_regular = (regular is defined and regular) or (mode is defined and mode in ('regular', 'vanilla', 'standard', 'default', 'clean')) %}
{%- set _kwarg_effort = """
)
ds = ds.replace(
"{{- message['content'] if message['content'] is string else scan_text(message['content']) -}}",
"{{- strip_control_tags(message['content']) if message['content'] is string else scan_text(message['content']) -}}"
)
ds = ds.replace(
"{%- set _terse_on = terse if terse is defined else true -%}",
"{%- set _terse_on = terse if terse is defined else (not is_explicit_regular) -%}"
)
old_ds_gen = """ {%- if thinking -%}
{{- thinking_start_token -}}
{%- else -%}
{{- thinking_end_token -}}
{%- endif -%}"""
new_ds_gen = """ {%- if is_explicit_regular -%}
{#- Pure regular mode: direct reply -#}
{%- elif thinking -%}
{{- thinking_start_token -}}
{%- else -%}
{{- thinking_end_token -}}
{%- endif -%}"""
ds = ds.replace(old_ds_gen, new_ds_gen)
with open(os.path.join(BASE_DIR, "deepseek.jinja"), "w", encoding="utf-8") as f:
f.write(ds)
print("Applied clean regular mode integration across qwen, universal, and deepseek!")