File size: 4,195 Bytes
c2ea5ed
 
 
 
18efc55
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c2ea5ed
 
 
7bc750c
c2ea5ed
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18efc55
 
c2ea5ed
 
18efc55
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
from pathlib import Path
from dotenv import load_dotenv

def load_environment_variables():
    """
    Load environment variables with proper priority:
    1. System environment variables (highest priority - for production/HF Spaces)
    2. .env file (fallback for local development)
    """
    # First check if we're in a production environment (HF Spaces, Docker, etc.)
    # by looking for common production indicators
    is_production = any([
        os.getenv("SPACE_ID"),  # Hugging Face Spaces
        os.getenv("RENDER"),    # Render.com
        os.getenv("RAILWAY_ENVIRONMENT"),  # Railway
        os.getenv("VERCEL"),    # Vercel
        os.getenv("KUBERNETES_SERVICE_HOST"),  # Kubernetes
        os.getenv("AWS_LAMBDA_FUNCTION_NAME"),  # AWS Lambda
    ])
    
    # Load .env file only if not in production AND file exists
    env_path = Path('.') / '.env'
    if not is_production and env_path.exists():
        print(f"πŸ”§ Loading environment variables from {env_path}")
        load_dotenv(dotenv_path=env_path, override=False)  # Don't override existing env vars
    elif is_production:
        print("πŸš€ Production environment detected, using system environment variables")
    else:
        print("⚠️ No .env file found and not in production environment")

# Load environment variables using the unified method
load_environment_variables()

# OpenAI Configuration
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
OPENAI_MODEL_NAME = os.getenv("OPENAI_MODEL_NAME", "gpt-5-mini")

AZURE_API_KEY = os.getenv("AZURE_API_KEY")
AZURE_API_BASE = os.getenv("AZURE_API_BASE")
AZURE_API_VERSION = os.getenv("AZURE_API_VERSION")

# Langfuse Configuration
LANGFUSE_PUBLIC_KEY = os.getenv("LANGFUSE_PUBLIC_KEY")
LANGFUSE_SECRET_KEY = os.getenv("LANGFUSE_SECRET_KEY")
LANGFUSE_HOST = os.getenv("LANGFUSE_HOST", "https://cloud.langfuse.com")
LANGFUSE_AUTH = ""
if LANGFUSE_PUBLIC_KEY and LANGFUSE_SECRET_KEY:
    import base64
    LANGFUSE_AUTH = base64.b64encode(f"{LANGFUSE_PUBLIC_KEY}:{LANGFUSE_SECRET_KEY}".encode()).decode()

# Other API Keys
ANTHROPIC_API_KEY = os.getenv("ANTHROPIC_API_KEY")

# Database Configuration
DB_URI = os.getenv("DB_URI", "sqlite:///agent_monitoring.db")

# Function to validate configuration
def validate_config():
    """Validates that all required environment variables are set"""
    required_vars = [
        ("OPENAI_API_KEY", OPENAI_API_KEY),
    ]
    
    missing_vars = [var_name for var_name, var_value in required_vars if not var_value]
    
    if missing_vars:
        missing_vars_str = ", ".join(missing_vars)
        print(f"❌ Missing required environment variables: {missing_vars_str}")
        print(f"πŸ“ Please set them in the .env file or as environment variables")
        return False
    
    return True

def debug_config():
    """Debug function to show current configuration state"""
    print("πŸ” AgentGraph Configuration Debug:")
    print("=" * 50)
    
    # Show environment loading method
    env_path = Path('.') / '.env'
    is_production = any([
        os.getenv("SPACE_ID"),
        os.getenv("RENDER"),
        os.getenv("RAILWAY_ENVIRONMENT"),
        os.getenv("VERCEL"),
        os.getenv("KUBERNETES_SERVICE_HOST"),
        os.getenv("AWS_LAMBDA_FUNCTION_NAME"),
    ])
    
    print(f"πŸ—οΈ Environment: {'Production' if is_production else 'Development'}")
    print(f"πŸ“ .env file exists: {env_path.exists()}")
    print(f"πŸ“ Working directory: {Path.cwd()}")
    print()
    
    # Show key configuration values (masked)
    configs = [
        ("OPENAI_API_KEY", OPENAI_API_KEY),
        ("OPENAI_MODEL_NAME", OPENAI_MODEL_NAME),
        ("LANGFUSE_PUBLIC_KEY", LANGFUSE_PUBLIC_KEY),
        ("LANGFUSE_SECRET_KEY", LANGFUSE_SECRET_KEY),
        ("LANGFUSE_HOST", LANGFUSE_HOST),
        ("DB_URI", DB_URI),
    ]
    
    for name, value in configs:
        if value:
            if "KEY" in name or "SECRET" in name:
                masked = f"{value[:8]}..." if len(value) > 8 else "***"
                print(f"βœ… {name}: {masked}")
            else:
                print(f"βœ… {name}: {value}")
        else:
            print(f"❌ {name}: Not set")
    
    print("=" * 50)