"""Bounded exact greedy-output check; never executes generated text."""
import argparse,json,pathlib,time,urllib.request
p=argparse.ArgumentParser();p.add_argument('--out',required=True);p.add_argument('--baseline');a=p.parse_args()
prompts=['Responde solo el resultado: 17*23.', 'Devuelve solo JSON: {"ok":true,"n":3}', 'Write a Python function square(n) that returns n squared.']
rows=[]
for prompt in prompts:
 data={'model':'ornith-vllm','messages':[{'role':'user','content':prompt}],'temperature':0,'seed':17,'max_tokens':128,'chat_template_kwargs':{'enable_thinking':False}}
 req=urllib.request.Request('http://127.0.0.1:8140/v1/chat/completions',data=json.dumps(data).encode(),headers={'Content-Type':'application/json'})
 start=time.monotonic()
 with urllib.request.urlopen(req,timeout=180) as response:result=json.load(response)
 choice=result['choices'][0]
 rows.append({'prompt':prompt,'content':choice['message'].get('content'),'finish_reason':choice['finish_reason'],'usage':result.get('usage'),'seconds':time.monotonic()-start})
out={'results':rows}
if a.baseline:
 base=json.loads(pathlib.Path(a.baseline).read_text())['results']
 out['baseline']=a.baseline;out['exact_match']=[x['content']==y['content'] for x,y in zip(rows,base)];out['all_exact']=all(out['exact_match'])
pathlib.Path(a.out).write_text(json.dumps(out,indent=2));print(json.dumps(out),flush=True)
