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."
def run(label, params, 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":{"enable_thinking":False},
              "top_k":20,"min_p":0.0,"repetition_penalty":1.0}
        body.update(params)
        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 ""
        t["n"]+=1
        if "<think>" in cont: t["LEAK"]+=1
        t["ctok"]+=d.get("usage",{}).get("completion_tokens") or 0
    print(f"  {label:<52} n={t['n']} LEAK={t.get('LEAK',0)} avg_ctok={t['ctok']//t['n']}")
run("A: temp0.7 top_p0.8 pp1.5   (CURRENT gen)", {"temperature":0.7,"top_p":0.8,"presence_penalty":1.5})
run("D: temp0.7 top_p0.8 pp0.0   (drop presence_penalty)", {"temperature":0.7,"top_p":0.8,"presence_penalty":0.0})
run("E: temp0.7 top_p0.8 pp0.5   (upstream low end)", {"temperature":0.7,"top_p":0.8,"presence_penalty":0.5})
run("F: temp0   top_p0.8 pp1.5   (temp-0, like summarizer)", {"temperature":0,"top_p":0.8,"presence_penalty":1.5})
