Bharat-24B-Math-Code / bharat_serving.py
DesaiJayM's picture
Release Bharat24B math and code adapter, scorecard and native inference helper
4cf8d9d verified
Raw History Blame Contribute Delete
810 Bytes
"""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