Simplified bootstrapping

This commit is contained in:
Niels Geens
2025-03-14 15:53:27 +01:00
parent 5c95a8482f
commit d5a5fd1071
8 changed files with 107 additions and 115 deletions

View File

@@ -4,6 +4,7 @@ RUN apt-get update && \
apt install -y \ apt install -y \
python3-pip \ python3-pip \
git \ git \
jq \
python3-venv \ python3-venv \
wget \ wget \
gnupg \ gnupg \

View File

@@ -3,68 +3,15 @@
set -eo pipefail # Exit on any error, pipe failures set -eo pipefail # Exit on any error, pipe failures
# Hardcoded paths for cloud deployment
SIA_REPO_URL="ssh://git@git.nielsgeens.be:222/llm/SIA.git"
SIA_DIR="/root/sia"
DATA_DIR="/root/data"
MODELS_DIR="/root/models"
DESKTOP_DIR="/root/desktop"
STATIC_DIR="/root/static"
VENVS_DIR="/root/venvs"
# Print header
echo "==================================================="
echo "SIA Bootstrap Script - Cloud Deployment"
echo "==================================================="
# Create directory structure # Create directory structure
echo "Creating directory structure..." echo "Creating directory structure..."
mkdir -p "$DATA_DIR/iterations" mkdir -p "/root/data/iterations"
mkdir -p "$DESKTOP_DIR" mkdir -p "/root/desktop"
mkdir -p "$VENVS_DIR" mkdir -p "/root/venvs"
cd "$DESKTOP_DIR"
# Set up SSH keys
echo "Setting up SSH keys for git access..."
mkdir -p ~/.ssh
chmod 700 ~/.ssh
ssh-keygen -t sia_git -N "" -f ~/.ssh/sia_git -C "sia-agent"
echo "New SSH key generated"
# Display public key for user to add to git server
echo "==================================================="
echo "Add this public key to your git server:"
cat ~/.ssh/sia_git.pub
echo "==================================================="
# Prompt user to confirm they've added the key
read -p "Press Enter once you've added the SSH key to the git server..."
# Clone SIA repository # Clone SIA repository
echo "Cloning SIA repository..." echo "Cloning SIA repository..."
git clone "$SIA_REPO_URL" "$SIA_DIR" git clone "$SIA_REPO_URL" "/root/sia"
# Create and setup virtual environments
echo "Setting up SIA virtual environments..."
# Setup ITB tool environment
echo "Creating ITB tool environment..."
python3 -m venv "$VENVS_DIR/itb"
"$VENVS_DIR/itb/bin/pip" install -e "$SIA_DIR/tools/itb"
# Setup Train tool environment
echo "Creating Train tool environment..."
python3 -m venv "$VENVS_DIR/train"
"$VENVS_DIR/train/bin/pip" install -e "$SIA_DIR/tools/train"
# Setup SIA core environment
echo "Creating SIA core environment..."
python3 -m venv "$VENVS_DIR/sia"
"$VENVS_DIR/sia/bin/pip" install -e "$SIA_DIR"
# Build web interface
echo "Building web interface"
cd "$SIA_DIR/web"
# Install Node.js if needed # Install Node.js if needed
if ! command -v node &> /dev/null; then if ! command -v node &> /dev/null; then
@@ -75,51 +22,17 @@ if ! command -v node &> /dev/null; then
nvm install node nvm install node
fi fi
# Build web interface
echo "Building web interface"
cd "/root/sia/web"
npm install npm install
npm run build npm run build
ln -s "/root/sia/web/dist" "/root/static"
mkdir -p "$STATIC_DIR"
cp -r "$SIA_DIR/web/dist/"* "$STATIC_DIR/"
echo "Web interface built successfully"
# Finetune model # Finetune model
echo "Starting model finetuning..." echo "Finetuning model..."
train
COMMIT_ID=$(cd "$SIA_DIR" && git rev-parse HEAD)
echo "Current commit: $COMMIT_ID"
mkdir -p "$MODELS_DIR/$COMMIT_ID"
mkdir -p "$MODELS_DIR/current"
# Run finetuning using the train environment
"$VENVS_DIR/train/bin/train_deepseek" --output-dir "$MODELS_DIR/$COMMIT_ID"
ln -sf "$MODELS_DIR/$COMMIT_ID" "$MODELS_DIR/current"
echo "Finetuning complete, model linked to current"
# Initialize environment information
echo "Initializing environment information..."
mkdir -p "$DATA_DIR/environment"
cat > "$DATA_DIR/environment/sia_repo.md" << EOF
# SIA Repository Information
- Repository URL: $SIA_REPO_URL
- ssh key: ~/.ssh/sia_git.pub
EOF
# Create .env file for local model only
cat > "$SIA_DIR/.env" << EOF
SIA_DEEPSEEK_ENABLED=true
SIA_DEEPSEEK_MODEL=$MODELS_DIR/current
SIA_DEEPSEEK_TEMPERATURE=0.6
EOF
# Print header
echo "==================================================="
echo "SIA environment initialization complete!"
echo "==================================================="
# Start SIA using restart script # Start SIA using restart script
echo "Starting SIA..." echo "Start restart script..."
"$SIA_DIR/scripts/restart.sh" "/root/sia/scripts/restart.sh"

