File size: 5,575 Bytes
07c2476 | 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 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 | # Environment Variables
Configuration for the AI Imaging Agent is managed via environment variables, typically defined in a `.env` file.
## Required Variables
### OPENAI_API_KEY
OpenAI API key for vision-language model calls.
```dotenv
OPENAI_API_KEY=sk-xxxx
```
**Where to get it**: [OpenAI API Keys](https://platform.openai.com/api-keys)
**Required**: Yes (unless using alternative model provider)
**Used by**: Agent VLM calls, tool selection
## Optional Variables
### SOFTWARE_CATALOG
Path to the software catalog JSONL file.
```dotenv
SOFTWARE_CATALOG=dataset/catalog.jsonl
```
**Default**: `dataset/catalog.jsonl`
**Required**: No (uses default)
### TOP_K
Number of candidate tools to retrieve from FAISS search.
```dotenv
TOP_K=8
```
**Default**: `8`
**Range**: 1-50 (recommended: 5-10)
**Impact**: More candidates = better recall but slower VLM calls
### NUM_CHOICES
Number of final tool recommendations to return to user.
```dotenv
NUM_CHOICES=3
```
**Default**: `3`
**Range**: 1-10 (recommended: 3-5)
**Impact**: Too many recommendations can overwhelm users
### GITHUB_TOKEN
GitHub personal access token for repository info tool.
```dotenv
GITHUB_TOKEN=ghp_xxxx
```
**Where to get it**: [GitHub Tokens](https://github.com/settings/tokens)
**Permissions needed**: `public_repo` (read access)
**Required**: No (tool gracefully degrades without it)
**Benefits**: Higher API rate limits, access to private repos
### SYNC_EVERY_HOURS
Auto-refresh catalog interval in hours.
```dotenv
SYNC_EVERY_HOURS=24
```
**Default**: `0` (disabled)
**Range**: 0 (disabled) or ≥1
**Behavior**: Background thread checks catalog every N hours and rebuilds index if changed
## Logging Configuration
### LOGLEVEL_CONSOLE
Console logging level.
```dotenv
LOGLEVEL_CONSOLE=WARNING
```
**Options**: `DEBUG`, `INFO`, `WARNING`, `ERROR`, `CRITICAL`
**Default**: `WARNING`
**Recommendation**:
- Development: `DEBUG` or `INFO`
- Production: `WARNING`
### LOGLEVEL_FILE
File logging level.
```dotenv
LOGLEVEL_FILE=INFO
```
**Options**: `DEBUG`, `INFO`, `WARNING`, `ERROR`, `CRITICAL`
**Default**: `INFO`
**Files written to**: `logs/app_YYYYMMDD.log`
### FILE_LOG
Enable file logging.
```dotenv
FILE_LOG=1
```
**Options**: `0` (disabled), `1` (enabled)
**Default**: `1`
### LOG_DIR
Directory for log files.
```dotenv
LOG_DIR=logs
```
**Default**: `logs`
**Created automatically** if it doesn't exist
### LOG_PROMPTS
Save VLM prompts and images for debugging.
```dotenv
LOG_PROMPTS=1
```
**Options**: `0` (disabled), `1` (enabled)
**Default**: `0`
**Writes to**: `logs/prompts/YYYYMMDD_HHMMSS/`
**Contents**:
- `prompt.txt`: Text prompt sent to VLM
- `image_*.png`: Images included in prompt
- `response.json`: VLM response
- `metadata.json`: Request metadata
**Warning**: Can consume significant disk space over time
## Model Configuration
### CONFIG_PATH
Path to YAML model configuration file.
```dotenv
CONFIG_PATH=config.yaml
```
**Default**: `config.yaml`
**See**: `config.yaml` for model configuration details
### Alternative Model Providers
For custom OpenAI-compatible endpoints, configure in `config.yaml`:
```yaml
agent_model:
name: "model-name"
base_url: "https://api.example.com/v1"
api_key_env: "CUSTOM_API_KEY"
```
Then in `.env`:
```dotenv
CUSTOM_API_KEY=your-key-here
```
<!-- ## Advanced Configuration
### RERANK_TOP_N
Number of candidates to retrieve before reranking.
```dotenv
RERANK_TOP_N=20
```
**Default**: `20`
**Interaction with TOP_K**:
- FAISS retrieves `RERANK_TOP_N` candidates (e.g., 20)
- CrossEncoder reranks them
- Top `TOP_K` (e.g., 8) passed to VLM
**Recommendation**: 2-3x `TOP_K` value
-->
## .env File Example
Complete example `.env` file:
```dotenv
# Required
OPENAI_API_KEY=sk-xxxx
# Optional: Alternative providers
EPFL_API_KEY=sk-xxxx
GITHUB_TOKEN=ghp_xxxx
# Catalog
SOFTWARE_CATALOG=dataset/catalog.jsonl
SYNC_EVERY_HOURS=24
# Pipeline
TOP_K=8
NUM_CHOICES=3
# Logging
LOGLEVEL_CONSOLE=WARNING
LOGLEVEL_FILE=INFO
FILE_LOG=1
LOG_DIR=logs
LOG_PROMPTS=0 # Set to 1 for debugging
# Model configuration
CONFIG_PATH=config.yaml
```
## Loading Environment Variables
### Automatic Loading
The application automatically loads `.env` from the repository root:
```python
from dotenv import load_dotenv
load_dotenv() # Loads .env automatically
```
### Manual Loading
```bash
# Export manually
export OPENAI_API_KEY=sk-xxxx
export TOP_K=8
# Or source .env
set -a
source .env
set +a
```
### Docker
Pass environment variables to Docker:
```bash
docker run --env-file .env ai-agent
```
## Security Best Practices
!!! warning "Never commit .env files"
Add `.env` to `.gitignore` to prevent accidental commits
!!! warning "Protect API keys"
Treat API keys as sensitive credentials:
- Never share in public repositories
- Rotate keys if exposed
- Use environment-specific keys (dev/prod)
!!! tip "Use .env.example"
Create `.env.example` with dummy values for documentation:
```dotenv
OPENAI_API_KEY=sk-your-key-here
GITHUB_TOKEN=ghp-your-token-here
```
## Next Steps
- Review [CLI Commands](cli.md)
- Check [Configuration Guide](../getting-started/configuration.md)
- See [Changelog](changelog.md)
|