File size: 3,538 Bytes
06d4b67
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/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!")