Spaces:
Sleeping

TFA / CONFIGURATION.md
VAH6002's picture
Upload 61 files
1af9fb8 verified
|
Raw History Blame Contribute Delete
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

# Copy the example file
cp .env.example .env

# Or run the setup script
python setup_env.py

Step 2: Edit .env file

# Open .env in your editor
nano .env
# or
code .env

Step 3: Add your API key

# 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)

$env:GOOGLE_API_KEY="your-api-key-here"

Windows (Command Prompt)

set GOOGLE_API_KEY=your-api-key-here

Linux/macOS (Bash)

export GOOGLE_API_KEY="your-api-key-here"

Permanent Setup (Linux/macOS)

# Add to ~/.bashrc or ~/.zshrc
echo 'export GOOGLE_API_KEY="your-api-key-here"' >> ~/.bashrc
source ~/.bashrc

3. 🐳 Docker Environment

Dockerfile

ENV GOOGLE_API_KEY=your-api-key-here

Docker Compose

version: '3.8'
services:
  tfa:
    build: .
    environment:
      - GOOGLE_API_KEY=your-api-key-here
    ports:
      - "8501:8501"

Docker Run

docker run -e GOOGLE_API_KEY=your-api-key-here tfa-app

4. ☁️ Cloud Deployment

Google Cloud Run

gcloud run deploy tfa-app \
  --set-env-vars GOOGLE_API_KEY=your-api-key-here

AWS ECS/Fargate

{
  "environment": [
    {
      "name": "GOOGLE_API_KEY",
      "value": "your-api-key-here"
    }
  ]
}

Kubernetes

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:

# 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

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

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

# 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

# Install missing dependencies
pip install -r requirements.txt

Configuration Not Loading

# 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:

# 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:

# 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!