import json, urllib.request, collections, sys
KEY=open('/home/lkraven/.config/litellm/infra-ops-key').read().strip()
P="A farmer has 17 sheep. All but 9 run away. He then buys twice as many as he has left, and sells 4. How many does he have? Explain your reasoning."

def raw(model, extra, n=6, maxtok=2048):
    tally=collections.Counter()
    for i in range(n):
        body={"model":model,"messages":[{"role":"user","content":P}],"max_tokens":maxtok}
        body.update(extra)
        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]; m=c["message"]
        cont=m.get("content") or ""; reas=m.get("reasoning_content") or ""
        leak = "<think>" in cont
        tally["n"]+=1
        if leak: tally["LEAK_think_in_content"]+=1
        if not cont.strip(): tally["empty_content"]+=1
        if reas: tally["reasoning_captured"]+=1
        tally[f"finish_{c.get('finish_reason')}"]+=1
        print(f"    #{i}: finish={c.get('finish_reason'):<7} content={len(cont):<5} reasoning={len(reas):<6} leak={leak}")
    return tally

print("=== ARM A: current gen config (enable_thinking=false), direct to vLLM ===")
a=raw("qwen3.8-27b-uncensored", {"chat_template_kwargs":{"enable_thinking":False},
      "temperature":0.7,"top_p":0.8,"presence_penalty":1.5,
      "top_k":20,"min_p":0.0,"repetition_penalty":1.0})
print("  TALLY:", dict(a)); print()

print("=== ARM B: enable_thinking=TRUE + reasoning_effort=low (proposed fix) ===")
b=raw("qwen3.8-27b-uncensored", {"chat_template_kwargs":{"enable_thinking":True,"reasoning_effort":"low"},
      "temperature":0.7,"top_p":0.8,"presence_penalty":1.5,
      "top_k":20,"min_p":0.0,"repetition_penalty":1.0})
print("  TALLY:", dict(b))
