Spaces:
Sleeping
Sleeping
Add safety checks for all API keys
Browse files
core_utils/core_model_loaders.py
CHANGED
|
@@ -14,13 +14,34 @@ def load_embedding_model():
|
|
| 14 |
|
| 15 |
def load_groq_llm():
|
| 16 |
"""Loads the Groq LLM without any Streamlit dependencies."""
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
def load_gemini_llm():
|
| 20 |
"""Loads the Gemini LLM without any Streamlit dependencies."""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
return ChatGoogleGenerativeAI(
|
| 22 |
model="gemini-2.5-flash",
|
| 23 |
temperature=0,
|
| 24 |
max_retries=5,
|
| 25 |
-
google_api_key=
|
| 26 |
)
|
|
|
|
| 14 |
|
| 15 |
def load_groq_llm():
|
| 16 |
"""Loads the Groq LLM without any Streamlit dependencies."""
|
| 17 |
+
api_key = os.getenv("GROQ_API_KEY")
|
| 18 |
+
if not api_key:
|
| 19 |
+
print("CRITICAL WARNING: GROQ_API_KEY is missing. Scheme finder will fail.")
|
| 20 |
+
class DummyLLM:
|
| 21 |
+
def invoke(self, *args, **kwargs):
|
| 22 |
+
raise ValueError("GROQ_API_KEY is missing. Please check your environment variables.")
|
| 23 |
+
return DummyLLM()
|
| 24 |
+
|
| 25 |
+
return ChatGroq(
|
| 26 |
+
temperature=0,
|
| 27 |
+
model="meta-llama/llama-3.3-70b-versatile", # Switched to a standard stable model
|
| 28 |
+
api_key=api_key
|
| 29 |
+
)
|
| 30 |
|
| 31 |
def load_gemini_llm():
|
| 32 |
"""Loads the Gemini LLM without any Streamlit dependencies."""
|
| 33 |
+
api_key = os.getenv("GOOGLE_API_KEY")
|
| 34 |
+
if not api_key:
|
| 35 |
+
print("CRITICAL WARNING: GOOGLE_API_KEY is missing. AI features will fail.")
|
| 36 |
+
# Return a dummy callable that fails gracefully at runtime, not logic load time
|
| 37 |
+
class DummyLLM:
|
| 38 |
+
def invoke(self, *args, **kwargs):
|
| 39 |
+
raise ValueError("GOOGLE_API_KEY is missing. Please check your environment variables.")
|
| 40 |
+
return DummyLLM()
|
| 41 |
+
|
| 42 |
return ChatGoogleGenerativeAI(
|
| 43 |
model="gemini-2.5-flash",
|
| 44 |
temperature=0,
|
| 45 |
max_retries=5,
|
| 46 |
+
google_api_key=api_key
|
| 47 |
)
|