Files
hass-addons/localai-p2p-worker/run.sh
alex 805290e812
Some checks failed
Builder / Build addons (localai-p2p-master, amd64) (push) Failing after 9s
Builder / Build addons (localai-p2p-worker, amd64) (push) Failing after 13s
Validate / validate (push) Failing after 2s
Builder / Create release (push) Has been skipped
9
2025-05-30 15:13:38 +02:00

52 lines
1.9 KiB
Bash

#!/bin/bash
# Forcer l'utilisation de la configuration Home Assistant
echo "Using Home Assistant configuration"
# Vérifier que bashio est disponible
if [ -f /usr/bin/bashio ]; then
echo "DEBUG: bashio found, reading configuration"
GPU_LAYERS="$(bashio config gpu_layers 2>/dev/null || echo '0')"
TOKEN="$(bashio config master_token 2>/dev/null || echo '')"
MODELS_PATH="$(bashio config models_path 2>/dev/null || echo '/share/localai/models')"
else
echo "DEBUG: bashio not found, using defaults"
GPU_LAYERS="0"
TOKEN=""
MODELS_PATH="/share/localai/models"
fi
echo "DEBUG: GPU_LAYERS=$GPU_LAYERS"
echo "DEBUG: TOKEN from config: '$TOKEN'"
echo "DEBUG: MODELS_PATH=$MODELS_PATH"
# Forcer l'utilisation du token si fourni
if [ -n "$TOKEN" ] && [ "$TOKEN" != "null" ] && [ "$TOKEN" != "" ]; then
echo "DEBUG: Setting LOCALAI_P2P_TOKEN to: $TOKEN"
export LOCALAI_P2P_TOKEN="$TOKEN"
export P2P_TOKEN="$TOKEN"
else
echo "DEBUG: No valid token provided in configuration"
fi
echo "DEBUG: LOCALAI_P2P_TOKEN is set to: '$LOCALAI_P2P_TOKEN'"
echo "DEBUG: P2P_TOKEN is set to: '$P2P_TOKEN'"
# Créer le répertoire des modèles s'il n'existe pas
mkdir -p "$MODELS_PATH"
# Nettoyer les fichiers de configuration corrompus
echo "DEBUG: Cleaning corrupted config files in $MODELS_PATH"
find "$MODELS_PATH" -name "*.yaml" -exec grep -l "#!/usr/bin/with-contenv bashio\|mapping values are not allowed in this context" {} \; | while read file; do
echo "DEBUG: Removing corrupted file: $file"
rm -f "$file"
done 2>/dev/null || true
# Définir les variables d'environnement pour LocalAI
export THREADS="${THREADS:-8}"
export OMP_NUM_THREADS="${OMP_NUM_THREADS:-8}"
# Lancer LocalAI avec nos paramètres
echo "DEBUG: Starting LocalAI with models-path=$MODELS_PATH, threads=$THREADS"
exec /build/local-ai run --models-path="$MODELS_PATH" --threads="$THREADS" --address="0.0.0.0:8080" --cors --cors-allow-origins="*"