Spaces:
Sleeping
Sleeping
official.ghost.logic
commited on
Commit
·
09d5a09
1
Parent(s):
969a225
Fix startup issues for HF Spaces
Browse files- Rename app_v2.py → app.py (HF Spaces requirement)
- Update config.py to not fail on missing API keys
- Add graceful warnings instead of errors
- App will now start and show friendly messages in UI
- Added has_any_api_key() and get_available_providers() helpers
- src/config.py +24 -2
src/config.py
CHANGED
|
@@ -101,15 +101,37 @@ class Config:
|
|
| 101 |
|
| 102 |
def _validate(self):
|
| 103 |
"""Validate configuration and API keys"""
|
|
|
|
|
|
|
| 104 |
if not self.anthropic_api_key and self.model.primary_provider == "anthropic":
|
| 105 |
-
|
|
|
|
| 106 |
|
| 107 |
if not self.google_api_key and self.model.memory_provider == "google":
|
| 108 |
-
|
| 109 |
|
| 110 |
# Ensure database directory exists
|
| 111 |
self.database.ensure_db_dir()
|
| 112 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
def get_model_config(self, task_type: str = "balanced") -> dict:
|
| 114 |
"""Get model configuration for specific task type"""
|
| 115 |
temp_map = {
|
|
|
|
| 101 |
|
| 102 |
def _validate(self):
|
| 103 |
"""Validate configuration and API keys"""
|
| 104 |
+
# Don't fail startup on missing keys - just warn
|
| 105 |
+
# The UI will show appropriate error messages when features are used
|
| 106 |
if not self.anthropic_api_key and self.model.primary_provider == "anthropic":
|
| 107 |
+
print("⚠️ Warning: ANTHROPIC_API_KEY not found in environment")
|
| 108 |
+
print(" Configure API keys in Settings → Variables and secrets")
|
| 109 |
|
| 110 |
if not self.google_api_key and self.model.memory_provider == "google":
|
| 111 |
+
print("⚠️ Warning: GOOGLE_API_KEY not found for memory model")
|
| 112 |
|
| 113 |
# Ensure database directory exists
|
| 114 |
self.database.ensure_db_dir()
|
| 115 |
|
| 116 |
+
def has_any_api_key(self) -> bool:
|
| 117 |
+
"""Check if at least one API key is configured"""
|
| 118 |
+
return bool(
|
| 119 |
+
self.anthropic_api_key or
|
| 120 |
+
self.openai_api_key or
|
| 121 |
+
self.google_api_key
|
| 122 |
+
)
|
| 123 |
+
|
| 124 |
+
def get_available_providers(self) -> list[str]:
|
| 125 |
+
"""Get list of providers with configured API keys"""
|
| 126 |
+
providers = []
|
| 127 |
+
if self.anthropic_api_key:
|
| 128 |
+
providers.append("anthropic")
|
| 129 |
+
if self.openai_api_key:
|
| 130 |
+
providers.append("openai")
|
| 131 |
+
if self.google_api_key:
|
| 132 |
+
providers.append("google")
|
| 133 |
+
return providers
|
| 134 |
+
|
| 135 |
def get_model_config(self, task_type: str = "balanced") -> dict:
|
| 136 |
"""Get model configuration for specific task type"""
|
| 137 |
temp_map = {
|