Spaces:
Sleeping
Sleeping
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") |