File size: 3,497 Bytes
8c867ac
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3412a0d
8c867ac
 
3412a0d
8c867ac
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""
check_keys.py β€” paste into a HF Space file and read the startup logs,
OR add as a temporary check tab in app.py.
Run: python check_keys.py
"""
import os

print("\n" + "="*50)
print("KEY & MODEL HEALTH CHECK")
print("="*50)

# ── 1. Check raw env vars ─────────────────────────────────────────────────────
keys = {
    "MISTRAL_API_KEY": os.getenv("MISTRAL_API_KEY"),
    "GROQ_API_KEY":    os.getenv("GROQ_API_KEY"),
    "GEMINI_API_KEY":  os.getenv("GEMINI_API_KEY"),
    "GOOGLE_API_KEY":  os.getenv("GOOGLE_API_KEY"),
    "OPENAI_API_KEY":  os.getenv("OPENAI_API_KEY"),   # should be absent now
}
print("\n── Secrets present ──")
for k, v in keys.items():
    status = "βœ… set" if v else "❌ missing"
    masked = (v[:6] + "..." + v[-3:]) if v and len(v) > 9 else "(empty)"
    print(f"  {k:25s} {status}   {masked if v else ''}")

# remap for google
if not os.getenv("GOOGLE_API_KEY") and os.getenv("GEMINI_API_KEY"):
    os.environ["GOOGLE_API_KEY"] = os.environ["GEMINI_API_KEY"]
    print("\n  ↳ Remapped GEMINI_API_KEY β†’ GOOGLE_API_KEY")

# ── 2. Test Mistral ───────────────────────────────────────────────────────────
print("\n── Mistral (mistral-small-latest) ──")
try:
    from langchain_mistralai import ChatMistralAI
    from langchain_core.messages import HumanMessage
    llm = ChatMistralAI(model="mistral-small-latest", temperature=0)
    r = llm.invoke([HumanMessage(content="Reply with just: OK")])
    print(f"  βœ… Response: {r.content.strip()[:60]}")
except Exception as e:
    print(f"  ❌ FAILED: {e}")

# ── 3. Test Gemini ────────────────────────────────────────────────────────────
print("\n── Gemini (gemini-2.5-flash) ──")
try:
    from langchain_google_genai import ChatGoogleGenerativeAI
    llm = ChatGoogleGenerativeAI(model="gemini-2.5-flash", temperature=0)
    r = llm.invoke([HumanMessage(content="Reply with just: OK")])
    print(f"  βœ… Response: {r.content.strip()[:60]}")
except Exception as e:
    print(f"  ❌ FAILED: {e}")

# ── 4. Test Groq ──────────────────────────────────────────────────────────────
print("\n── Groq (llama-3.3-70b-versatile) ──")
try:
    from langchain_groq import ChatGroq
    llm = ChatGroq(model="llama-3.3-70b-versatile", temperature=0)
    r = llm.invoke([HumanMessage(content="Reply with just: OK")])
    print(f"  βœ… Response: {r.content.strip()[:60]}")
except Exception as e:
    print(f"  ❌ FAILED: {e}")

# ── 5. Test MiniLM ───────────────────────────────────────────────────────────
print("\n── MiniLM (all-MiniLM-L6-v2) ──")
try:
    from sentence_transformers import SentenceTransformer
    m = SentenceTransformer("all-MiniLM-L6-v2")
    e = m.encode(["test sentence"], normalize_embeddings=True)
    print(f"  βœ… Embedding shape: {e.shape}  (expected: (1, 384))")
except Exception as e:
    print(f"  ❌ FAILED: {e}")

print("\n" + "="*50 + "\n")