"""Bharat's explicit default identity policy with the unchanged native tokenizer.""" import json from pathlib import Path def encode_messages(tokenizer,messages,identity_path=None): path=Path(identity_path) if identity_path else Path(__file__).parent/'bharat-model-identity.json' policy=json.loads(path.read_text()) messages=[dict(m) for m in messages] if not any(m['role']=='system' for m in messages): messages.insert(0,{'role':'system','content':policy['default_system_message']}) return tokenizer.apply_chat_template(messages,tokenize=True,return_dict=False,add_generation_prompt=True) def visible_answer(text): """Separate the exposed reasoning envelope without modifying its raw record.""" return text.split('',1)[-1].strip() if '' in text else text