docs
API Reference

API Reference

Command Line Interface

GSwarm provides a comprehensive command-line interface with various options and flags for different use cases.

Main Command

gswarm

The main command to start the GSwarm supervisor.

gswarm [flags]

Command Options

Core Configuration Flags

FlagTypeDefaultDescriptionEnvironment Variable
--testnetboolfalseConnect to the TestnetGSWARM_TESTNET
--big-swarmboolfalseUse big swarm (Math Hard) instead of small swarm (Math)GSWARM_BIG_SWARM
--model-sizestring0.5Parameter count in billions (0.5, 1.5, 7, 32, 72)GSWARM_MODEL_SIZE
--hf-tokenstringHuggingFace access token for model pushingHUGGINGFACE_ACCESS_TOKEN, GSWARM_HF_TOKEN
--org-idstringModal ORG_ID (required for testnet)GSWARM_ORG_ID
--identity-pathstringswarm.pemPath to identity PEM fileGSWARM_IDENTITY_PATH
--contract-addressstringOverride smart contract addressGSWARM_CONTRACT_ADDRESS
--gamestringGame type ('gsm8k' or 'dapo')GSWARM_GAME
--config-pathstringPath to YAML config fileGSWARM_CONFIG_PATH
--cpu-onlyboolfalseForce CPU-only modeGSWARM_CPU_ONLY
--requirementsstringRequirements file path (overrides default)GSWARM_REQUIREMENTS
--interactiveboolfalseForce interactive mode (prompt for all options)GSWARM_INTERACTIVE

Telegram Monitoring Flags

FlagTypeDefaultDescriptionEnvironment Variable
--telegramboolfalseStart Telegram monitoring serviceGSWARM_TELEGRAM
--user-data-pathstringPath to userData.json fileGSWARM_USER_DATA_PATH
--telegram-config-pathstringtelegram-config.jsonPath to telegram-config.jsonGSWARM_TELEGRAM_CONFIG_PATH
--update-telegram-configboolfalseForce update of Telegram configGSWARM_UPDATE_TELEGRAM_CONFIG

Utility Commands

CommandDescription
gswarm --versionShow version information
gswarm --helpShow help information
gswarm versionShow version information
gswarm help versionShow help for specific command

Environment Variables

All command-line flags can be set via environment variables with the GSWARM_ prefix:

# Core configuration
export GSWARM_TESTNET=true
export GSWARM_BIG_SWARM=true
export GSWARM_MODEL_SIZE=7
export GSWARM_ORG_ID=your-org-id
export GSWARM_IDENTITY_PATH=/path/to/identity.pem
export GSWARM_CONTRACT_ADDRESS=0x...
export GSWARM_GAME=gsm8k
export GSWARM_CONFIG_PATH=config.yaml
export GSWARM_CPU_ONLY=false
export GSWARM_REQUIREMENTS=requirements-gpu.txt
 
# HuggingFace configuration
export HUGGINGFACE_ACCESS_TOKEN=your-token
export GSWARM_HF_TOKEN=your-token
 
# Telegram configuration
export GSWARM_TELEGRAM=true
export GSWARM_USER_DATA_PATH=/path/to/userData.json
export GSWARM_TELEGRAM_CONFIG_PATH=telegram-config.json
export GSWARM_UPDATE_TELEGRAM_CONFIG=false
 
# Debug mode
export SWARM_DEBUG=1

Configuration File Format

GSwarm can use YAML configuration files for complex setups:

# config.yaml
testnet: true
big_swarm: true
model_size: 7
org_id: "your-org-id"
identity_path: "swarm.pem"
contract_address: "0x..."
game: "gsm8k"
cpu_only: false
requirements: "requirements-gpu.txt"

Usage Examples

Basic Usage

# Interactive mode (default)
gswarm
 
# Non-interactive mode with all options
gswarm --testnet --big-swarm --model-size 7 --org-id YOUR_ORG_ID --hf-token YOUR_TOKEN
 
