import os,json,re,concurrent.futures as cf from openai import OpenAI from writing import W c=OpenAI(base_url="https://router.huggingface.co/v1",api_key=os.environ["HF_TOKEN"],timeout=180) P={w["id"]:w for w in W} R={json.loads(l)["id"]:json.loads(l) for l in open('all_raw.jsonl') if '"write"' in l} J=["google/gemma-3-27b-it","deepseek-ai/DeepSeek-V3.1"] RUB="""You are a strict native Tamil-speaking evaluator. A user sent the PROMPT below to an AI model and got the RESPONSE. Score the RESPONSE (integers 1-5): - correctness: facts and advice are accurate and safe - fluency: natural, grammatical Tamil (or natural Tanglish if the prompt was Tanglish); penalise literal translation, odd word choice, spelling errors - instruction: follows the requested length/format/audience - register_match: 1 if it replies in the same script/register as the prompt (Tamil script for Tamil prompts, Romanized Tamil for Tanglish prompts), else 0 Return only JSON: {"correctness":n,"fluency":n,"instruction":n,"register_match":0or1,"note":"<=15 words"} PROMPT: %s RESPONSE: %s""" def go(a): wid,j=a for t in range(4): try: r=c.chat.completions.create(model=j,messages=[{"role":"user","content":RUB%(P[wid]["prompt"],R[wid]["output"])}],max_tokens=300,temperature=0) s=r.choices[0].message.content; d=json.loads(re.search(r"\{.*\}",s,re.S).group(0)); d.update(id=wid,judge=j); return d except Exception as e: err=str(e) return dict(id=wid,judge=j,error=err) with cf.ThreadPoolExecutor(6) as ex: out=list(ex.map(go,[(w,j) for w in R for j in J])) json.dump(out,open("judge.json","w"),ensure_ascii=False,indent=1) for d in out: print(d)