View File

@@ -41,8 +41,10 @@ output=$(runpodctl create pod \
--mem $MEMORY \ --mem $MEMORY \
--vcpu $CPU_COUNT \ --vcpu $CPU_COUNT \
--ports "8080/http,8888/http" \ --ports "8080/http,8888/http" \
--env "SIA_QWQ_ENABLED=1" \ --env "SIA_REPO_URL=git.nielsgeens.be/llm/SIA" \
--env "SIA_GITEA_API_KEY=$SIA_GITEA_API_KEY" \
--env "SIA_HF_API_KEY=$SIA_HF_API_KEY" \ --env "SIA_HF_API_KEY=$SIA_HF_API_KEY" \
--env "SIA_QWQ_ENABLED=1" \
) )
echo "$output" echo "$output"

72
scripts/gitea_keys.sh Normal file
View File

@@ -0,0 +1,72 @@
#!/bin/bash
set -e
# Check if required environment variables are set
if [ -z "$SIA_GITEA_API_KEY" ]; then
echo "Error: SIA_GITEA_API_KEY environment variable is not set"
exit 1
fi
if [ -z "$SIA_REPO_URL" ]; then
echo "Error: SIA_REPO_URL environment variable is not set"
exit 1
fi
# Extract domain and port from repo URL
if [[ "$SIA_REPO_URL" == *":"*"/"* ]]; then
# Format: git@domain:port/path or domain:port/path
DOMAIN_PORT=$(echo "$SIA_REPO_URL" | cut -d'/' -f1)
DOMAIN=$(echo "$DOMAIN_PORT" | cut -d':' -f1)
PORT=$(echo "$DOMAIN_PORT" | cut -d':' -f2)
else
# Format: git@domain/path or domain/path (no port specified)
DOMAIN=$(echo "$SIA_REPO_URL" | cut -d'/' -f1)
PORT=22
fi
# If domain includes username (like git@domain), extract just the domain
if [[ "$DOMAIN" == *"@"* ]]; then
DOMAIN=$(echo "$DOMAIN" | cut -d'@' -f2)
fi
echo "Gitea domain: $DOMAIN"
echo "Gitea port: $PORT"
# Create SSH directory if it doesn't exist
mkdir -p ~/.ssh
chmod 700 ~/.ssh
# Generate SSH key if it doesn't exist
if [ ! -f ~/.ssh/sia_repo ]; then
echo "Generating new SSH key..."
ssh-keygen -t ed25519 -f ~/.ssh/sia_repo -N ""
fi
# Get the public key
SSH_PUBLIC_KEY=$(cat ~/.ssh/sia_repo.pub)
# Add host key to known_hosts to avoid verification prompt
echo "Adding host key to known_hosts..."
ssh-keyscan -t rsa -p $PORT $DOMAIN >> ~/.ssh/known_hosts
chmod 600 ~/.ssh/known_hosts
# Check if a key with title "sia" already exists and delete it
echo "Checking for existing SSH key in Gitea..."
EXISTING_KEYS=$(curl -s -X GET "https://$DOMAIN/api/v1/user/keys" \
-H "accept: application/json" \
-H "Authorization: token $SIA_GITEA_API_KEY")
KEY_ID=$(echo "$EXISTING_KEYS" | jq -r '.[] | select(.title=="sia") | .id')
if [ ! -z "$KEY_ID" ]; then
echo "Found existing key with ID $KEY_ID, deleting..."
curl -X DELETE "https://$DOMAIN/api/v1/user/keys/$KEY_ID" \
-H "accept: application/json" \
-H "Authorization: token $SIA_GITEA_API_KEY"
fi
# Add the SSH key to Gitea using the API
echo "Adding SSH key to Gitea using API..."
curl -X POST "https://$DOMAIN/api/v1/user/keys" \
-H "accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: token $SIA_GITEA_API_KEY" \
-d "{\"title\":\"sia\", \"key\":\"$SSH_PUBLIC_KEY\"}"

View File

