fdd
Some checks failed
Builder / Build addons (localai-p2p-master, amd64) (push) Failing after 15s
Builder / Build addons (localai-p2p-worker, amd64) (push) Failing after 14s
Validate / validate (push) Failing after 2s
Builder / Create release (push) Has been skipped

This commit is contained in:
2025-05-30 17:35:08 +02:00
parent 7e33a6a069
commit 58e228f0a1
3 changed files with 60 additions and 116 deletions

View File

@@ -1,64 +1,69 @@
#!/command/with-contenv bashio
# shellcheck shell=bash
# ==============================================================================
# LocalAI P2P Worker - Home Assistant Add-on
# ==============================================================================
#!/bin/bash
bashio::log.info "Starting LocalAI P2P Worker"
echo "Starting LocalAI P2P Worker"
# Sourcer bashio pour utiliser les fonctions de configuration Home Assistant
source /usr/lib/bashio/bashio
# Lire la configuration Home Assistant
TOKEN="$(bashio::config 'master_token')"
GPU_LAYERS="$(bashio::config 'gpu_layers')"
DEBUG="$(bashio::config 'debug')"
MODELS_PATH="$(bashio::config 'models_path')"
THREADS="$(bashio::config 'threads')"
bashio::log.info "Configuration loaded:"
bashio::log.info "- Master Token: ${TOKEN:0:20}..."
bashio::log.info "- GPU Layers: ${GPU_LAYERS}"
bashio::log.info "- Debug: ${DEBUG}"
bashio::log.info "- Models Path: ${MODELS_PATH}"
bashio::log.info "- Threads: ${THREADS}"
if [ -f /data/options.json ]; then
TOKEN="$(bashio::config 'master_token' 2>/dev/null || echo '')"
GPU_LAYERS="$(bashio::config 'gpu_layers' 2>/dev/null || echo '0')"
DEBUG="$(bashio::config 'debug' 2>/dev/null || echo 'false')"
MODELS_PATH="$(bashio::config 'models_path' 2>/dev/null || echo '/share/localai/models')"
THREADS="$(bashio::config 'threads' 2>/dev/null || echo '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 bashio::var.has_value "${TOKEN}"; then
export LOCALAI_P2P_TOKEN="${TOKEN}"
export P2P_TOKEN="${TOKEN}"
bashio::log.info "P2P Token configured"
if [ -n "$TOKEN" ] && [ "$TOKEN" != "null" ] && [ "$TOKEN" != "" ]; then
export LOCALAI_P2P_TOKEN="$TOKEN"
export P2P_TOKEN="$TOKEN"
echo "P2P Token configured"
else
bashio::log.warning "No P2P token provided - will generate one"
echo "No P2P token provided - will generate one"
fi
# Créer le répertoire des modèles
bashio::log.info "Creating models directory: ${MODELS_PATH}"
mkdir -p "${MODELS_PATH}"
mkdir -p "$MODELS_PATH"
# Nettoyer les fichiers corrompus
bashio::log.info "Cleaning corrupted files..."
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
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}"
export THREADS="$THREADS"
export OMP_NUM_THREADS="$THREADS"
# Configurer le debug si activé
if bashio::var.true "${DEBUG}"; then
if [ "$DEBUG" = "true" ]; then
export LOCALAI_DEBUG="true"
export LOCALAI_LOG_LEVEL="debug"
bashio::log.info "Debug mode enabled"
echo "Debug mode enabled"
fi
# Configurer GPU layers si spécifié
if [ "${GPU_LAYERS}" -gt 0 ]; then
export LOCALAI_GPU_LAYERS="${GPU_LAYERS}"
bashio::log.info "GPU layers configured: ${GPU_LAYERS}"
if [ "$GPU_LAYERS" -gt 0 ]; then
export LOCALAI_GPU_LAYERS="$GPU_LAYERS"
echo "GPU layers configured: $GPU_LAYERS"
fi
# Lancer LocalAI
bashio::log.info "Starting LocalAI with models path: ${MODELS_PATH}"
echo "Starting LocalAI with models path: $MODELS_PATH"
exec /build/local-ai run \
--models-path="${MODELS_PATH}" \
--threads="${THREADS}" \
--models-path="$MODELS_PATH" \
--threads="$THREADS" \
--address="0.0.0.0:8080" \
--cors \
--cors-allow-origins="*"