|
@@ -0,0 +1,51 @@
|
|
|
|
|
+import struct
|
|
|
|
|
+import sys
|
|
|
|
|
+
|
|
|
|
|
+src = r'Qwen3.5-9B-Uncensored-HauhauCS-Aggressive-NoThink-Q4_K_M.gguf'
|
|
|
|
|
+if len(sys.argv) > 1:
|
|
|
|
|
+ src = sys.argv[1]
|
|
|
|
|
+
|
|
|
|
|
+with open(src, 'rb') as f:
|
|
|
|
|
+ data = bytearray(f.read())
|
|
|
|
|
+
|
|
|
|
|
+key = b'tokenizer.chat_template'
|
|
|
|
|
+kp = data.find(key)
|
|
|
|
|
+kl = struct.unpack('<Q', data[kp-8:kp])[0]
|
|
|
|
|
+sl = struct.unpack('<Q', data[kp+kl+4:kp+kl+12])[0]
|
|
|
|
|
+sp = kp + kl + 12
|
|
|
|
|
+template = data[sp:sp+sl].decode('utf-8').rstrip(' ')
|
|
|
|
|
+
|
|
|
|
|
+old = (
|
|
|
|
|
+ "{%- if add_generation_prompt %}\n"
|
|
|
|
|
+ " {{- '<|im_start|>assistant\\n' }}\n"
|
|
|
|
|
+ " {%- if enable_thinking is defined and enable_thinking is false %}\n"
|
|
|
|
|
+ " {{- '<think>\\n\\n</think>\\n\\n' }}\n"
|
|
|
|
|
+ " {%- else %}\n"
|
|
|
|
|
+ " {{- '<think>\\n' }}\n"
|
|
|
|
|
+ " {%- endif %}\n"
|
|
|
|
|
+ "{%- endif %}"
|
|
|
|
|
+)
|
|
|
|
|
+new = (
|
|
|
|
|
+ "{%- if add_generation_prompt %}\n"
|
|
|
|
|
+ " {{- '<|im_start|>assistant\\n' }}\n"
|
|
|
|
|
+ " {{- '<think>\\n\\n</think>\\n\\n' }}\n"
|
|
|
|
|
+ "{%- endif %}"
|
|
|
|
|
+)
|
|
|
|
|
+
|
|
|
|
|
+if old in template:
|
|
|
|
|
+ template = template.replace(old, new)
|
|
|
|
|
+ new_bytes = template.encode('utf-8')
|
|
|
|
|
+ if len(new_bytes) > sl:
|
|
|
|
|
+ print("ERROR: New template longer than original")
|
|
|
|
|
+ exit(1)
|
|
|
|
|
+ padded = new_bytes + b' ' * (sl - len(new_bytes))
|
|
|
|
|
+ data[sp:sp+sl] = padded
|
|
|
|
|
+ with open(src, 'wb') as f:
|
|
|
|
|
+ f.write(data)
|
|
|
|
|
+ print("Done: enable_thinking conditional removed, forced empty think block")
|
|
|
|
|
+else:
|
|
|
|
|
+ print("No enable_thinking conditional found in template")
|
|
|
|
|
+ idx = template.find('enable_thinking')
|
|
|
|
|
+ if idx >= 0:
|
|
|
|
|
+ print("Found at position", idx)
|
|
|
|
|
+ print(template[idx-50:idx+200])
|