import json, urllib.request, collections
P="A farmer has 17 sheep. All but 9 run away. He buys twice as many as he has left, then sells 4. How many now? Explain."
BASE={"temperature":0.7,"top_p":0.8,"presence_penalty":1.5,"top_k":20,"min_p":0.0,"repetition_penalty":1.0}
def run(label, ctk, n=12):
    t=collections.Counter()
    for i in range(n):
        body={"model":"qwen3.8-27b-uncensored","messages":[{"role":"user","content":P}],
              "max_tokens":2048,"chat_template_kwargs":ctk}; body.update(BASE)
        req=urllib.request.Request("http://10.250.50.54:8015/v1/chat/completions",
            data=json.dumps(body).encode(),headers={"Content-Type":"application/json"})
        d=json.loads(urllib.request.urlopen(req,timeout=300).read().decode(),strict=False)
        c=d["choices"][0]; cont=c["message"].get("content") or ""; reas=c["message"].get("reasoning_content") or ""
        t["n"]+=1
        if "<think>" in cont: t["LEAK"]+=1
        if not cont.strip(): t["EMPTY"]+=1
        if reas: t["reasoning_captured"]+=1
        t["ctok_total"]+=d.get("usage",{}).get("completion_tokens") or 0
        if c.get("finish_reason")!="stop": t["finish_"+str(c.get("finish_reason"))]+=1
    n_=t["n"]
    print(f"  {label:<44} n={n_} LEAK={t.get('LEAK',0)} EMPTY={t.get('EMPTY',0)} reas_captured={t.get('reasoning_captured',0)} avg_ctok={t['ctok_total']//n_}")
run("A: enable_thinking=false  (CURRENT gen)", {"enable_thinking":False})
run("B: enable_thinking=true + effort=low", {"enable_thinking":True,"reasoning_effort":"low"})
run("C: enable_thinking=true + effort=medium", {"enable_thinking":True,"reasoning_effort":"medium"})