# CPU-only mode
gswarm --cpu-only --model-size 0.5
 
# Custom requirements file
gswarm --requirements requirements-gpu.txt

Telegram Monitoring

# Basic Telegram monitoring
gswarm --telegram
 
# Telegram with custom paths
gswarm --telegram \
  --user-data-path /path/to/userData.json \
  --telegram-config-path /path/to/telegram-config.json
 
# Update Telegram configuration
gswarm --telegram --update-telegram-config

Advanced Configuration

# Full configuration with all options
gswarm \
  --org-id YOUR_ORG_ID \
  --identity-path /path/to/identity.pem \
  --hf-token YOUR_HF_TOKEN \
  --model-size 7 \
  --big-swarm \
  --cpu-only \
  --telegram
 
# Environment-based configuration
export GSWARM_ORG_ID=your-org-id
export GSWARM_HF_TOKEN=your-token
export GSWARM_MODEL_SIZE=7
gswarm

Return Codes

GSwarm uses standard exit codes:

CodeDescription
0Success
1General error
2Configuration error
3Python environment error
4Process management error
5Telegram service error

Logging

Log File Location

Logs are written to logs/gensyn_rl_swarm_go.log by default.

Log Format

2024-01-01 12:00:00.000000 [LEVEL] Message

Log Levels

  • INFO: General information
  • WARN: Warning messages
  • ERROR: Error messages
  • DEBUG: Debug information (when SWARM_DEBUG=1)

Error Handling

Common Error Messages

ErrorDescriptionSolution
python3 not foundPython 3.10+ not in PATHInstall Python 3.10+
requirements installation failedFailed to install dependenciesCheck network and requirements.txt
invalid model-size valueInvalid model size specifiedUse: 0.5, 1.5, 7, 32, 72
invalid game typeInvalid game type specifiedUse: gsm8k or dapo
bot token invalidInvalid Telegram bot tokenVerify token with @BotFather

Debug Mode

Enable debug mode for detailed logging:

export SWARM_DEBUG=1
gswarm

Integration Examples

Shell Script Integration

#!/bin/bash
# start-gswarm.sh
 
# Set configuration
export GSWARM_ORG_ID=$1
export GSWARM_HF_TOKEN=$2
export GSWARM_MODEL_SIZE=${3:-7}
 
# Start GSwarm
gswarm --non-interactive
 
# Check exit code
if [ $? -eq 0 ]; then
    echo "GSwarm started successfully"
else
    echo "GSwarm failed to start"
    exit 1
fi

Docker Integration

FROM golang:1.21-alpine
 
# Install Python
RUN apk add --no-cache python3 py3-pip
 
# Install GSwarm
RUN go install github.com/Deep-Commit/gswarm/cmd/gswarm@latest
 
# Set working directory
WORKDIR /app
 
# Copy requirements
COPY requirements.txt .
 
# Install Python dependencies
RUN pip3 install -r requirements.txt
 
# Run GSwarm
CMD ["gswarm"]

Systemd Service

[Unit]
Description=GSwarm Supervisor
After=network.target
 
[Service]
Type=simple
User=gswarm
Environment=GSWARM_ORG_ID=your-org-id
Environment=GSWARM_HF_TOKEN=your-token
Environment=GSWARM_MODEL_SIZE=7
WorkingDirectory=/path/to/gensyn-rl-swarm
ExecStart=/usr/local/bin/gswarm
Restart=always
RestartSec=10
 
[Install]
WantedBy=multi-user.target

API Stability

The command-line interface is considered stable for the following:

  • Core flags and options
  • Environment variable support
  • Basic configuration options
  • Telegram monitoring flags

The following may change in future versions:

  • Internal implementation details
  • Log format and location
  • Error message text
  • Debug output format

Version Compatibility

GSwarm maintains backward compatibility for:

  • Command-line flags
  • Environment variables
  • Configuration file format
  • Basic functionality

Breaking changes will be documented in release notes and may require migration steps.