| #!/usr/bin/env python3 | |
| import json | |
| # 读取模板文件 | |
| with open('chat_template.jinja', 'r', encoding='utf-8') as f: | |
| chat_template = f.read() | |
| # 读取tokenizer配置 | |
| with open('tokenizer_config.json', 'r', encoding='utf-8') as f: | |
| config = json.load(f) | |
| # 更新chat_template | |
| config['chat_template'] = chat_template | |
| # 写回配置文件 | |
| with open('tokenizer_config.json', 'w', encoding='utf-8') as f: | |
| json.dump(config, f, ensure_ascii=False, indent=4) | |
| print("✅ 已更新 tokenizer_config.json 的 chat_template") | |
| print(f"模板长度: {len(chat_template)} 字符") | |
| print(f"包含 skip_im_start: {'skip_im_start' in chat_template}") | |