File size: 1,978 Bytes
94cd5f4
 
 
 
 
 
 
 
 
 
 
0c75592
 
d23d069
 
 
0c75592
 
 
 
94cd5f4
 
 
 
d23d069
0c75592
 
94cd5f4
 
 
 
d23d069
 
 
 
94cd5f4
 
0c75592
94cd5f4
d23d069
 
 
 
 
94cd5f4
 
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
import os
import dotenv
from typing import Optional

# Load environment variables from .env file if it exists
dotenv.load_dotenv()

def get_required_env(key: str, error_message: Optional[str] = None) -> str:
    """Get a required environment variable or raise a helpful error."""
    value = os.getenv(key)
    if not value:
        api_instructions = {
            "GOOGLE_API_KEY": "1. Go to https://makersuite.google.com/app/apikey\n2. Create a new API key",
            "TAVILY_API_KEY": "1. Go to https://tavily.com/#pricing\n2. Sign up for an account\n3. Get your API key from the dashboard",
            "OAUTH_CLIENT_ID": "Enable OAuth in your Space by setting `hf_oauth: true` in the README.md Space metadata",
            "OAUTH_CLIENT_SECRET": "Enable OAuth in your Space by setting `hf_oauth: true` in the README.md Space metadata"
        }
        
        instructions = api_instructions.get(key, "Please obtain an API key from the service provider")
        
        default_message = (
            f"{key} environment variable is not set.\n"
            f"Please create a .env file in the project root with:\n"
            f"{key}=your_{key.lower()}_here\n\n"
            f"If you don't have the credentials:\n"
            f"{instructions}\n"
            f"4. Add it to your .env file"
        )
        raise ValueError(error_message or default_message)
    return value

def is_running_in_space() -> bool:
    """Check if we're running in a Hugging Face Space."""
    return bool(os.getenv("SPACE_ID"))

# Required environment variables
GOOGLE_API_KEY = get_required_env("GOOGLE_API_KEY")
TAVILY_API_KEY = get_required_env("TAVILY_API_KEY")

# OAuth is only required when running in a Space
if is_running_in_space():
    OAUTH_CLIENT_ID = get_required_env("OAUTH_CLIENT_ID")
    OAUTH_CLIENT_SECRET = get_required_env("OAUTH_CLIENT_SECRET")

# Optional environment variables with defaults
AGENT_MODEL_NAME = os.getenv("AGENT_MODEL_NAME", "gemini-2.0-flash")