|
Download CONFIGURATION.md from VAH6002/TFA: direct link, hf CLI and curl.
- Browser
- Download file 5.97 kB
-
https://huggingface.co/spaces/VAH6002/TFA/resolve/main/CONFIGURATION.md
- Command line
-
hf download hf://spaces/VAH6002/TFA/CONFIGURATION.md
-
curl -L -o CONFIGURATION.md https://huggingface.co/spaces/VAH6002/TFA/resolve/main/CONFIGURATION.md
5.97 kB
| # TFA Configuration Guide | |
| ## π§ Configuration Options | |
| The TFA application supports multiple ways to provide configuration, including the `GOOGLE_API_KEY`. | |
| ## 1. π Recommended: `.env` File (Best for Development) | |
| ### Step 1: Create `.env` file | |
| ```bash | |
| # Copy the example file | |
| cp .env.example .env | |
| # Or run the setup script | |
| python setup_env.py | |
| ``` | |
| ### Step 2: Edit `.env` file | |
| ```bash | |
| # Open .env in your editor | |
| nano .env | |
| # or | |
| code .env | |
| ``` | |
| ### Step 3: Add your API key | |
| ```env | |
| # Required: Google API Key for Gemini/ADK | |
| GOOGLE_API_KEY=your-actual-google-api-key-here | |
| # Optional: Other configuration | |
| SPONGE_API_ENDPOINT=https://sponge.corp.google.com/api/v2 | |
| TFA_LOG_LEVEL=INFO | |
| ``` | |
| ## 2. π Environment Variables (Best for Production) | |
| ### Windows (PowerShell) | |
| ```powershell | |
| $env:GOOGLE_API_KEY="your-api-key-here" | |
| ``` | |
| ### Windows (Command Prompt) | |
| ```cmd | |
| set GOOGLE_API_KEY=your-api-key-here | |
| ``` | |
| ### Linux/macOS (Bash) | |
| ```bash | |
| export GOOGLE_API_KEY="your-api-key-here" | |
| ``` | |
| ### Permanent Setup (Linux/macOS) | |
| ```bash | |
| # Add to ~/.bashrc or ~/.zshrc | |
| echo 'export GOOGLE_API_KEY="your-api-key-here"' >> ~/.bashrc | |
| source ~/.bashrc | |
| ``` | |
| ## 3. π³ Docker Environment | |
| ### Dockerfile | |
| ```dockerfile | |
| ENV GOOGLE_API_KEY=your-api-key-here | |
| ``` | |
| ### Docker Compose | |
| ```yaml | |
| version: '3.8' | |
| services: | |
| tfa: | |
| build: . | |
| environment: | |
| - GOOGLE_API_KEY=your-api-key-here | |
| ports: | |
| - "8501:8501" | |
| ``` | |
| ### Docker Run | |
| ```bash | |
| docker run -e GOOGLE_API_KEY=your-api-key-here tfa-app | |
| ``` | |
| ## 4. βοΈ Cloud Deployment | |
| ### Google Cloud Run | |
| ```bash | |
| gcloud run deploy tfa-app \ | |
| --set-env-vars GOOGLE_API_KEY=your-api-key-here | |
| ``` | |
| ### AWS ECS/Fargate | |
| ```json | |
| { | |
| "environment": [ | |
| { | |
| "name": "GOOGLE_API_KEY", | |
| "value": "your-api-key-here" | |
| } | |
| ] | |
| } | |
| ``` | |
| ### Kubernetes | |
| ```yaml | |
| apiVersion: v1 | |
| kind: Secret | |
| metadata: | |
| name: tfa-secrets | |
| data: | |
| google-api-key: <base64-encoded-key> | |
| --- | |
| apiVersion: apps/v1 | |
| kind: Deployment | |
| spec: | |
| template: | |
| spec: | |
| containers: | |
| - name: tfa | |
| env: | |
| - name: GOOGLE_API_KEY | |
| valueFrom: | |
| secretKeyRef: | |
| name: tfa-secrets | |
| key: google-api-key | |
| ``` | |
| ## 5. π Getting a Google API Key | |
| ### Step 1: Go to Google AI Studio | |
| 1. Visit: https://aistudio.google.com/ | |
| 2. Sign in with your Google account | |
| ### Step 2: Create API Key | |
| 1. Click "Get API Key" | |
| 2. Create a new project or select existing | |
| 3. Click "Create API Key" | |
| 4. Copy the generated key | |
| ### Step 3: Secure Your Key | |
| - β Store in `.env` file (not committed to git) | |
| - β Use environment variables in production | |
| - β Never commit API keys to version control | |
| - β Never share API keys in public | |
| ## 6. π Configuration Priority | |
| The application loads configuration in this order (later overrides earlier): | |
| 1. **Default values** (built into the code) | |
| 2. **`.env` file** (if present and python-dotenv installed) | |
| 3. **Environment variables** (highest priority) | |
| ## 7. π§ͺ Testing Without API Key | |
| The application works with mock data even without a real API key: | |
| ```bash | |
| # These work without real API key | |
| python simple_test.py | |
| python test_mock.py | |
| python -m tfa_agents.metrics_cli daily | |
| # Web UI also works with mock data | |
| streamlit run tfa_ui/app.py | |
| ``` | |
| ## 8. π Verifying Configuration | |
| ### Check Configuration Status | |
| ```python | |
| from tfa_agents.config import get_config | |
| config = get_config() | |
| config.print_config() # Shows all config (masks sensitive values) | |
| # Check API key specifically | |
| api_key = config.get_google_api_key() | |
| if api_key: | |
| print("β API key configured") | |
| else: | |
| print("β οΈ No API key found") | |
| ``` | |
| ### CLI Configuration Check | |
| ```bash | |
| python -c "from tfa_agents.config import get_config; get_config().print_config()" | |
| ``` | |
| ## 9. π¨ Security Best Practices | |
| ### β DO: | |
| - Use `.env` files for development | |
| - Use environment variables in production | |
| - Add `.env` to `.gitignore` | |
| - Use secrets management in cloud deployments | |
| - Rotate API keys regularly | |
| ### β DON'T: | |
| - Commit API keys to version control | |
| - Share API keys in chat/email | |
| - Use production keys in development | |
| - Store keys in plain text files in production | |
| ## 10. π§ Troubleshooting | |
| ### "API key not valid" Error | |
| ```bash | |
| # Check if key is set | |
| echo $GOOGLE_API_KEY | |
| # Verify key format (should start with 'AI...') | |
| python -c "import os; print('Key format:', os.environ.get('GOOGLE_API_KEY', 'NOT SET')[:10] + '...')" | |
| ``` | |
| ### "Cannot import name 'tool'" Error | |
| ```bash | |
| # Install missing dependencies | |
| pip install -r requirements.txt | |
| ``` | |
| ### Configuration Not Loading | |
| ```bash | |
| # Install python-dotenv | |
| pip install python-dotenv | |
| # Check .env file exists | |
| ls -la .env | |
| # Run setup script | |
| python setup_env.py | |
| ``` | |
| ## 11. π Complete Example | |
| ### `.env` file: | |
| ```env | |
| # Google API Key (Required for agents) | |
| GOOGLE_API_KEY=AIzaSyD...your-actual-key-here | |
| # Optional: Sponge API (for production data) | |
| SPONGE_API_ENDPOINT=https://sponge.corp.google.com/api/v2 | |
| SPONGE_BEARER_TOKEN=your-oauth-token | |
| # Optional: Application settings | |
| TFA_LOG_LEVEL=INFO | |
| TFA_ENVIRONMENT=development | |
| TFA_USE_MOCK_DATA=false | |
| # Optional: UI settings | |
| STREAMLIT_SERVER_PORT=8501 | |
| ``` | |
| ### Usage: | |
| ```bash | |
| # Install dependencies | |
| pip install -r requirements.txt | |
| # Run setup (creates .env from template) | |
| python setup_env.py | |
| # Test configuration | |
| python simple_test.py | |
| # Use the application | |
| python -m tfa_agents.metrics_cli daily | |
| streamlit run tfa_ui/app.py | |
| ``` | |
| ## π― Quick Start | |
| 1. **Run setup**: `python setup_env.py` | |
| 2. **Edit `.env`**: Add your `GOOGLE_API_KEY` | |
| 3. **Test**: `python simple_test.py` | |
| 4. **Use**: `streamlit run tfa_ui/app.py` | |
| The application works immediately with mock data, and adding a real API key enables full agent functionality! |