92 lines
2.6 KiB
Bash
92 lines
2.6 KiB
Bash
#!/bin/bash
|
|
|
|
# Initialiser bashio pour utiliser les fonctions de configuration Home Assistant
|
|
# shellcheck disable=SC1091
|
|
source /usr/lib/bashio/bashio || {
|
|
echo "Bashio not available, using direct JSON parsing"
|
|
BASHIO_AVAILABLE=false
|
|
}
|
|
|
|
echo "Starting LocalAI P2P Worker"
|
|
|
|
# Fonction pour lire la configuration avec fallback
|
|
get_config() {
|
|
local key="$1"
|
|
local default="$2"
|
|
|
|
if [ -f /data/options.json ]; then
|
|
if command -v bashio::config >/dev/null 2>&1; then
|
|
bashio::config "$key" 2>/dev/null || echo "$default"
|
|
else
|
|
# Fallback: utiliser jq pour lire directement le JSON
|
|
jq -r ".$key // \"$default\"" /data/options.json 2>/dev/null || echo "$default"
|
|
fi
|
|
else
|
|
echo "$default"
|
|
fi
|
|
}
|
|
|
|
# Lire la configuration Home Assistant
|
|
if [ -f /data/options.json ]; then
|
|
echo "Reading Home Assistant configuration..."
|
|
TOKEN="$(get_config 'master_token' '')"
|
|
GPU_LAYERS="$(get_config 'gpu_layers' '0')"
|
|
DEBUG="$(get_config 'debug' 'false')"
|
|
MODELS_PATH="$(get_config 'models_path' '/share/localai/models')"
|
|
THREADS="$(get_config 'threads' '8')"
|
|
|
|
echo "Master Token: $TOKEN"
|
|
echo "GPU Layers: $GPU_LAYERS"
|
|
echo "Debug: $DEBUG"
|
|
echo "Models Path: $MODELS_PATH"
|
|
echo "Threads: $THREADS"
|
|
else
|
|
echo "No Home Assistant config found, using defaults"
|
|
TOKEN=""
|
|
GPU_LAYERS="0"
|
|
DEBUG="false"
|
|
MODELS_PATH="/share/localai/models"
|
|
THREADS="8"
|
|
fi
|
|
|
|
# Configurer le token P2P si fourni
|
|
if [ -n "$TOKEN" ] && [ "$TOKEN" != "null" ] && [ "$TOKEN" != "" ]; then
|
|
export LOCALAI_P2P_TOKEN="$TOKEN"
|
|
export P2P_TOKEN="$TOKEN"
|
|
echo "P2P Token configured"
|
|
else
|
|
echo "No P2P token provided - will generate one"
|
|
fi
|
|
|
|
# Créer le répertoire des modèles
|
|
mkdir -p "$MODELS_PATH"
|
|
|
|
# Nettoyer les fichiers corrompus
|
|
find "$MODELS_PATH" -name "*.yaml" -exec grep -l "#!/usr/bin/with-contenv bashio\|mapping values are not allowed in this context" {} \; 2>/dev/null | xargs rm -f 2>/dev/null || true
|
|
|
|
# Configurer les variables d'environnement
|
|
export THREADS="$THREADS"
|
|
export OMP_NUM_THREADS="$THREADS"
|
|
|
|
# Configurer le debug si activé
|
|
if [ "$DEBUG" = "true" ]; then
|
|
export LOCALAI_DEBUG="true"
|
|
export LOCALAI_LOG_LEVEL="debug"
|
|
echo "Debug mode enabled"
|
|
fi
|
|
|
|
# Configurer GPU layers si spécifié
|
|
if [ "$GPU_LAYERS" -gt 0 ]; then
|
|
export LOCALAI_GPU_LAYERS="$GPU_LAYERS"
|
|
echo "GPU layers configured: $GPU_LAYERS"
|
|
fi
|
|
|
|
# Lancer LocalAI
|
|
echo "Starting LocalAI with models path: $MODELS_PATH"
|
|
exec /build/local-ai run \
|
|
--models-path="$MODELS_PATH" \
|
|
--threads="$THREADS" \
|
|
--address="0.0.0.0:8080" \
|
|
--cors \
|
|
--cors-allow-origins="*"
|