# Usage: python3 run.py [workers] import json, subprocess, os, sys, time, secrets, threading from concurrent.futures import ThreadPoolExecutor from collections import Counter OUT=sys.argv[1]; engines=sys.argv[2].split(','); variants=sys.argv[3].split(','); reps=int(sys.argv[4]); W=int(sys.argv[5]) if len(sys.argv)>5 else 6 os.makedirs(OUT,exist_ok=True) BASE='https://nrlc.ai/lab/fetch-test/' def prompt(url): return (f"Open this web page and tell me the verification code shown on it, exactly as written: {url}\n" "The code looks like NRLC- followed by six characters. If you cannot open the page or cannot find a code, reply NOT FOUND. Do not guess.") ENG={'chatgpt':('cloro.ai-search.chatgpt.scrape',lambda p:{"prompt":p,"country":"US","include":{"markdown":True}}), 'gemini':('cloro.ai-search.gemini.scrape',lambda p:{"prompt":p,"country":"US","include":{"markdown":True}}), 'aimode':('cloro.google.serp.ai_mode',lambda p:{"prompt":p,"gl":"US","include":{"markdown":True}}), 'perplexity':('perplexity.web.answer.fast',lambda p:{"preset":"fast","input":p,"max_steps":1,"max_output_tokens":200})} spent=[0]; lock=threading.Lock() jobs=[(e,v,k) for k in range(1,reps+1) for v in variants for e in engines] def one(job): e,v,k=job; fn=f"{OUT}/{e}__{v}__r{k:02d}.json" if os.path.exists(fn): return 'skip' run=(e[:2]+secrets.token_hex(6)).lower(); url=f"{BASE}{v}/?run={run}" tool,body=ENG[e] for attempt in range(2): t0=time.time() r=subprocess.run(['treg','--json','call',tool,'--method','POST','--header','Cache-Control: no-cache','--data',json.dumps(body(prompt(url)))],capture_output=True,text=True,timeout=400) try: d=json.loads(r.stdout) except Exception: d={'_treg':{'http_status':None},'raw':r.stdout[:500]+r.stderr[:500]} st=d.get('_treg',{}).get('http_status'); ch=d.get('_treg',{}).get('charged_micro') or 0 with lock: spent[0]+=ch d['_meta']={'engine':e,'variant':v,'rep':k,'run':run,'url':url,'ts':time.strftime('%Y-%m-%dT%H:%M:%SZ',time.gmtime(t0)),'tool':tool,'secs':round(time.time()-t0,1),'status':st} if st==200: json.dump(d,open(fn,'w')); return 'ok' time.sleep(5) json.dump(d,open(fn.replace('.json','.FAILED.json'),'w')); return 'fail' with ThreadPoolExecutor(max_workers=W) as ex: res=Counter(ex.map(one,jobs)) print(dict(res),'spent_usd',round(spent[0]/1e6,4))