import json, time, sys, requests
B="http://127.0.0.1:11434"
P=["Write a blog post of about 200 words about learning to bake bread at 40.",
"Write a blog post of about 200 words about running my first marathon.",
"Write a LinkedIn post of about 200 words about switching our 20-person agency to a four-day work week.",
"Write a LinkedIn post of about 200 words about hiring our first data engineer.",
"Write an explainer of about 200 words on how heat pumps work.",
"Write an explainer of about 200 words on what an index fund is.",
"Write an opinion piece of about 200 words on whether cities should ban cars from downtown.",
"Write an opinion piece of about 200 words on whether schools should allow phones."]
Q=[("What is 17*23? Reply with only the number.",["391"]),("What is the capital of Australia?",["canberra"]),("What is the chemical symbol for gold?",["au"]),("What is 2 to the power of 10?",["1024","1,024"]),("Who wrote 'Pride and Prejudice'?",["austen"]),("What is the largest planet in our solar system?",["jupiter"]),("What is the square root of 144?",["12"]),("At what temperature in Celsius does water boil at sea level?",["100"]),("What is the speed of light in a vacuum, approximately?",["299,792","299792","300,000","300 000","3 x 10","3×10","3 × 10","3.0 × 10","3.00 × 10","3x10"]),("In what year did the Berlin Wall fall?",["1989"]),("What is the chemical formula of table salt?",["nacl"]),("What is 15% of 80?",["12"]),("What is the longest river in Africa?",["nile"]),("Who wrote the novel '1984'?",["orwell"]),("How many continents are there?",["7","seven"]),("What is 9*7?",["63"]),("What is the smallest prime number?",["2","two"]),("What is the capital of Canada?",["ottawa"]),("What is the freezing point of water in Fahrenheit?",["32"]),("Who painted the Mona Lisa?",["leonardo","da vinci"])]
out={"started":time.strftime("%H:%M:%S"),"writing":[],"quiz":[]}
models=["deslop-local","qwen3-base-local"]
for seed in [1,2]:
  for i,p in enumerate(P):
    for m in models:
      t=time.time()
      r=requests.post(B+"/api/chat",json={"model":m,"messages":[{"role":"user","content":p}],"stream":False,"options":{"temperature":0.7,"seed":seed,"num_predict":260}},timeout=900).json()
      txt=r.get("message",{}).get("content","")
      out["writing"].append({"model":m,"seed":seed,"prompt_i":i,"prompt":p,"text":txt,"eval_tokens":r.get("eval_count"),"tok_per_s":round(r["eval_count"]/(r["eval_duration"]/1e9),1) if r.get("eval_duration") else None,"wall_s":round(time.time()-t,1)})
      print(time.strftime("%H:%M:%S"),"W",m,seed,i,out["writing"][-1]["eval_tokens"],out["writing"][-1]["tok_per_s"],flush=True)
      json.dump(out,open(sys.argv[1],"w"),indent=1,ensure_ascii=False)
for q,gt in Q:
  for m in models:
    r=requests.post(B+"/api/chat",json={"model":m,"messages":[{"role":"user","content":q}],"stream":False,"options":{"temperature":0,"seed":1,"num_predict":120}},timeout=600).json()
    a=r.get("message",{}).get("content","")
    out["quiz"].append({"model":m,"q":q,"gt":gt,"answer":a,"correct":any(g in a.lower() for g in gt)})
    print("Q",m,out["quiz"][-1]["correct"],a[:60].replace("\n"," "),flush=True)
    json.dump(out,open(sys.argv[1],"w"),indent=1,ensure_ascii=False)
out["ended"]=time.strftime("%H:%M:%S"); json.dump(out,open(sys.argv[1],"w"),indent=1,ensure_ascii=False)
