Spaces:
Sleeping
Sleeping
File size: 5,958 Bytes
4e20ec4 |
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 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
#!/usr/bin/env python3
"""
Environment Variables Debug Script for HF Spaces
Helps diagnose the 'str expected, not NoneType' error
"""
import os
import sys
from pathlib import Path
def check_environment():
"""Check all required environment variables and configurations"""
print("π AgentGraph Environment Debug Report")
print("=" * 50)
print()
# Critical environment variables
env_vars = {
"OPENAI_API_KEY": "β REQUIRED - OpenAI API access",
"LANGFUSE_PUBLIC_KEY": "π‘ Optional - AI monitoring",
"LANGFUSE_SECRET_KEY": "π‘ Optional - AI monitoring",
"LANGFUSE_HOST": "π‘ Optional - AI monitoring",
"OPENAI_MODEL_NAME": "π‘ Optional - defaults to gpt-4o-mini",
"DB_URI": "π‘ Optional - defaults to SQLite",
"PYTHONPATH": "π§ System variable",
"HOME": "π§ System variable",
"PATH": "π§ System variable"
}
print("π Environment Variables Check:")
print("-" * 30)
missing_critical = []
for var, description in env_vars.items():
value = os.getenv(var)
if value is None:
status = "β NOT SET"
if "REQUIRED" in description:
missing_critical.append(var)
elif value == "":
status = "β οΈ EMPTY"
if "REQUIRED" in description:
missing_critical.append(var)
else:
# Mask sensitive values
if "KEY" in var or "SECRET" in var:
masked_value = f"{value[:8]}..." if len(value) > 8 else "***"
status = f"β
SET ({masked_value})"
else:
status = f"β
SET ({value[:50]}...)" if len(value) > 50 else f"β
SET ({value})"
print(f" {var:20} | {status:25} | {description}")
print()
# Check critical paths and files
print("π Critical Paths Check:")
print("-" * 25)
paths_to_check = [
("Current directory", Path.cwd()),
("utils/config.py", Path("utils/config.py")),
("backend/app.py", Path("backend/app.py")),
("main.py", Path("main.py")),
("pyproject.toml", Path("pyproject.toml"))
]
for name, path in paths_to_check:
if path.exists():
status = "β
EXISTS"
else:
status = "β MISSING"
print(f" {name:20} | {status:15} | {path}")
print()
# Python path check
print("π Python Environment:")
print("-" * 20)
print(f" Python version: {sys.version}")
print(f" Python path: {sys.executable}")
print(f" Working directory: {os.getcwd()}")
print(f" PYTHONPATH: {os.getenv('PYTHONPATH', 'NOT SET')}")
print()
# Try importing critical modules
print("π¦ Import Test:")
print("-" * 15)
modules_to_test = [
"utils.config",
"backend.app",
"fastapi",
"uvicorn",
"pydantic",
"sqlalchemy"
]
for module in modules_to_test:
try:
__import__(module)
print(f" {module:20} | β
OK")
except ImportError as e:
print(f" {module:20} | β FAILED: {str(e)}")
except Exception as e:
print(f" {module:20} | β οΈ ERROR: {str(e)}")
print()
# Summary
print("π Summary:")
print("-" * 10)
if missing_critical:
print(f"β CRITICAL: Missing required environment variables: {', '.join(missing_critical)}")
print("π§ Fix: Set these variables in HF Spaces Settings > Environment variables")
return False
else:
print("β
All critical environment variables are set")
# Try to identify the specific error
print()
print("π Specific Error Analysis:")
print("The 'str expected, not NoneType' error suggests:")
print("1. A string parameter is being passed None instead of a string")
print("2. Most likely in configuration or initialization code")
print("3. Check Pydantic model validation or string concatenation")
return True
def test_config_import():
"""Test importing and using the config module"""
print()
print("π§ͺ Config Module Test:")
print("-" * 20)
try:
from utils.config import OPENAI_API_KEY, validate_config
print(f"OPENAI_API_KEY loaded: {'β
YES' if OPENAI_API_KEY else 'β NO'}")
# Test validation
is_valid = validate_config()
print(f"Config validation: {'β
PASSED' if is_valid else 'β FAILED'}")
return is_valid
except Exception as e:
print(f"β Config import failed: {str(e)}")
return False
if __name__ == "__main__":
print("Starting environment debug check...")
print()
# Basic environment check
env_ok = check_environment()
# Config test
config_ok = test_config_import()
print()
print("π― RECOMMENDATIONS:")
print("=" * 20)
if not env_ok:
print("1. β Set missing OPENAI_API_KEY in HF Spaces environment variables")
print("2. π Go to: https://huggingface.co/spaces/holistic-ai/AgentGraph/settings")
print("3. π Add: OPENAI_API_KEY = your_openai_api_key")
if not config_ok:
print("4. π§ Check utils/config.py for import issues")
print("5. π Verify Python dependencies are installed correctly")
if env_ok and config_ok:
print("β
Environment looks good!")
print("π The 'str expected, not NoneType' error may be in:")
print(" β’ Pydantic model validation")
print(" β’ String formatting/concatenation")
print(" β’ Database connection string")
print(" β’ FastAPI configuration")
print()
print("π Run this script in HF Spaces to get the exact error location!")
|