botserver/docs/src/chapter-01/installation.md

374 lines
9 KiB
Markdown
Raw Normal View History

# Installation
2025-11-23 17:02:22 -03:00
BotServer installs itself automatically through the bootstrap process. No manual setup required - just run the binary and everything gets configured.
## Bootstrap Flow Diagram
2025-11-24 14:15:01 -03:00
<img src="./assets/bootstrap-process.svg" alt="Auto-Bootstrap Process" style="max-height: 400px; width: 100%; object-fit: contain;">
2025-11-21 12:13:48 -03:00
2025-11-23 09:19:06 -03:00
## System Requirements
2025-11-23 13:46:55 -03:00
### Minimum Requirements
2025-11-23 09:19:06 -03:00
- **OS**: Linux, macOS, or Windows
2025-11-23 13:46:55 -03:00
- **RAM**: 4GB minimum
2025-11-23 09:19:06 -03:00
- **Disk**: 10GB for installation + data storage
2025-11-23 13:46:55 -03:00
- **CPU**: 1 core (sufficient for development/testing)
### Recommended for Production
- **OS**: Linux server (Ubuntu/Debian preferred)
- **RAM**: 16GB or more
- **Disk**: 100GB SSD storage
- **CPU**: 2+ cores
- **GPU**: RTX 3060 or better (12GB VRAM minimum) for local LLM hosting
2025-11-23 09:19:06 -03:00
2025-11-23 13:46:55 -03:00
## Quick Start
2025-11-23 09:19:06 -03:00
2025-11-23 13:46:55 -03:00
BotServer handles all dependencies automatically:
2025-11-21 12:13:48 -03:00
```bash
2025-11-23 13:46:55 -03:00
# Download and run
./botserver
2025-11-21 12:13:48 -03:00
```
2025-11-23 13:46:55 -03:00
The bootstrap process automatically downloads everything to `botserver-stack/`:
- PostgreSQL database
- Drive (S3-compatible object storage)
- Valkey cache
- LLM server and models
- All required dependencies
2025-11-21 12:13:48 -03:00
2025-11-23 13:46:55 -03:00
**No manual installation required!**
2025-11-21 12:13:48 -03:00
2025-11-23 13:46:55 -03:00
## Environment Variables
2025-11-21 12:13:48 -03:00
2025-11-23 13:46:55 -03:00
The `.env` file is **automatically generated** during bootstrap from a blank environment with secure random credentials.
2025-11-21 12:13:48 -03:00
2025-11-23 13:46:55 -03:00
### Automatic Generation (Bootstrap Mode)
2025-11-21 12:13:48 -03:00
2025-11-23 13:46:55 -03:00
When you first run `./botserver`, it creates `.env` with:
2025-11-21 12:13:48 -03:00
2025-11-23 13:46:55 -03:00
```bash
# Auto-generated secure credentials
DATABASE_URL=postgres://gbuser:RANDOM_PASS@localhost:5432/botserver
DRIVE_SERVER=http://localhost:9000
DRIVE_ACCESSKEY=GENERATED_KEY
DRIVE_SECRET=GENERATED_SECRET
2025-11-23 09:19:06 -03:00
```
2025-11-23 13:46:55 -03:00
### Using Existing Services
2025-11-21 12:13:48 -03:00
2025-11-23 13:46:55 -03:00
If you already have PostgreSQL or drive storage running, you can point to them:
2025-11-21 12:13:48 -03:00
2025-11-23 09:19:06 -03:00
```bash
2025-11-23 13:46:55 -03:00
# Point to your existing PostgreSQL
DATABASE_URL=postgres://myuser:mypass@myhost:5432/mydb
2025-11-21 12:13:48 -03:00
2025-11-23 13:46:55 -03:00
# Point to your existing drive/S3
DRIVE_SERVER=http://my-drive:9000
DRIVE_ACCESSKEY=my-access-key
DRIVE_SECRET=my-secret-key
2025-11-23 09:19:06 -03:00
```
2025-11-23 09:19:06 -03:00
## Configuration
2025-11-21 12:13:48 -03:00
2025-11-23 13:46:55 -03:00
### Bot Configuration Parameters
2025-11-21 12:13:48 -03:00
2025-11-23 13:46:55 -03:00
Each bot has a `config.csv` file in its `.gbot/` directory. Available parameters:
2025-11-21 12:13:48 -03:00
2025-11-23 13:46:55 -03:00
#### Server Configuration
2025-11-23 09:19:06 -03:00
```csv
name,value
2025-11-24 13:02:30 -03:00
server-host,0.0.0.0
server-port,8080
sites-root,/tmp
2025-11-21 12:13:48 -03:00
```
2025-11-23 13:46:55 -03:00
#### LLM Configuration
```csv
name,value
llm-key,none
llm-url,http://localhost:8081
llm-model,../../../../data/llm/model.gguf
llm-cache,false # Semantic cache (needs integration)
llm-cache-ttl,3600 # Cache TTL in seconds (needs integration)
llm-cache-semantic,true # Enable semantic matching (needs integration)
llm-cache-threshold,0.95 # Similarity threshold (needs integration)
```
2025-11-21 12:13:48 -03:00
2025-11-23 13:46:55 -03:00
#### LLM Server Settings
```csv
name,value
llm-server,false
llm-server-path,botserver-stack/bin/llm/build/bin
llm-server-host,0.0.0.0
llm-server-port,8081
llm-server-gpu-layers,0
llm-server-n-moe,0
llm-server-ctx-size,4096
llm-server-n-predict,1024
llm-server-parallel,6
llm-server-cont-batching,true
```
2025-11-21 12:13:48 -03:00
2025-11-23 13:46:55 -03:00
#### Email Configuration
```csv
name,value
email-from,from@domain.com
email-server,mail.domain.com
email-port,587
email-user,user@domain.com
email-pass,yourpassword
```
2025-11-21 12:13:48 -03:00
2025-11-23 13:46:55 -03:00
#### Theme Configuration
2025-11-23 09:19:06 -03:00
```csv
name,value
theme-color1,#0d2b55
theme-color2,#fff9c2
theme-title,My Bot
theme-logo,https://example.com/logo.svg
```
2025-11-21 12:13:48 -03:00
2025-11-23 13:46:55 -03:00
#### Prompt Configuration
```csv
name,value
prompt-history,2
prompt-compact,4
```
2025-11-23 13:46:55 -03:00
## Bootstrap Process
2025-11-21 12:13:48 -03:00
2025-11-23 13:46:55 -03:00
When you first run BotServer, it:
2025-11-21 12:13:48 -03:00
2025-11-23 13:46:55 -03:00
1. **Detects your system** - Identifies OS and architecture
2. **Creates directories** - Sets up `botserver-stack/` structure
3. **Downloads components** - Gets all required binaries
4. **Configures services** - Sets up database, storage, and cache
5. **Initializes database** - Creates tables and initial data
6. **Deploys default bot** - Creates a working bot instance
7. **Starts services** - Launches all components
2025-11-21 12:13:48 -03:00
2025-11-23 13:46:55 -03:00
This typically takes 2-5 minutes on first run.
## Storage Setup
2025-11-21 12:13:48 -03:00
2025-11-23 13:46:55 -03:00
BotServer uses S3-compatible object storage. Each bot deployment creates a new bucket in the drive:
```bash
2025-11-23 13:46:55 -03:00
# Deploy a new bot = create a new bucket in drive
# Bots are stored in the object storage, not local filesystem
mybot.gbai → creates 'mybot' bucket in drive storage
```
2025-11-23 13:46:55 -03:00
**Note**: The `work/` folder is for internal use only and should not be used for bot deployment. Bot packages should be deployed directly to the object storage (drive).
2025-11-21 12:13:48 -03:00
2025-11-23 13:46:55 -03:00
The storage server runs on:
- API: http://localhost:9000
- Console: http://localhost:9001
2025-11-23 13:46:55 -03:00
### Local Development with S3 Sync Tools
2025-11-23 13:46:55 -03:00
You can edit your bot files locally and have them automatically sync to drive storage using S3-compatible tools:
2025-11-21 12:13:48 -03:00
2025-11-23 13:46:55 -03:00
#### Free S3 Sync Tools
- **Cyberduck** (Windows/Mac/Linux) - GUI file browser with S3 support
- **WinSCP** (Windows) - File manager with S3 protocol support
- **Mountain Duck** (Windows/Mac) - Mount S3 as local drive
- **S3 Browser** (Windows) - Freeware S3 client
- **CloudBerry Explorer** (Windows/Mac) - Free version available
- **rclone** (All platforms) - Command-line sync tool
2025-11-23 09:19:06 -03:00
2025-11-23 13:46:55 -03:00
#### Setup Example with rclone
```bash
# Configure rclone for drive storage
rclone config
# Choose: n) New remote
# Name: drive
# Storage: s3
# Provider: Other
# Access Key: (from .env DRIVE_ACCESSKEY)
# Secret Key: (from .env DRIVE_SECRET)
# Endpoint: http://localhost:9000
# Sync local folder to bucket (watches for changes)
rclone sync ./mybot.gbai drive:mybot --watch
# Now edit files locally:
# - Edit mybot.gbai/mybot.gbot/config.csv → Bot reloads automatically
# - Edit mybot.gbai/mybot.gbdialog/*.bas → Scripts compile automatically
# - Add docs to mybot.gbai/mybot.gbkb/ → Knowledge base updates automatically
```
2025-11-21 12:13:48 -03:00
2025-11-23 13:46:55 -03:00
With this setup:
- ✅ Edit `.csv` files → Bot configuration updates instantly
- ✅ Edit `.bas` files → BASIC scripts compile automatically
- ✅ Add documents → Knowledge base reindexes automatically
- ✅ No manual uploads needed
- ✅ Works like local development but uses object storage
2025-11-21 12:13:48 -03:00
2025-11-23 13:46:55 -03:00
## Database Setup
2025-11-23 09:19:06 -03:00
2025-11-23 13:46:55 -03:00
PostgreSQL is automatically configured with:
- Database: `botserver`
- User: `gbuser`
- Tables created via migrations
- Connection pooling enabled
2025-11-21 12:13:48 -03:00
2025-11-23 13:46:55 -03:00
## Authentication Setup
BotServer uses an external directory service for user management:
- Handles user authentication
- Manages OAuth2/OIDC flows
- Controls access permissions
- Integrates with existing identity providers
2025-11-21 12:13:48 -03:00
2025-11-23 09:19:06 -03:00
## LLM Setup
2025-11-21 12:13:48 -03:00
2025-11-23 13:46:55 -03:00
### Local LLM (Recommended)
2025-11-21 12:13:48 -03:00
2025-11-23 13:46:55 -03:00
The bootstrap downloads a default model to `botserver-stack/data/llm/`. Configure in `config.csv`:
2025-11-21 12:13:48 -03:00
2025-11-23 13:46:55 -03:00
```csv
name,value
2025-11-23 09:19:06 -03:00
llm-url,http://localhost:8081
2025-11-23 13:46:55 -03:00
llm-model,../../../../data/llm/model.gguf
llm-server-gpu-layers,0
```
For GPU acceleration (RTX 3060 or better):
```csv
name,value
llm-server-gpu-layers,35
2025-11-23 09:19:06 -03:00
```
### External LLM Provider
2025-11-21 12:13:48 -03:00
2025-11-23 13:46:55 -03:00
To use external APIs, configure in `config.csv`:
2025-11-21 12:13:48 -03:00
```csv
name,value
2025-11-23 13:46:55 -03:00
llm-url,https://api.provider.com/v1
2025-11-23 09:19:06 -03:00
llm-key,your-api-key
2025-11-23 13:46:55 -03:00
llm-model,model-name
```
## Container Deployment (LXC)
For production isolation using Linux containers:
```bash
# Create container
lxc-create -n botserver -t download -- -d ubuntu -r jammy -a amd64
# Start container
lxc-start -n botserver
# Attach to container
lxc-attach -n botserver
# Install BotServer inside container
./botserver
2025-11-21 12:13:48 -03:00
```
2025-11-23 09:19:06 -03:00
## Verifying Installation
2025-11-21 12:13:48 -03:00
2025-11-23 09:19:06 -03:00
### Check Component Status
2025-11-21 12:13:48 -03:00
```bash
2025-11-23 09:19:06 -03:00
# Check all services
botserver status
2025-11-21 12:13:48 -03:00
2025-11-23 09:19:06 -03:00
# Test database connection
psql $DATABASE_URL -c "SELECT version();"
# Test storage
2025-11-23 13:46:55 -03:00
curl http://localhost:9000/health/live
2025-11-23 09:19:06 -03:00
# Test LLM
curl http://localhost:8081/v1/models
```
2025-11-21 12:13:48 -03:00
2025-11-23 09:19:06 -03:00
### Run Test Bot
2025-11-21 12:13:48 -03:00
```bash
2025-11-23 13:46:55 -03:00
# The default bot is automatically deployed to the drive during bootstrap
2025-11-23 20:12:09 -03:00
# Access UI interface
2025-11-23 09:19:06 -03:00
open http://localhost:8080
2025-11-21 12:13:48 -03:00
```
2025-11-23 13:46:55 -03:00
To deploy additional bots, upload them to the object storage, not the local filesystem. The `work/` folder is reserved for internal operations.
2025-11-23 09:19:06 -03:00
## Troubleshooting
2025-11-21 12:13:48 -03:00
2025-11-23 09:19:06 -03:00
### Database Connection Issues
2025-11-21 12:13:48 -03:00
```bash
2025-11-23 13:46:55 -03:00
# Check if PostgreSQL is running
ps aux | grep postgres
2025-11-21 12:13:48 -03:00
2025-11-23 09:19:06 -03:00
# Test connection
psql -h localhost -U gbuser -d botserver
2025-11-23 13:46:55 -03:00
# Verify DATABASE_URL
2025-11-23 09:19:06 -03:00
echo $DATABASE_URL
```
2025-11-23 09:19:06 -03:00
### Storage Connection Issues
```bash
2025-11-23 13:46:55 -03:00
# Check drive process
ps aux | grep minio
2025-11-21 12:13:48 -03:00
2025-11-23 13:46:55 -03:00
# Test storage access
curl -I $DRIVE_SERVER/health/live
```
2025-11-23 09:19:06 -03:00
### Port Conflicts
2025-11-23 13:46:55 -03:00
Default ports used:
2025-11-23 09:19:06 -03:00
| Service | Port | Configure in |
|---------|------|--------------|
2025-11-24 13:02:30 -03:00
| UI Server | 8080 | config.csv: `server-port` |
2025-11-23 09:19:06 -03:00
| PostgreSQL | 5432 | DATABASE_URL |
2025-11-23 13:46:55 -03:00
| Drive API | 9000 | DRIVE_SERVER |
| Drive Console | 9001 | N/A |
2025-11-23 09:19:06 -03:00
| LLM Server | 8081 | config.csv: `llm-server-port` |
2025-11-23 13:46:55 -03:00
| Embedding Server | 8082 | config.csv: `embedding-url` |
| Valkey Cache | 6379 | Internal |
2025-11-23 09:19:06 -03:00
### Memory Issues
For systems with limited RAM:
2025-11-23 13:46:55 -03:00
1. Reduce LLM context size:
2025-11-23 09:19:06 -03:00
```csv
llm-server-ctx-size,2048
```
2. Limit parallel processing:
```csv
llm-server-parallel,2
```
2025-11-23 13:46:55 -03:00
3. Use quantized models (Q3_K_M or Q4_K_M)
4. For Mixture of Experts models, adjust CPU MoE threads:
```csv
llm-server-n-moe,4
```
### GPU Issues
If GPU is not detected:
1. Check CUDA installation (NVIDIA)
2. Verify GPU memory (12GB minimum)
3. Set `llm-server-gpu-layers` to 0 for CPU-only mode
2025-11-21 12:13:48 -03:00
## Next Steps
2025-11-23 09:19:06 -03:00
- [Quick Start Guide](./quick-start.md) - Create your first bot
2025-11-23 13:46:55 -03:00
- [First Conversation](./first-conversation.md) - Test your bot
2025-11-23 09:19:06 -03:00
- [Configuration Reference](../chapter-02/gbot.md) - All configuration options
2025-11-23 13:46:55 -03:00
- [BASIC Programming](../chapter-05/basics.md) - Learn the scripting language