aadisawant2912 commited on
Commit
8c867ac
Β·
verified Β·
1 Parent(s): e7a16e9

Create check_keys.py

Browse files
Files changed (1) hide show
  1. check_keys.py +72 -0
check_keys.py ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ check_keys.py β€” paste into a HF Space file and read the startup logs,
3
+ OR add as a temporary check tab in app.py.
4
+ Run: python check_keys.py
5
+ """
6
+ import os
7
+
8
+ print("\n" + "="*50)
9
+ print("KEY & MODEL HEALTH CHECK")
10
+ print("="*50)
11
+
12
+ # ── 1. Check raw env vars ─────────────────────────────────────────────────────
13
+ keys = {
14
+ "MISTRAL_API_KEY": os.getenv("MISTRAL_API_KEY"),
15
+ "GROQ_API_KEY": os.getenv("GROQ_API_KEY"),
16
+ "GEMINI_API_KEY": os.getenv("GEMINI_API_KEY"),
17
+ "GOOGLE_API_KEY": os.getenv("GOOGLE_API_KEY"),
18
+ "OPENAI_API_KEY": os.getenv("OPENAI_API_KEY"), # should be absent now
19
+ }
20
+ print("\n── Secrets present ──")
21
+ for k, v in keys.items():
22
+ status = "βœ… set" if v else "❌ missing"
23
+ masked = (v[:6] + "..." + v[-3:]) if v and len(v) > 9 else "(empty)"
24
+ print(f" {k:25s} {status} {masked if v else ''}")
25
+
26
+ # remap for google
27
+ if not os.getenv("GOOGLE_API_KEY") and os.getenv("GEMINI_API_KEY"):
28
+ os.environ["GOOGLE_API_KEY"] = os.environ["GEMINI_API_KEY"]
29
+ print("\n ↳ Remapped GEMINI_API_KEY β†’ GOOGLE_API_KEY")
30
+
31
+ # ── 2. Test Mistral ───────────────────────────────────────────────────────────
32
+ print("\n── Mistral (mistral-small-latest) ──")
33
+ try:
34
+ from langchain_mistralai import ChatMistralAI
35
+ from langchain_core.messages import HumanMessage
36
+ llm = ChatMistralAI(model="mistral-small-latest", temperature=0)
37
+ r = llm.invoke([HumanMessage(content="Reply with just: OK")])
38
+ print(f" βœ… Response: {r.content.strip()[:60]}")
39
+ except Exception as e:
40
+ print(f" ❌ FAILED: {e}")
41
+
42
+ # ── 3. Test Gemini ────────────────────────────────────────────────────────────
43
+ print("\n── Gemini (gemini-1.5-flash-latest) ──")
44
+ try:
45
+ from langchain_google_genai import ChatGoogleGenerativeAI
46
+ llm = ChatGoogleGenerativeAI(model="gemini-1.5-flash-latest", temperature=0)
47
+ r = llm.invoke([HumanMessage(content="Reply with just: OK")])
48
+ print(f" βœ… Response: {r.content.strip()[:60]}")
49
+ except Exception as e:
50
+ print(f" ❌ FAILED: {e}")
51
+
52
+ # ── 4. Test Groq ──────────────────────────────────────────────────────────────
53
+ print("\n── Groq (llama-3.3-70b-versatile) ──")
54
+ try:
55
+ from langchain_groq import ChatGroq
56
+ llm = ChatGroq(model="llama-3.3-70b-versatile", temperature=0)
57
+ r = llm.invoke([HumanMessage(content="Reply with just: OK")])
58
+ print(f" βœ… Response: {r.content.strip()[:60]}")
59
+ except Exception as e:
60
+ print(f" ❌ FAILED: {e}")
61
+
62
+ # ── 5. Test MiniLM ───────────────────────────────────────────────────────────
63
+ print("\n── MiniLM (all-MiniLM-L6-v2) ──")
64
+ try:
65
+ from sentence_transformers import SentenceTransformer
66
+ m = SentenceTransformer("all-MiniLM-L6-v2")
67
+ e = m.encode(["test sentence"], normalize_embeddings=True)
68
+ print(f" βœ… Embedding shape: {e.shape} (expected: (1, 384))")
69
+ except Exception as e:
70
+ print(f" ❌ FAILED: {e}")
71
+
72
+ print("\n" + "="*50 + "\n")