Explorer
/proc/58/root/tmp/test_qwen_reasoning.py
← Zurück ↓ Download
#!/usr/bin/env python3
"""Direct OpenRouter test: qwen/qwen3.7-flash with reasoning.effort=none"""

import json, urllib.request

key = ""
with open("/etc/graphiti/graphiti.env") as f:
    for line in f:
        if line.startswith("OPENROUTER_API_KEY="):
            key = line.split("=", 1)[1].strip()
            break

if not key:
    raise SystemExit("No OPENROUTER_API_KEY found")

payload = {
    "model": "qwen/qwen3.7-flash",
    "messages": [{"role": "user", "content": "Test reasoning none"}],
    "max_tokens": 50,
    "reasoning": {"effort": "none"}
}

req = urllib.request.Request(
    "https://openrouter.ai/api/v1/chat/completions",
    data=json.dumps(payload).encode(),
    headers={"Content-Type": "application/json", "Authorization": f"Bearer {key}"},
)

resp = urllib.request.urlopen(req, timeout=60)
data = json.loads(resp.read())

choice = data["choices"][0]
msg = choice["message"]
c = msg.get("content")
r = msg.get("reasoning", "")

print(f"HTTP OK (status {resp.status})")
print(f"Model: {data['model']}")
print(f"content NULL: {c is None}")
print(f"content value: {repr(c)}")
print(f"reasoning present: {bool(r)}")
print(f"reasoning value: {repr(r[:80] if r else '')}")

# Also test structured output prompt
struct_payload = {
    "model": "qwen/qwen3.7-flash",
    "messages": [
        {"role": "system", "content": "You are an AI that outputs JSON only. Output exactly: {\"status\":\"ok\",\"value\":42}"},
        {"role": "user", "content": "Respond with JSON."}
    ],
    "max_tokens": 100,
    "reasoning": {"effort": "none"}
}

req2 = urllib.request.Request(
    "https://openrouter.ai/api/v1/chat/completions",
    data=json.dumps(struct_payload).encode(),
    headers={"Content-Type": "application/json", "Authorization": f"Bearer {key}"},
)

try:
    resp2 = urllib.request.urlopen(req2, timeout=60)
    data2 = json.loads(resp2.read())
    msg2 = data2["choices"][0]["message"]
    c2 = msg2.get("content")
    print(f"\nStructured output test:")
    print(f"content NULL: {c2 is None}")
    if c2:
        try:
            j = json.loads(c2)
            print(f"Parsed JSON successfully: {j}")
        except:
            print(f"JSON parse failed, raw content: {repr(c2[:200])}")
except Exception as e2:
    print(f"Structured output test ERROR: {e2}")