|
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
# 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
- Visit: https://aistudio.google.com/
- Sign in with your Google account
Step 2: Create API Key
- Click "Get API Key"
- Create a new project or select existing
- Click "Create API Key"
- Copy the generated key
Step 3: Secure Your Key
- β
Store in
.envfile (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):
- Default values (built into the code)
.envfile (if present and python-dotenv installed)- 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
.envfiles for development - Use environment variables in production
- Add
.envto.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
- Run setup:
python setup_env.py - Edit
.env: Add yourGOOGLE_API_KEY - Test:
python simple_test.py - Use:
streamlit run tfa_ui/app.py
The application works immediately with mock data, and adding a real API key enables full agent functionality!