Spaces:
Running
Running
File size: 7,148 Bytes
016b413 |
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 |
# Configuration Guide
## Overview
DeepCritical uses **Pydantic Settings** for centralized configuration management. All settings are defined in `src/utils/config.py` and can be configured via environment variables or a `.env` file.
## Quick Start
1. Copy the example environment file (if available) or create a `.env` file in the project root
2. Set at least one LLM API key (`OPENAI_API_KEY` or `ANTHROPIC_API_KEY`)
3. Optionally configure other services as needed
## Configuration System
### How It Works
- **Settings Class**: `Settings` class in `src/utils/config.py` extends `BaseSettings` from `pydantic_settings`
- **Environment File**: Automatically loads from `.env` file (if present)
- **Environment Variables**: Reads from environment variables (case-insensitive)
- **Type Safety**: Strongly-typed fields with validation
- **Singleton Pattern**: Global `settings` instance for easy access
### Usage
```python
from src.utils.config import settings
# Check if API keys are available
if settings.has_openai_key:
# Use OpenAI
pass
# Access configuration values
max_iterations = settings.max_iterations
web_search_provider = settings.web_search_provider
```
## Required Configuration
### At Least One LLM Provider
You must configure at least one LLM provider:
**OpenAI:**
```bash
LLM_PROVIDER=openai
OPENAI_API_KEY=your_openai_api_key_here
OPENAI_MODEL=gpt-5.1
```
**Anthropic:**
```bash
LLM_PROVIDER=anthropic
ANTHROPIC_API_KEY=your_anthropic_api_key_here
ANTHROPIC_MODEL=claude-sonnet-4-5-20250929
```
## Optional Configuration
### Embedding Configuration
```bash
# Embedding Provider: "openai", "local", or "huggingface"
EMBEDDING_PROVIDER=local
# OpenAI Embedding Model (used by LlamaIndex RAG)
OPENAI_EMBEDDING_MODEL=text-embedding-3-small
# Local Embedding Model (sentence-transformers)
LOCAL_EMBEDDING_MODEL=all-MiniLM-L6-v2
# HuggingFace Embedding Model
HUGGINGFACE_EMBEDDING_MODEL=sentence-transformers/all-MiniLM-L6-v2
```
### HuggingFace Configuration
```bash
# HuggingFace API Token (for inference API)
HUGGINGFACE_API_KEY=your_huggingface_api_key_here
# Or use HF_TOKEN (alternative name)
# Default HuggingFace Model ID
HUGGINGFACE_MODEL=meta-llama/Llama-3.1-8B-Instruct
```
### Web Search Configuration
```bash
# Web Search Provider: "serper", "searchxng", "brave", "tavily", or "duckduckgo"
# Default: "duckduckgo" (no API key required)
WEB_SEARCH_PROVIDER=duckduckgo
# Serper API Key (for Google search via Serper)
SERPER_API_KEY=your_serper_api_key_here
# SearchXNG Host URL
SEARCHXNG_HOST=http://localhost:8080
# Brave Search API Key
BRAVE_API_KEY=your_brave_api_key_here
# Tavily API Key
TAVILY_API_KEY=your_tavily_api_key_here
```
### PubMed Configuration
```bash
# NCBI API Key (optional, for higher rate limits: 10 req/sec vs 3 req/sec)
NCBI_API_KEY=your_ncbi_api_key_here
```
### Agent Configuration
```bash
# Maximum iterations per research loop
MAX_ITERATIONS=10
# Search timeout in seconds
SEARCH_TIMEOUT=30
# Use graph-based execution for research flows
USE_GRAPH_EXECUTION=false
```
### Budget & Rate Limiting Configuration
```bash
# Default token budget per research loop
DEFAULT_TOKEN_LIMIT=100000
# Default time limit per research loop (minutes)
DEFAULT_TIME_LIMIT_MINUTES=10
# Default iterations limit per research loop
DEFAULT_ITERATIONS_LIMIT=10
```
### RAG Service Configuration
```bash
# ChromaDB collection name for RAG
RAG_COLLECTION_NAME=deepcritical_evidence
# Number of top results to retrieve from RAG
RAG_SIMILARITY_TOP_K=5
# Automatically ingest evidence into RAG
RAG_AUTO_INGEST=true
```
### ChromaDB Configuration
```bash
# ChromaDB storage path
CHROMA_DB_PATH=./chroma_db
# Whether to persist ChromaDB to disk
CHROMA_DB_PERSIST=true
# ChromaDB server host (for remote ChromaDB, optional)
# CHROMA_DB_HOST=localhost
# ChromaDB server port (for remote ChromaDB, optional)
# CHROMA_DB_PORT=8000
```
### External Services
```bash
# Modal Token ID (for Modal sandbox execution)
MODAL_TOKEN_ID=your_modal_token_id_here
# Modal Token Secret
MODAL_TOKEN_SECRET=your_modal_token_secret_here
```
### Logging Configuration
```bash
# Log Level: "DEBUG", "INFO", "WARNING", or "ERROR"
LOG_LEVEL=INFO
```
## Configuration Properties
The `Settings` class provides helpful properties for checking configuration:
```python
from src.utils.config import settings
# Check API key availability
settings.has_openai_key # bool
settings.has_anthropic_key # bool
settings.has_huggingface_key # bool
settings.has_any_llm_key # bool
# Check service availability
settings.modal_available # bool
settings.web_search_available # bool
```
## Environment Variables Reference
### Required (at least one LLM)
- `OPENAI_API_KEY` or `ANTHROPIC_API_KEY` - At least one LLM provider key
### Optional LLM Providers
- `DEEPSEEK_API_KEY` (Phase 2)
- `OPENROUTER_API_KEY` (Phase 2)
- `GEMINI_API_KEY` (Phase 2)
- `PERPLEXITY_API_KEY` (Phase 2)
- `HUGGINGFACE_API_KEY` or `HF_TOKEN`
- `AZURE_OPENAI_ENDPOINT` (Phase 2)
- `AZURE_OPENAI_DEPLOYMENT` (Phase 2)
- `AZURE_OPENAI_API_KEY` (Phase 2)
- `AZURE_OPENAI_API_VERSION` (Phase 2)
- `LOCAL_MODEL_URL` (Phase 2)
### Web Search
- `WEB_SEARCH_PROVIDER` (default: "duckduckgo")
- `SERPER_API_KEY`
- `SEARCHXNG_HOST`
- `BRAVE_API_KEY`
- `TAVILY_API_KEY`
### Embeddings
- `EMBEDDING_PROVIDER` (default: "local")
- `HUGGINGFACE_EMBEDDING_MODEL` (optional)
### RAG
- `RAG_COLLECTION_NAME` (default: "deepcritical_evidence")
- `RAG_SIMILARITY_TOP_K` (default: 5)
- `RAG_AUTO_INGEST` (default: true)
### ChromaDB
- `CHROMA_DB_PATH` (default: "./chroma_db")
- `CHROMA_DB_PERSIST` (default: true)
- `CHROMA_DB_HOST` (optional)
- `CHROMA_DB_PORT` (optional)
### Budget
- `DEFAULT_TOKEN_LIMIT` (default: 100000)
- `DEFAULT_TIME_LIMIT_MINUTES` (default: 10)
- `DEFAULT_ITERATIONS_LIMIT` (default: 10)
### Other
- `LLM_PROVIDER` (default: "openai")
- `NCBI_API_KEY` (optional)
- `MODAL_TOKEN_ID` (optional)
- `MODAL_TOKEN_SECRET` (optional)
- `MAX_ITERATIONS` (default: 10)
- `LOG_LEVEL` (default: "INFO")
- `USE_GRAPH_EXECUTION` (default: false)
## Validation
Settings are validated on load using Pydantic validation:
- **Type checking**: All fields are strongly typed
- **Range validation**: Numeric fields have min/max constraints
- **Literal validation**: Enum fields only accept specific values
- **Required fields**: API keys are checked when accessed via `get_api_key()`
## Error Handling
Configuration errors raise `ConfigurationError`:
```python
from src.utils.config import settings
from src.utils.exceptions import ConfigurationError
try:
api_key = settings.get_api_key()
except ConfigurationError as e:
print(f"Configuration error: {e}")
```
## Future Enhancements (Phase 2)
The following configurations are planned for Phase 2:
1. **Additional LLM Providers**: DeepSeek, OpenRouter, Gemini, Perplexity, Azure OpenAI, Local models
2. **Model Selection**: Reasoning/main/fast model configuration
3. **Service Integration**: Migrate `folder/llm_config.py` to centralized config
See `CONFIGURATION_ANALYSIS.md` for the complete implementation plan.
|