File size: 2,344 Bytes
df97e68
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
"""
test_all_models.py — Manual NVIDIA API connectivity test.

NOT a pytest unit test. Run directly:
    python tests/test_all_models.py

Tests each model in the global pool with a minimal API call.
"""

import os
import time
import sys
from pathlib import Path

_ROOT = Path(__file__).resolve().parent.parent
if str(_ROOT) not in sys.path:
    sys.path.insert(0, str(_ROOT))

from dotenv import load_dotenv
load_dotenv(dotenv_path=_ROOT / ".env", override=False)

from baseline_openai import GLOBAL_MODEL_POOL, FREE_POOL

MODELS_TO_TEST = GLOBAL_MODEL_POOL.copy()

key1 = os.getenv("NVIDIA_API_KEY")
key2 = os.getenv("NVIDIA_API_KEY_2")


def test_model(model_name, api_key, label):
    if not api_key:
        return "SKIP (No API Key)"

    from openai import OpenAI
    client = OpenAI(base_url="https://integrate.api.nvidia.com/v1", api_key=api_key)
    print(f"Testing {label} model: {model_name}...", end="", flush=True)

    try:
        start = time.time()
        response = client.chat.completions.create(
            model=model_name,
            messages=[{"role": "user", "content": "Return the word 'OK' and nothing else."}],
            max_tokens=5,
            temperature=0.0,
        )
        elapsed = time.time() - start
        content = response.choices[0].message.content.strip()
        print(f" SUCCESS ({elapsed:.2f}s) -> '{content}'")
        return "PASS"
    except Exception as e:
        print(f" FAILED: {str(e)[:100]}")
        return f"FAIL: {str(e)[:100]}"


if __name__ == "__main__":
    results = {}

    print("\n=== Testing Primary/Backup Models (Key 1) ===")
    for m in MODELS_TO_TEST:
        results[m] = test_model(m, key1, "Primary")
        time.sleep(1)

    print("\n=== Testing Free Pool Models (Key 2) ===")
    for m in FREE_POOL:
        results[m] = test_model(m, key2 or key1, "Free")
        time.sleep(1)

    print("\n\n" + "=" * 50)
    print(f"{'Model Name':<50} | {'Status'}")
    print("-" * 70)
    for m, status in results.items():
        print(f"{m:<50} | {status}")
    print("=" * 50)

    fails = [m for m, s in results.items() if s.startswith("FAIL")]
    summary = f"Tested {len(results)} models. "
    if fails:
        summary += f"Found {len(fails)} failures: {', '.join(fails)}"
    else:
        summary += "All tests passed!"
    print(f"\nSummary: {summary}")