@@ -5,16 +5,20 @@ set -e
echo "=== Preparing SIA environment ===" echo "=== Preparing SIA environment ==="
echo "Installing ITB tool..." echo "Installing ITB tool..."
/root/venvs/itb/bin/pip install -e /root/sia/tools/itb/ || echo "Warning: Failed to install ITB tool" python3 -m venv "/root/venvs/itb"
/root/venvs/itb/bin/pip install -e /root/sia/tools/itb/
echo "Installing Train tool..." echo "Installing Train tool..."
/root/venvs/train/bin/pip install -e /root/sia/tools/train/ || echo "Warning: Failed to install Train tool" python3 -m venv "/root/venvs/train"
/root/venvs/train/bin/pip install -e /root/sia/tools/train/
echo "Installing SIA core..." echo "Installing SIA core..."
/root/venvs/sia/bin/pip install -e /root/sia/ || { echo "Error: Failed to install SIA core"; exit 1; } python3 -m venv "/root/venvs/sia"
/root/venvs/sia/bin/pip install -e /root/sia/
echo "=== Starting SIA ===" echo "=== Starting SIA ==="
cd "/root/desktop"
while true; do while true; do
sia sia
EXIT_CODE=$? EXIT_CODE=$?

View File

@@ -79,8 +79,8 @@ class Config:
parser.add_argument( parser.add_argument(
'--local-temperature', '--local-temperature',
type=float, type=float,
default=float(os.getenv('SIA_LOCAL_TEMPERATURE', '0.7')), default=float(os.getenv('SIA_LOCAL_TEMPERATURE', '0.1')),
help='Local LLM temperature (default: 0.7, env: SIA_LOCAL_TEMPERATURE)' help='Local LLM temperature (default: 0.1, env: SIA_LOCAL_TEMPERATURE)'
) )
parser.add_argument( parser.add_argument(
'--local-token-limit', '--local-token-limit',
@@ -105,14 +105,14 @@ class Config:
parser.add_argument( parser.add_argument(
'--openai-model', '--openai-model',
type=str, type=str,
default=os.getenv('SIA_OPENAI_MODEL', 'gpt-3.5-turbo'), default=os.getenv('SIA_OPENAI_MODEL', 'gpt-4o'),
help='OpenAI model name (default: gpt-3.5-turbo, env: SIA_OPENAI_MODEL)' help='OpenAI model name (default: gpt-4o, env: SIA_OPENAI_MODEL)'
) )
parser.add_argument( parser.add_argument(
'--openai-temperature', '--openai-temperature',
type=float, type=float,
default=float(os.getenv('SIA_OPENAI_TEMPERATURE', '0.7')), default=float(os.getenv('SIA_OPENAI_TEMPERATURE', '0.1')),
help='OpenAI temperature (default: 0.7, env: SIA_OPENAI_TEMPERATURE)' help='OpenAI temperature (default: 0.1, env: SIA_OPENAI_TEMPERATURE)'
) )
parser.add_argument( parser.add_argument(
'--openai-token-limit', '--openai-token-limit',
@@ -143,8 +143,8 @@ class Config:
parser.add_argument( parser.add_argument(
'--hf-temperature', '--hf-temperature',
type=float, type=float,
default=float(os.getenv('SIA_HF_TEMPERATURE', '0.7')), default=float(os.getenv('SIA_HF_TEMPERATURE', '0.1')),
help='Hugging Face temperature (default: 0.7, env: SIA_HF_TEMPERATURE)' help='Hugging Face temperature (default: 0.1, env: SIA_HF_TEMPERATURE)'
) )
parser.add_argument( parser.add_argument(
'--hf-api-key', '--hf-api-key',
@@ -169,8 +169,8 @@ class Config:
parser.add_argument( parser.add_argument(
'--mistral-temperature', '--mistral-temperature',
type=float, type=float,
default=float(os.getenv('SIA_MISTRAL_TEMPERATURE', '0.7')), default=float(os.getenv('SIA_MISTRAL_TEMPERATURE', '0.1')),
help='Mistral temperature (default: 0.7, env: SIA_MISTRAL_TEMPERATURE)' help='Mistral temperature (default: 0.1, env: SIA_MISTRAL_TEMPERATURE)'
) )
parser.add_argument( parser.add_argument(
'--mistral-token-limit', '--mistral-token-limit',
@@ -200,8 +200,8 @@ class Config:
parser.add_argument( parser.add_argument(
'--qwq-temperature', '--qwq-temperature',
type=float, type=float,
default=float(os.getenv('SIA_QWQ_TEMPERATURE', '0.6')), default=float(os.getenv('SIA_QWQ_TEMPERATURE', '0.1')),
help='QwQ temperature (default: 0.6, env: SIA_QWQ_TEMPERATURE)' help='QwQ temperature (default: 0.1, env: SIA_QWQ_TEMPERATURE)'
) )
parser.add_argument( parser.add_argument(
'--qwq-token-limit', '--qwq-token-limit',