import sys, time, requests
sys.path.insert(0, '.')
from backend.config import _load_settings

s = _load_settings()
gemini_key = s.get('gemini_api_key', '')

# 1. qwen3.5:2b (fast model, already in GPU)
t0 = time.time()
r = requests.post('http://localhost:11434/api/chat', json={
    'model': 'qwen3.5:2b',
    'messages': [{'role': 'user', 'content': '3x4=?'}],
    'stream': False,
    'options': {'num_ctx': 1024}
}, timeout=30)
ans = r.json().get('message', {}).get('content', '') if r.status_code == 200 else f'HTTP {r.status_code}'
print(f'qwen3.5:2b (fast): {round(time.time()-t0, 1)}s - {ans[:60]}')

# 2. deepseek-v4-flash:cloud (main model)
t0 = time.time()
r2 = requests.post('http://localhost:11434/api/chat', json={
    'model': 'deepseek-v4-flash:cloud',
    'messages': [{'role': 'user', 'content': '3x4=?'}],
    'stream': False,
    'options': {'num_ctx': 1024}
}, timeout=15)
ans2 = r2.json().get('message', {}).get('content', '') if r2.status_code == 200 else f'HTTP {r2.status_code}: {r2.text[:80]}'
print(f'deepseek-v4-flash:cloud: {round(time.time()-t0, 1)}s - {ans2[:80]}')

# 3. gemini-2.5-flash
if gemini_key:
    t0 = time.time()
    r3 = requests.post(
        f'https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent',
        params={'key': gemini_key},
        json={'contents': [{'parts': [{'text': '3x4=?'}]}]},
        timeout=15
    )
    ans3 = r3.json()['candidates'][0]['content']['parts'][0]['text'][:60] if r3.status_code == 200 else f'HTTP {r3.status_code}'
    print(f'gemini-2.5-flash: {round(time.time()-t0, 1)}s - {ans3}')
else:
    print('gemini: no key')
