Added restart script and fixed dockerfile and run to match docs

This commit is contained in:
2025-03-01 13:29:17 +01:00
parent 1d5b687e00
commit b7e95d7398
30 changed files with 3047 additions and 1640 deletions

294
scripts/collect.sh Normal file
View File

@@ -0,0 +1,294 @@
#!/usr/bin/env bash
set -euo pipefail
declare -A FILTER_SETS=(
["py"]="-f .*(\\.py|requirements.txt)$"
["web"]="-f .*\\.(js|jsx|json|css|html)$"
["doc"]="-f .*\\.md$"
["deploy"]="-f .*(Dockerfile|\\.sh|\\.xsd)$"
["core"]="-s py ./sia ./tools -s deploy . -f ^(?!procedures/).*\\.md$ ."
["webui"]="-s web ./web"
["tests"]="-s py ./test"
["procedures"]="-s doc ./procedures"
)
OUTPUT="/dev/stdout"
VERBOSE=0
usage() {
echo "Usage: $0 [OPTIONS] [DIRS...]"
echo
echo "Options:"
echo " -f, --filter PATTERN Regex filter for subsequent directories"
echo " -s, --set SETNAME Use predefined set of parameters"
echo " -o, --output FILE Output file (default: stdout)"
echo " -v, -vv Verbose output"
echo
echo "Predefined Filter Sets:"
for setname in $(echo "${!FILTER_SETS[@]}" | tr ' ' '\n' | sort); do
printf " %-15s %s\n" "$setname:" "${FILTER_SETS[$setname]}"
done
exit 1
}
# Expand any set arguments to their full form
expand_args() {
local -a expanded=()
local i=1
local has_sets=0
# First pass: expand sets
while [ $i -le $# ]; do
local arg="${!i}"
case "$arg" in
-s|--set)
has_sets=1
i=$((i+1))
[ $i -le $# ] || { echo "Error: No set name specified"; usage; }
local set_name="${!i}"
if [[ -v "FILTER_SETS[$set_name]" ]]; then
# Add the expanded set parameters
local -a set_args
read -ra set_args <<< "${FILTER_SETS[$set_name]}"
for set_arg in "${set_args[@]}"; do
expanded+=("$set_arg")
done
else
echo "Error: Unknown set '$set_name'"
usage
fi
;;
*)
# Preserve other arguments
expanded+=("$arg")
;;
esac
i=$((i+1))
done
# If we expanded sets, recursively expand again until no more sets
if [ $has_sets -eq 1 ]; then
expand_args "${expanded[@]}"
else
# No more sets, return the fully expanded arguments
echo "${expanded[@]+"${expanded[@]}"}"
fi
}
# Process the final expanded command line
process_command() {
local filter=""
declare -A dir_filters_map # Maps directory to array of filters
if ((VERBOSE >= 1)); then
echo "Expanded arguments:"
for arg in "$@"; do
echo " $arg"
done
fi
# Process final arguments
local i=1
while [ $i -le $# ]; do
local arg="${!i}"
case "$arg" in
-f|--filter)
i=$((i+1))
[ $i -le $# ] || break
filter="${!i}"
;;
-o|--output)
i=$((i+1))
[ $i -le $# ] || break
OUTPUT="${!i}"
;;
-v)
((VERBOSE++))
;;
-vv)
VERBOSE=2
;;
-s|--set)
echo "Warning: Set argument found after expansion"
i=$((i+1))
;;
-*)
# Skip other options
;;
*)
# It's a directory
if [ -e "$arg" ]; then
# Add filter to this directory's filter list
if [ -n "$filter" ]; then
if [ -n "${dir_filters_map[$arg]:-}" ]; then
dir_filters_map["$arg"]="${dir_filters_map["$arg"]}|$filter"
else
dir_filters_map["$arg"]="$filter"
fi
if ((VERBOSE >= 1)); then
echo "Adding filter: $filter to directory: $arg"
fi
else
# If no filter specified, ensure directory is in the map
[ -z "${dir_filters_map[$arg]:-}" ] && dir_filters_map["$arg"]=""
if ((VERBOSE >= 1)); then
echo "Adding directory with no filter: $arg"
fi
fi
else
echo "Warning: Directory '$arg' not found"
fi
;;
esac
i=$((i+1))
done
# Convert output path and check conflicts
output_abs_path=$(realpath -m "$OUTPUT")
output_rel_path=$(realpath --relative-to=. "$output_abs_path")
# Generate directory tree
{
echo "Directory Tree:"
if command -v tree &>/dev/null; then
tree -a -I '.git' .
else
find . -name .git -prune -o -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g'
fi
} > "$OUTPUT"
# Process directories and collect files
declare -a all_files=()
# Cache git-ignored files once
declare -a git_ignored_files=()
if git rev-parse --is-inside-work-tree &>/dev/null; then
while IFS= read -r ignored_file; do
git_ignored_files+=("$ignored_file")
done < <(git ls-files --others --ignored --exclude-standard 2>/dev/null)
if ((VERBOSE >= 1)); then
echo "Cached ${#git_ignored_files[@]} git-ignored files"
fi
fi
for dir in "${!dir_filters_map[@]}"; do
local filters="${dir_filters_map[$dir]}"
if ((VERBOSE >= 1)); then
echo "Processing directory: $dir with filters: ${filters:-none}"
fi
# Get all files in the directory first
declare -a dir_files=()
while IFS= read -r -d $'\0' file; do
local rel_path="${file#./}"
[[ -z "$rel_path" || "$rel_path" == "." ]] && continue
# Skip output file
[[ "$rel_path" == "$output_rel_path" ]] && continue
# Check if file is git-ignored using cached list
local is_ignored=0
for ignored in "${git_ignored_files[@]}"; do
if [[ "$rel_path" == "$ignored" ]]; then
is_ignored=1
break
fi
done
# Skip git-ignored files
[[ $is_ignored -eq 1 ]] && continue
dir_files+=("$rel_path")
done < <(find "$dir" \( -path '*/.git' -prune \) -o \( -path "./$output_rel_path" -prune \) -o -type f -print0 2>/dev/null)
if ((VERBOSE >= 1)); then
echo " Found ${#dir_files[@]} files in directory"
fi
# If filters are specified, apply them to the full file list
if [[ -n "$filters" ]]; then
# Create temp file with all paths
local temp_file=$(mktemp)
printf "%s\n" "${dir_files[@]}" > "$temp_file"
# Apply filters to get matching files
declare -a matching_files=()
while IFS= read -r matched; do
[[ -n "$matched" ]] && matching_files+=("$matched")
(( VERBOSE >= 2 )) && echo " Included: $matched"
done < <(grep -E "($filters)" "$temp_file")
# Add matching files to all_files
all_files+=("${matching_files[@]}")
# Clean up
rm -f "$temp_file"
if ((VERBOSE >= 1)); then
echo " Matched ${#matching_files[@]} files after filtering"
fi
else
# No filter, add all files
all_files+=("${dir_files[@]}")
if ((VERBOSE >= 2)); then
for file in "${dir_files[@]}"; do
echo " Included: $file"
done
fi
fi
done
# Generate unique file list
if [ ${#all_files[@]} -gt 0 ]; then
readarray -t unique_files < <(printf "%s\n" "${all_files[@]}" | sort -u)
# Append file contents to output
{
echo -e "\n\nFile Contents:"
for file in "${unique_files[@]}"; do
if [[ -L "$file" ]]; then
target=$(readlink -f "$file" || echo "unknown")
echo -e "\n===== SYMLINK: $file$target ====="
else
echo -e "\n===== FILE: $file ====="
cat "$file" 2>/dev/null || echo "Error: Unable to read file"
fi
done
} >> "$OUTPUT"
fi
}
main() {
# No arguments? Show usage
[ $# -eq 0 ] && usage
# First scan for verbose flags
for arg in "$@"; do
if [[ "$arg" == "-v" ]]; then
((VERBOSE++))
elif [[ "$arg" == "-vv" ]]; then
VERBOSE=2
fi
done
# Expand all set arguments recursively
local -a expanded_args
read -ra expanded_args <<< "$(expand_args "$@")"
# Process the completely expanded arguments
process_command "${expanded_args[@]}"
echo "Concatenation complete. Output written to $OUTPUT" >&2
}
main "$@"

4
scripts/container.sh Normal file
View File

@@ -0,0 +1,4 @@
#!/bin/bash
container_id=$(docker ps -q)
docker exec -it $container_id bash

23
scripts/install.sh Normal file
View File

@@ -0,0 +1,23 @@
#!/bin/bash
cd /
git clone https://git.nielsgeens.be/llm/SIA.git
cd /SIA
pip3 install -r requirements.txt
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
nvm install node
cd /SIA/web
npm install
npm install -D tailwindcss
npm run build
mv /root/SIA/web/dist/ /root/SIA/static
apt update
apt install -y vim tmux
vim .env
cd /root/SIA
python3 -m sia
#The SIA source is located in /root/sia. Not all features are implemented yet. Look at the readme and code to find what is missing. Make sure to unit test your work.

11
scripts/restart.sh Normal file
View File

@@ -0,0 +1,11 @@
#!/bin/bash
while true; do
PYTHONPATH="/root/sia:$PYTHONPATH" python3 -m sia
if [ $? -eq 42 ]; then
echo "SIA exited with code 42. Restarting."
else
echo "SIA exited with code $?. Not restarting."
break
fi
done

34
scripts/run.sh Normal file
View File

@@ -0,0 +1,34 @@
#!/bin/bash
export MSYS_NO_PATHCONV=1
set -e
function chown_iterations() {
if [ -d "./iterations" ] && [ "$(find ./iterations/ ! -user $USER -o ! -group $USER 2>/dev/null)" ]; then
echo "Chowning iterations directory"
sudo chown -R $USER:$USER ./iterations/
fi
}
trap chown_iterations EXIT
docker build \
--tag sia \
.
docker run \
--init \
--rm \
-ti \
--gpus=all \
-p 8080:8080 \
--env-file .env \
-v /$(pwd)/model/:/root/models/current/ \
-v /$(pwd)/iterations/:/root/data/iterations/ \
-v /$(pwd)/tasks/:/root/data/tasks/ \
-v /$(pwd)/user/:/root/data/user/ \
-v /$(pwd)/environment/:/root/data/environment/ \
-v /$(pwd)/:/root/sia/ \
sia "$@"
exit $?

12
scripts/test.sh Normal file
View File

@@ -0,0 +1,12 @@
#!/bin/bash
docker build \
--target sia-test \
--tag sia-test \
.
docker run \
--rm \
--gpus=all \
-v /$(pwd)/model/:/root/model/ \
sia-test