Files
gpu-rent/gpu-rent.sh
T
Leonid Pershin 64f93b4bf6 Update LLM support for llama.cpp and enhance configuration management
- Added support for `llamacpp-models.yaml` in `.gitignore` and implemented logic to copy it in `gpu-rent.ps1` and `gpu-rent.sh`.
- Enhanced CLI to prompt for llama.cpp model presets during setup and execution, improving user experience.
- Updated configuration handling to include `llamacpp_models_manifest` and related functions for managing llama.cpp models.
- Improved documentation in `cli.md` and `llm.md` to reflect changes in llama.cpp integration and model management.
- Refactored provisioning logic to handle llama.cpp model downloads and configurations effectively.
2026-08-21 06:25:12 +03:00

124 lines
3.8 KiB
Bash

#!/usr/bin/env bash
# Linux / macOS / Git Bash: venv + pip + python -m gpu_rent
set -euo pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$ROOT"
load_vars_file() {
local file="$1"
[[ -f "$file" ]] || return 0
while IFS= read -r line || [[ -n "$line" ]]; do
line="${line#"${line%%[![:space:]]*}"}"
line="${line%"${line##*[![:space:]]}"}"
[[ -z "$line" || "$line" == \#* ]] && continue
if [[ "$line" == [eE][xX][pP][oO][rR][tT][[:space:]]* ]]; then
line="${line#*[eE][xX][pP][oO][rR][tT]}"
line="${line#"${line%%[![:space:]]*}"}"
fi
[[ "$line" != *=* ]] && continue
local key="${line%%=*}"
local val="${line#*=}"
key="${key%"${key##*[![:space:]]}"}"
key="${key#"${key%%[![:space:]]*}"}"
val="${val#"${val%%[![:space:]]*}"}"
val="${val%"${val##*[![:space:]]}"}"
if [[ ${#val} -ge 2 ]]; then
local q="${val:0:1}"
if [[ ( "$q" == '"' || "$q" == "'" ) && "${val: -1}" == "$q" ]]; then
val="${val:1:${#val}-2}"
fi
fi
[[ -z "$key" ]] && continue
if [[ -z "${!key+x}" || -z "${!key}" ]]; then
export "$key=$val"
fi
done <"$file"
}
ok_py() {
local exe="$1"
shift || true
command -v "$exe" >/dev/null 2>&1 || return 1
"$exe" "$@" -c 'import sys; raise SystemExit(0 if sys.version_info >= (3, 11) else 1)' >/dev/null 2>&1
}
PY=()
if ok_py python3.12; then
PY=(python3.12)
elif ok_py python3.11; then
PY=(python3.11)
elif ok_py python3; then
PY=(python3)
elif ok_py python; then
PY=(python)
elif ok_py py -3.12; then
PY=(py -3.12)
elif ok_py py -3.11; then
PY=(py -3.11)
else
echo "gpu-rent: нужен Python 3.11+. Ubuntu: sudo apt install python3 python3-venv python3-pip" >&2
exit 1
fi
if [[ -x "$ROOT/.venv/Scripts/python.exe" ]]; then
VENV_PY="$ROOT/.venv/Scripts/python.exe"
elif [[ -x "$ROOT/.venv/bin/python" ]]; then
VENV_PY="$ROOT/.venv/bin/python"
else
echo "gpu-rent: создаю .venv"
"${PY[@]}" -m venv "$ROOT/.venv"
if [[ -x "$ROOT/.venv/Scripts/python.exe" ]]; then
VENV_PY="$ROOT/.venv/Scripts/python.exe"
else
VENV_PY="$ROOT/.venv/bin/python"
fi
fi
STAMP="$ROOT/.venv/.gpu-rent-installed"
if [[ ! -f "$STAMP" || "$ROOT/pyproject.toml" -nt "$STAMP" ]]; then
echo "gpu-rent: ставлю пакет в .venv"
"$VENV_PY" -m pip install -U pip
"$VENV_PY" -m pip install -e "$ROOT"
date -u +"%Y-%m-%dT%H:%M:%SZ" >"$STAMP"
fi
if [[ ! -f "$ROOT/.env" && -f "$ROOT/env.example" ]]; then
cp "$ROOT/env.example" "$ROOT/.env"
echo "gpu-rent: created .env - fill OS_* (see docs/setup.md)"
fi
if [[ ! -f "$ROOT/models.yaml" && -f "$ROOT/models.example.yaml" ]]; then
cp "$ROOT/models.example.yaml" "$ROOT/models.yaml"
echo "gpu-rent: created models.yaml"
fi
if [[ ! -f "$ROOT/extensions.yaml" && -f "$ROOT/extensions.example.yaml" ]]; then
cp "$ROOT/extensions.example.yaml" "$ROOT/extensions.yaml"
echo "gpu-rent: created extensions.yaml"
fi
if [[ ! -f "$ROOT/ollama-models.yaml" && -f "$ROOT/ollama-models.example.yaml" ]]; then
cp "$ROOT/ollama-models.example.yaml" "$ROOT/ollama-models.yaml"
echo "gpu-rent: created ollama-models.yaml"
fi
if [[ ! -f "$ROOT/llamacpp-models.yaml" && -f "$ROOT/llamacpp-models.example.yaml" ]]; then
cp "$ROOT/llamacpp-models.example.yaml" "$ROOT/llamacpp-models.yaml"
echo "gpu-rent: created llamacpp-models.yaml"
fi
if [[ ! -f "$ROOT/gpu-rent.vars" && -f "$ROOT/gpu-rent.vars.example" ]]; then
cp "$ROOT/gpu-rent.vars.example" "$ROOT/gpu-rent.vars"
echo "gpu-rent: created gpu-rent.vars"
fi
load_vars_file "$ROOT/gpu-rent.vars"
ARGS=("$@")
if [[ ${#ARGS[@]} -eq 0 && -n "${GPU_RENT_DEFAULT_ARGS:-}" ]]; then
# shellcheck disable=SC2206
ARGS=(${GPU_RENT_DEFAULT_ARGS})
fi
if [[ -n "${GPU_RENT_EXTRA_ARGS:-}" ]]; then
# shellcheck disable=SC2206
ARGS+=(${GPU_RENT_EXTRA_ARGS})
fi
exec "$VENV_PY" -m gpu_rent "${ARGS[@]}"