File size: 810 Bytes
4cf8d9d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
"""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('</think>',1)[-1].strip() if '</think>' in text else text