The RKLLAMA configuration system provides a flexible, type-safe mechanism for managing application settings from multiple sources with proper prioritization.
Settings are loaded in order of increasing priority:
- Schema defaults - Default values defined in the schema
- System settings - System-wide configuration files
- User settings - User-specific configuration files
- Project settings - Local project configuration
- Environment variables - Settings from environment variables
- Command-line arguments - Highest priority settings
RKLLAMA searches for configuration files in the following locations:
/etc/rkllama/rkllama.ini
/etc/rkllama.ini
/usr/local/etc/rkllama.ini
<app_root>/system/rkllama.ini
~/.config/rkllama/rkllama.ini
~/.config/rkllama.ini
~/.rkllama.ini
<app_root>/rkllama.ini
<app_root>/config/rkllama.ini
RKLLAMA uses standard INI format with sections and key-value pairs:
[server]
port = 8080
debug = false
[paths]
models = models
data = data
logs = logs/rkllama
Environment variables can override settings using the format RKLLAMA_SECTION_KEY
.
For example:
RKLLAMA_SERVER_PORT=9090
sets the server port to 9090RKLLAMA_PATHS_MODELS=/opt/models
sets the models path
Special environment variables:
RKLLAMA_DEBUG=(1|true|yes|on)
enables debug modeRKLLAMA_DEBUG=(0|false|no|off)
disables debug mode
RKLLAMA supports command-line arguments with the highest priority:
# Load specific configuration file
python -m rkllama --config /path/to/config.ini
# Set server section values
python -m rkllama --server_port 8080 --server_debug
from rkllama import config
# Get values with automatic type inference
port = config.get("server", "port")
debug = config.get("server", "debug")
# Get values with explicit types
port = config.get("server", "port", 8080, as_type=int)
debug = config.get("server", "debug", False, as_type=bool)
# Get path values (resolved against app_root)
models_dir = config.get_path("models")
# Set values
config.set("server", "port", 9090)
config.set("logging", "level", "DEBUG")
# Display current configuration
config.display()
# Validate configuration
if not config.validate():
print("Configuration validation failed!")
# Save to project configuration file
config.save_to_project_ini()
# Reload configuration from all sources
config.reload_config()
The configuration system automatically handles type conversion based on the schema or heuristic detection:
true
,yes
,on
,1
→ BooleanTrue
false
,no
,off
,0
→ BooleanFalse
- Numeric strings → integers or floats
- Comma-separated values → lists
- Everything else → strings
Paths are automatically resolved relative to the application root directory. The system also supports:
- Absolute paths
- Environment variable expansion (
$HOME/data
) - User home expansion (
~/models
)
Resolved paths are cached for performance, particularly for frequently accessed paths.
The configuration system generates a shell environment file at <app_root>/config/config.env
that exports all settings as environment variables. This file can be sourced in shell scripts:
source /path/to/rkllama/config/config.env
echo $RKLLAMA_SERVER_PORT