File size: 3,605 Bytes
db82745
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
"""Verify teacher API keys work."""

import os
import sys
from pathlib import Path

# Load env
from dotenv import load_dotenv
load_dotenv(Path(__file__).parent.parent / ".env")

import httpx

def test_anthropic():
    key = os.getenv("BEE_TEACHER_API_KEY", "")
    if not key:
        print("[SKIP] Anthropic: No key set")
        return False
    try:
        r = httpx.post(
            "https://api.anthropic.com/v1/messages",
            headers={
                "x-api-key": key,
                "anthropic-version": "2023-06-01",
                "content-type": "application/json",
            },
            json={
                "model": "claude-sonnet-4-20250514",
                "max_tokens": 50,
                "messages": [{"role": "user", "content": "Say 'Bee teacher connected' and nothing else."}],
            },
            timeout=15,
        )
        if r.status_code == 200:
            text = r.json()["content"][0]["text"]
            print(f"[OK]   Anthropic Claude: {text.strip()}")
            return True
        else:
            print(f"[FAIL] Anthropic: {r.status_code} β€” {r.text[:200]}")
            return False
    except Exception as e:
        print(f"[FAIL] Anthropic: {e}")
        return False


def test_openai():
    key = os.getenv("BEE_OPENAI_API_KEY", "")
    if not key:
        print("[SKIP] OpenAI: No key set")
        return False
    try:
        r = httpx.post(
            "https://api.openai.com/v1/chat/completions",
            headers={
                "Authorization": f"Bearer {key}",
                "Content-Type": "application/json",
            },
            json={
                "model": "gpt-4o-mini",
                "max_tokens": 50,
                "messages": [{"role": "user", "content": "Say 'Bee teacher connected' and nothing else."}],
            },
            timeout=15,
        )
        if r.status_code == 200:
            text = r.json()["choices"][0]["message"]["content"]
            print(f"[OK]   OpenAI GPT-4o-mini: {text.strip()}")
            return True
        else:
            print(f"[FAIL] OpenAI: {r.status_code} β€” {r.text[:200]}")
            return False
    except Exception as e:
        print(f"[FAIL] OpenAI: {e}")
        return False


def test_google():
    key = os.getenv("BEE_GOOGLE_API_KEY", "")
    if not key:
        print("[SKIP] Google: No key set")
        return False
    try:
        r = httpx.post(
            f"https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash:generateContent?key={key}",
            headers={"Content-Type": "application/json"},
            json={
                "contents": [{"parts": [{"text": "Say 'Bee teacher connected' and nothing else."}]}],
                "generationConfig": {"maxOutputTokens": 50},
            },
            timeout=15,
        )
        if r.status_code == 200:
            text = r.json()["candidates"][0]["content"]["parts"][0]["text"]
            print(f"[OK]   Google Gemini: {text.strip()}")
            return True
        else:
            print(f"[FAIL] Google: {r.status_code} β€” {r.text[:200]}")
            return False
    except Exception as e:
        print(f"[FAIL] Google: {e}")
        return False


if __name__ == "__main__":
    print("=" * 50)
    print("BEE TEACHER API β€” CONNECTION TEST")
    print("=" * 50)
    results = []
    results.append(("Anthropic", test_anthropic()))
    results.append(("OpenAI", test_openai()))
    results.append(("Google", test_google()))

    ok = sum(1 for _, v in results if v)
    print(f"\n{ok}/3 teacher APIs connected")
    print("=" * 50)