Compare commits

..
Author SHA1 Message Date
hermes 2fcb438d53 feat: fallback del modelo via HuggingFace si el registry falla
Si el pull de Ollama agota 3 intentos (red sin salida al registry), el
script descarga el mismo modelo (GGUF Q4_K_M, ~2 GB) desde HuggingFace
con curl.exe --retry 3, lo copia al volumen y lo importa con ollama
create. Probado e2e: cp + create + ollama list OK (2.0 GB).

Sin -v en el down: el volumen (modelo cacheado) se conserva entre runs.
2026-09-12 21:04:02 +02:00
4 changed files with 83 additions and 132 deletions

No files matched your search

+20 -32
View File
@@ -80,9 +80,6 @@ if ($TotalRamGb -lt 3.5) {
} }
Ok "RAM: $TotalRamGb GB" Ok "RAM: $TotalRamGb GB"
# --- Tumbar deploy previo (antes de detectar puertos) -----------------------
cmd /c docker rm -f d0a1-hermes-ollama '>' NUL '2>&1'
# --- Auto-detect Ollama port ------------------------------------------------ # --- Auto-detect Ollama port ------------------------------------------------
$OllamaPort = Find-FreePort 11434 $OllamaPort = Find-FreePort 11434
@@ -99,6 +96,7 @@ Write-Host ''
# --- 1. Arrancar Ollama (Docker) ------------------------------------------- # --- 1. Arrancar Ollama (Docker) -------------------------------------------
Warn '[1/3] Arrancando Ollama (IA local)...' Warn '[1/3] Arrancando Ollama (IA local)...'
cmd /c docker rm -f d0a1-hermes-ollama '>' NUL '2>&1'
$running = docker ps --format '{{.Names}}' | Select-String -Quiet 'd0a1-hermes-ollama' $running = docker ps --format '{{.Names}}' | Select-String -Quiet 'd0a1-hermes-ollama'
if (-not $running) { if (-not $running) {
docker run -d --name d0a1-hermes-ollama ` docker run -d --name d0a1-hermes-ollama `
@@ -127,46 +125,36 @@ Warn ' Descargando modelo (llama3.2:3b, ~2 GB)...'
# Si el usuario define $env:HTTPS_PROXY, Ollama lo usa para el pull (doc oficial): # Si el usuario define $env:HTTPS_PROXY, Ollama lo usa para el pull (doc oficial):
$ProxyEnv = @() $ProxyEnv = @()
if ($env:HTTPS_PROXY) { $ProxyEnv = @('-e', "HTTPS_PROXY=$env:HTTPS_PROXY", '-e', "HTTP_PROXY=$env:HTTP_PROXY") } if ($env:HTTPS_PROXY) { $ProxyEnv = @('-e', "HTTPS_PROXY=$env:HTTPS_PROXY", '-e', "HTTP_PROXY=$env:HTTP_PROXY") }
# --- Modelo: HF primero (CDN propio, rapido) y registry de Ollama como ultimo recurso --- $PullOk = $false
$Gguf = Join-Path $ScriptDir 'llama3.2-3b-q4.gguf' foreach ($Attempt in 1..3) {
$HfUrls = @( if ($Attempt -gt 1) { Warn "Reintento $Attempt de 3..." }
'https://huggingface.co/bartowski/Llama-3.2-3B-Instruct-GGUF/resolve/main/Llama-3.2-3B-Instruct-Q4_K_M.gguf', docker exec @ProxyEnv d0a1-hermes-ollama ollama pull llama3.2:3b
'https://huggingface.co/unsloth/Llama-3.2-3B-Instruct-GGUF/resolve/main/Llama-3.2-3B-Instruct-Q4_K_M.gguf' if ($LASTEXITCODE -eq 0) { $PullOk = $true; break }
) Warn 'Descarga interrumpida (red). Reintentando en 5 s...'
Info 'Descargando modelo de IA (llama3.2:3b, ~2 GB)...' Start-Sleep -Seconds 5
foreach ($Url in $HfUrls) {
curl.exe -# -L --retry 3 --max-time 1800 -o "$Gguf" $Url
if ($LASTEXITCODE -eq 0 -and (Test-Path $Gguf) -and (Get-Item $Gguf).Length -gt 1900000000) { break }
Remove-Item "$Gguf" -Force -ErrorAction SilentlyContinue
if ($Url -ne $HfUrls[-1]) { Warn 'Mirror no accesible, probando el siguiente...' }
} }
if ((Test-Path $Gguf) -and (Get-Item $Gguf).Length -gt 1900000000) { if (-not $PullOk) {
Info 'Importando modelo en Ollama...' # --- Fallback: mismo modelo via HuggingFace (otro CDN, no el registry de Ollama) ---
Warn 'Registry de Ollama no accesible. Probando via HuggingFace (mismo modelo)...'
$Gguf = Join-Path $ScriptDir 'llama3.2-3b-q4.gguf'
curl.exe -L -# --retry 3 --max-time 1800 -o "$Gguf" 'https://huggingface.co/bartowski/Llama-3.2-3B-Instruct-GGUF/resolve/main/Llama-3.2-3B-Instruct-Q4_K_M.gguf'
if ($LASTEXITCODE -eq 0 -and (Get-Item $Gguf).Length -gt 1900000000) {
docker cp "$Gguf" d0a1-hermes-ollama:/root/.ollama/import.gguf docker cp "$Gguf" d0a1-hermes-ollama:/root/.ollama/import.gguf
docker exec d0a1-hermes-ollama sh -c 'printf "FROM /root/.ollama/import.gguf\\nPARAMETER num_ctx 16384\\n" > /tmp/mf && ollama create llama3.2:3b -f /tmp/mf' docker exec d0a1-hermes-ollama sh -c 'echo FROM /root/.ollama/import.gguf > /tmp/mf && ollama create llama3.2:3b -f /tmp/mf'
$CreateOk = ($LASTEXITCODE -eq 0) $CreateOk = ($LASTEXITCODE -eq 0)
docker exec d0a1-hermes-ollama rm -f /root/.ollama/import.gguf | Out-Null docker exec d0a1-hermes-ollama rm -f /root/.ollama/import.gguf | Out-Null
Remove-Item "$Gguf" -Force -ErrorAction SilentlyContinue Remove-Item "$Gguf" -Force -ErrorAction SilentlyContinue
$PullOk = $CreateOk if ($CreateOk) { $PullOk = $true }
if (-not $CreateOk) { Err 'Fallo al importar el modelo desde el GGUF.' } else { Err 'Fallo al importar el modelo desde el GGUF.' }
} else { } else {
# Ultimo recurso: pull directo (1 intento, ya sin esperar 3 rondas) Err 'No se pudo descargar el modelo (ni registry ni HuggingFace).'
Warn 'HuggingFace no accesible. Probando el registry de Ollama (ultimo recurso)...'
docker exec @ProxyEnv d0a1-hermes-ollama ollama pull llama3.2:3b
if ($LASTEXITCODE -eq 0) {
$PullOk = $true
# Contexto ampliado (el default 4096 da 400 en Open WebUI con prompts largos)
docker exec d0a1-hermes-ollama sh -c 'printf "FROM llama3.2:3b\\nPARAMETER num_ctx 16384\\n" > /tmp/mf && ollama create llama3.2:3b -f /tmp/mf'
}
}
if (-not $PullOk) {
Err 'No se pudo descargar el modelo (ni HuggingFace ni registry).'
if (-not $env:HTTPS_PROXY) { if (-not $env:HTTPS_PROXY) {
Write-Host ' Tu red bloquea ambos. Si tienes proxy/VPN:' Write-Host ' Tu red bloquea ambos. Si tienes proxy/VPN:'
Write-Host ' $env:HTTPS_PROXY = "http://127.0.0.1:7890" # (puerto de tu proxy)' Write-Host ' $env:HTTPS_PROXY = "http://127.0.0.1:7890" # (puerto de tu proxy)'
Write-Host ' .\deploy.ps1 vps' Write-Host ' .\deploy.ps1 vps'
} }
exit 1 exit 1
}
} }
Ok "Ollama corriendo en http://localhost:${OllamaPort}" Ok "Ollama corriendo en http://localhost:${OllamaPort}"
+20 -32
View File
@@ -80,9 +80,6 @@ if ($TotalRamGb -lt 3.5) {
} }
Ok "RAM: $TotalRamGb GB" Ok "RAM: $TotalRamGb GB"
# --- Tumbar deploy previo (antes de detectar puertos) -----------------------
cmd /c docker rm -f d0a1-openclaw-ollama '>' NUL '2>&1'
# --- Auto-detect Ollama port ------------------------------------------------ # --- Auto-detect Ollama port ------------------------------------------------
$OllamaPort = Find-FreePort 11434 $OllamaPort = Find-FreePort 11434
@@ -99,6 +96,7 @@ Write-Host ''
# --- 1. Arrancar Ollama (Docker) ------------------------------------------- # --- 1. Arrancar Ollama (Docker) -------------------------------------------
Warn '[1/3] Arrancando Ollama (IA local)...' Warn '[1/3] Arrancando Ollama (IA local)...'
cmd /c docker rm -f d0a1-openclaw-ollama '>' NUL '2>&1'
$running = docker ps --format '{{.Names}}' | Select-String -Quiet 'd0a1-openclaw-ollama' $running = docker ps --format '{{.Names}}' | Select-String -Quiet 'd0a1-openclaw-ollama'
if (-not $running) { if (-not $running) {
docker run -d --name d0a1-openclaw-ollama ` docker run -d --name d0a1-openclaw-ollama `
@@ -127,46 +125,36 @@ Warn ' Descargando modelo (llama3.2:3b, ~2 GB)...'
# Si el usuario define $env:HTTPS_PROXY, Ollama lo usa para el pull (doc oficial): # Si el usuario define $env:HTTPS_PROXY, Ollama lo usa para el pull (doc oficial):
$ProxyEnv = @() $ProxyEnv = @()
if ($env:HTTPS_PROXY) { $ProxyEnv = @('-e', "HTTPS_PROXY=$env:HTTPS_PROXY", '-e', "HTTP_PROXY=$env:HTTP_PROXY") } if ($env:HTTPS_PROXY) { $ProxyEnv = @('-e', "HTTPS_PROXY=$env:HTTPS_PROXY", '-e', "HTTP_PROXY=$env:HTTP_PROXY") }
# --- Modelo: HF primero (CDN propio, rapido) y registry de Ollama como ultimo recurso --- $PullOk = $false
$Gguf = Join-Path $ScriptDir 'llama3.2-3b-q4.gguf' foreach ($Attempt in 1..3) {
$HfUrls = @( if ($Attempt -gt 1) { Warn "Reintento $Attempt de 3..." }
'https://huggingface.co/bartowski/Llama-3.2-3B-Instruct-GGUF/resolve/main/Llama-3.2-3B-Instruct-Q4_K_M.gguf', docker exec @ProxyEnv d0a1-openclaw-ollama ollama pull llama3.2:3b
'https://huggingface.co/unsloth/Llama-3.2-3B-Instruct-GGUF/resolve/main/Llama-3.2-3B-Instruct-Q4_K_M.gguf' if ($LASTEXITCODE -eq 0) { $PullOk = $true; break }
) Warn 'Descarga interrumpida (red). Reintentando en 5 s...'
Info 'Descargando modelo de IA (llama3.2:3b, ~2 GB)...' Start-Sleep -Seconds 5
foreach ($Url in $HfUrls) {
curl.exe -# -L --retry 3 --max-time 1800 -o "$Gguf" $Url
if ($LASTEXITCODE -eq 0 -and (Test-Path $Gguf) -and (Get-Item $Gguf).Length -gt 1900000000) { break }
Remove-Item "$Gguf" -Force -ErrorAction SilentlyContinue
if ($Url -ne $HfUrls[-1]) { Warn 'Mirror no accesible, probando el siguiente...' }
} }
if ((Test-Path $Gguf) -and (Get-Item $Gguf).Length -gt 1900000000) { if (-not $PullOk) {
Info 'Importando modelo en Ollama...' # --- Fallback: mismo modelo via HuggingFace (otro CDN, no el registry de Ollama) ---
Warn 'Registry de Ollama no accesible. Probando via HuggingFace (mismo modelo)...'
$Gguf = Join-Path $ScriptDir 'llama3.2-3b-q4.gguf'
curl.exe -L -# --retry 3 --max-time 1800 -o "$Gguf" 'https://huggingface.co/bartowski/Llama-3.2-3B-Instruct-GGUF/resolve/main/Llama-3.2-3B-Instruct-Q4_K_M.gguf'
if ($LASTEXITCODE -eq 0 -and (Get-Item $Gguf).Length -gt 1900000000) {
docker cp "$Gguf" d0a1-openclaw-ollama:/root/.ollama/import.gguf docker cp "$Gguf" d0a1-openclaw-ollama:/root/.ollama/import.gguf
docker exec d0a1-openclaw-ollama sh -c 'printf "FROM /root/.ollama/import.gguf\\nPARAMETER num_ctx 16384\\n" > /tmp/mf && ollama create llama3.2:3b -f /tmp/mf' docker exec d0a1-openclaw-ollama sh -c 'echo FROM /root/.ollama/import.gguf > /tmp/mf && ollama create llama3.2:3b -f /tmp/mf'
$CreateOk = ($LASTEXITCODE -eq 0) $CreateOk = ($LASTEXITCODE -eq 0)
docker exec d0a1-openclaw-ollama rm -f /root/.ollama/import.gguf | Out-Null docker exec d0a1-openclaw-ollama rm -f /root/.ollama/import.gguf | Out-Null
Remove-Item "$Gguf" -Force -ErrorAction SilentlyContinue Remove-Item "$Gguf" -Force -ErrorAction SilentlyContinue
$PullOk = $CreateOk if ($CreateOk) { $PullOk = $true }
if (-not $CreateOk) { Err 'Fallo al importar el modelo desde el GGUF.' } else { Err 'Fallo al importar el modelo desde el GGUF.' }
} else { } else {
# Ultimo recurso: pull directo (1 intento, ya sin esperar 3 rondas) Err 'No se pudo descargar el modelo (ni registry ni HuggingFace).'
Warn 'HuggingFace no accesible. Probando el registry de Ollama (ultimo recurso)...'
docker exec @ProxyEnv d0a1-openclaw-ollama ollama pull llama3.2:3b
if ($LASTEXITCODE -eq 0) {
$PullOk = $true
# Contexto ampliado (el default 4096 da 400 en Open WebUI con prompts largos)
docker exec d0a1-openclaw-ollama sh -c 'printf "FROM llama3.2:3b\\nPARAMETER num_ctx 16384\\n" > /tmp/mf && ollama create llama3.2:3b -f /tmp/mf'
}
}
if (-not $PullOk) {
Err 'No se pudo descargar el modelo (ni HuggingFace ni registry).'
if (-not $env:HTTPS_PROXY) { if (-not $env:HTTPS_PROXY) {
Write-Host ' Tu red bloquea ambos. Si tienes proxy/VPN:' Write-Host ' Tu red bloquea ambos. Si tienes proxy/VPN:'
Write-Host ' $env:HTTPS_PROXY = "http://127.0.0.1:7890" # (puerto de tu proxy)' Write-Host ' $env:HTTPS_PROXY = "http://127.0.0.1:7890" # (puerto de tu proxy)'
Write-Host ' .\deploy.ps1 vps' Write-Host ' .\deploy.ps1 vps'
} }
exit 1 exit 1
}
} }
Ok "Ollama corriendo en http://localhost:${OllamaPort}" Ok "Ollama corriendo en http://localhost:${OllamaPort}"
+23 -35
View File
@@ -86,11 +86,6 @@ if ($TotalRamGb -lt 3.5) {
} }
Ok "RAM: $TotalRamGb GB" Ok "RAM: $TotalRamGb GB"
# --- Tumbar deploy previo (antes de detectar puertos) ----------------------
# Mantiene los volumenes (el modelo ya descargado no se re-descarga) y libera
# los puertos para que Find-FreePort vea el estado REAL tras el down.
cmd /c docker compose -f $ComposeFile down '>' NUL '2>&1'
# --- Auto-detect ports ---------------------------------------------------- # --- Auto-detect ports ----------------------------------------------------
$OllamaPort = Find-FreePort 11434 $OllamaPort = Find-FreePort 11434
$WebUiPort = Find-FreePort 3000 $WebUiPort = Find-FreePort 3000
@@ -121,6 +116,9 @@ if ($WebUiPort -ne 3000) { Warn "Puerto 3000 ocupado, usando $WebUiPort" }
Write-Host '' Write-Host ''
# --- Deploy ---------------------------------------------------------------- # --- Deploy ----------------------------------------------------------------
# Si hay un deploy previo del pack, tumbarlo primero (mantiene los volumenes:
# el modelo ya descargado no se re-descarga) para que los nuevos puertos apliquen.
cmd /c docker compose -f $ComposeFile down '>' NUL '2>&1'
Warn 'Descargando contenedores (2-3 min la primera vez)...' Warn 'Descargando contenedores (2-3 min la primera vez)...'
$env:OLLAMA_PORT = "$OllamaPort" $env:OLLAMA_PORT = "$OllamaPort"
$env:WEBUI_PORT = "$WebUiPort" $env:WEBUI_PORT = "$WebUiPort"
@@ -128,7 +126,7 @@ docker compose -f $ComposeFile up -d
if ($LASTEXITCODE -ne 0) { Err "docker compose up fallo (exit $LASTEXITCODE)."; exit 1 } if ($LASTEXITCODE -ne 0) { Err "docker compose up fallo (exit $LASTEXITCODE)."; exit 1 }
# --- Pull model ------------------------------------------------------------- # --- Pull model -------------------------------------------------------------
Info 'Esperando a que Ollama arranque...' Warn 'Descargando modelo de IA (llama3.2:3b, ~2 GB)...'
$MaxWait = 60; $Waited = 0 $MaxWait = 60; $Waited = 0
while ($true) { while ($true) {
# Descarte de stderr via cmd /c (ver nota de PS 5.1 / PS #4002 arriba) # Descarte de stderr via cmd /c (ver nota de PS 5.1 / PS #4002 arriba)
@@ -144,46 +142,36 @@ while ($true) {
# Si el usuario define $env:HTTPS_PROXY, Ollama lo usa para el pull (doc oficial): # Si el usuario define $env:HTTPS_PROXY, Ollama lo usa para el pull (doc oficial):
$ProxyEnv = @() $ProxyEnv = @()
if ($env:HTTPS_PROXY) { $ProxyEnv = @('-e', "HTTPS_PROXY=$env:HTTPS_PROXY", '-e', "HTTP_PROXY=$env:HTTP_PROXY") } if ($env:HTTPS_PROXY) { $ProxyEnv = @('-e', "HTTPS_PROXY=$env:HTTPS_PROXY", '-e', "HTTP_PROXY=$env:HTTP_PROXY") }
# --- Modelo: HF primero (CDN propio, rapido) y registry de Ollama como ultimo recurso --- $PullOk = $false
$Gguf = Join-Path $ScriptDir 'llama3.2-3b-q4.gguf' foreach ($Attempt in 1..3) {
$HfUrls = @( if ($Attempt -gt 1) { Warn "Reintento $Attempt de 3..." }
'https://huggingface.co/bartowski/Llama-3.2-3B-Instruct-GGUF/resolve/main/Llama-3.2-3B-Instruct-Q4_K_M.gguf', docker exec @ProxyEnv d0a1-ollama ollama pull llama3.2:3b
'https://huggingface.co/unsloth/Llama-3.2-3B-Instruct-GGUF/resolve/main/Llama-3.2-3B-Instruct-Q4_K_M.gguf' if ($LASTEXITCODE -eq 0) { $PullOk = $true; break }
) Warn 'Descarga interrumpida (red). Reintentando en 5 s...'
Info 'Descargando modelo de IA (llama3.2:3b, ~2 GB)...' Start-Sleep -Seconds 5
foreach ($Url in $HfUrls) {
curl.exe -# -L --retry 3 --max-time 1800 -o "$Gguf" $Url
if ($LASTEXITCODE -eq 0 -and (Test-Path $Gguf) -and (Get-Item $Gguf).Length -gt 1900000000) { break }
Remove-Item "$Gguf" -Force -ErrorAction SilentlyContinue
if ($Url -ne $HfUrls[-1]) { Warn 'Mirror no accesible, probando el siguiente...' }
} }
if ((Test-Path $Gguf) -and (Get-Item $Gguf).Length -gt 1900000000) { if (-not $PullOk) {
Info 'Importando modelo en Ollama...' # --- Fallback: mismo modelo via HuggingFace (otro CDN, no el registry de Ollama) ---
Warn 'Registry de Ollama no accesible. Probando via HuggingFace (mismo modelo)...'
$Gguf = Join-Path $ScriptDir 'llama3.2-3b-q4.gguf'
curl.exe -L -# --retry 3 --max-time 1800 -o "$Gguf" 'https://huggingface.co/bartowski/Llama-3.2-3B-Instruct-GGUF/resolve/main/Llama-3.2-3B-Instruct-Q4_K_M.gguf'
if ($LASTEXITCODE -eq 0 -and (Get-Item $Gguf).Length -gt 1900000000) {
docker cp "$Gguf" d0a1-ollama:/root/.ollama/import.gguf docker cp "$Gguf" d0a1-ollama:/root/.ollama/import.gguf
docker exec d0a1-ollama sh -c 'printf "FROM /root/.ollama/import.gguf\\nPARAMETER num_ctx 16384\\n" > /tmp/mf && ollama create llama3.2:3b -f /tmp/mf' docker exec d0a1-ollama sh -c 'echo FROM /root/.ollama/import.gguf > /tmp/mf && ollama create llama3.2:3b -f /tmp/mf'
$CreateOk = ($LASTEXITCODE -eq 0) $CreateOk = ($LASTEXITCODE -eq 0)
docker exec d0a1-ollama rm -f /root/.ollama/import.gguf | Out-Null docker exec d0a1-ollama rm -f /root/.ollama/import.gguf | Out-Null
Remove-Item "$Gguf" -Force -ErrorAction SilentlyContinue Remove-Item "$Gguf" -Force -ErrorAction SilentlyContinue
$PullOk = $CreateOk if ($CreateOk) { $PullOk = $true }
if (-not $CreateOk) { Err 'Fallo al importar el modelo desde el GGUF.' } else { Err 'Fallo al importar el modelo desde el GGUF.' }
} else { } else {
# Ultimo recurso: pull directo (1 intento, ya sin esperar 3 rondas) Err 'No se pudo descargar el modelo (ni registry ni HuggingFace).'
Warn 'HuggingFace no accesible. Probando el registry de Ollama (ultimo recurso)...'
docker exec @ProxyEnv d0a1-ollama ollama pull llama3.2:3b
if ($LASTEXITCODE -eq 0) {
$PullOk = $true
# Contexto ampliado (el default 4096 da 400 en Open WebUI con prompts largos)
docker exec d0a1-ollama sh -c 'printf "FROM llama3.2:3b\\nPARAMETER num_ctx 16384\\n" > /tmp/mf && ollama create llama3.2:3b -f /tmp/mf'
}
}
if (-not $PullOk) {
Err 'No se pudo descargar el modelo (ni HuggingFace ni registry).'
if (-not $env:HTTPS_PROXY) { if (-not $env:HTTPS_PROXY) {
Write-Host ' Tu red bloquea ambos. Si tienes proxy/VPN:' Write-Host ' Tu red bloquea ambos. Si tienes proxy/VPN:'
Write-Host ' $env:HTTPS_PROXY = "http://127.0.0.1:7890" # (puerto de tu proxy)' Write-Host ' $env:HTTPS_PROXY = "http://127.0.0.1:7890" # (puerto de tu proxy)'
Write-Host ' .\deploy.ps1 vps' Write-Host ' .\deploy.ps1 vps'
} }
exit 1 exit 1
}
} }
# --- Done ------------------------------------------------------------------- # --- Done -------------------------------------------------------------------
+20 -33
View File
@@ -120,9 +120,6 @@ if (-not (Test-Path $EnvFile)) {
} }
# --- Auto-detect ports ---------------------------------------------------- # --- Auto-detect ports ----------------------------------------------------
# --- Tumbar deploy previo (antes de detectar puertos) ----------------------
cmd /c docker compose -f $ComposeFile down '>' NUL '2>&1'
$OllamaPort = Find-FreePort 11434 $OllamaPort = Find-FreePort 11434
$WpPort = Find-FreePort 8080 $WpPort = Find-FreePort 8080
$WebUiPort = Find-FreePort 3000 $WebUiPort = Find-FreePort 3000
@@ -165,7 +162,7 @@ docker compose -f $ComposeFile up -d
if ($LASTEXITCODE -ne 0) { Err "docker compose up fallo (exit $LASTEXITCODE)."; exit 1 } if ($LASTEXITCODE -ne 0) { Err "docker compose up fallo (exit $LASTEXITCODE)."; exit 1 }
# --- Pull model ------------------------------------------------------------- # --- Pull model -------------------------------------------------------------
Info 'Esperando a que Ollama arranque...' Warn 'Descargando modelo de IA (llama3.2:3b, ~2 GB)...'
$MaxWait = 60; $Waited = 0 $MaxWait = 60; $Waited = 0
while ($true) { while ($true) {
# Descarte de stderr via cmd /c (ver nota de PS 5.1 / PS #4002 arriba) # Descarte de stderr via cmd /c (ver nota de PS 5.1 / PS #4002 arriba)
@@ -181,46 +178,36 @@ while ($true) {
# Si el usuario define $env:HTTPS_PROXY, Ollama lo usa para el pull (doc oficial): # Si el usuario define $env:HTTPS_PROXY, Ollama lo usa para el pull (doc oficial):
$ProxyEnv = @() $ProxyEnv = @()
if ($env:HTTPS_PROXY) { $ProxyEnv = @('-e', "HTTPS_PROXY=$env:HTTPS_PROXY", '-e', "HTTP_PROXY=$env:HTTP_PROXY") } if ($env:HTTPS_PROXY) { $ProxyEnv = @('-e', "HTTPS_PROXY=$env:HTTPS_PROXY", '-e', "HTTP_PROXY=$env:HTTP_PROXY") }
# --- Modelo: HF primero (CDN propio, rapido) y registry de Ollama como ultimo recurso --- $PullOk = $false
$Gguf = Join-Path $ScriptDir 'llama3.2-3b-q4.gguf' foreach ($Attempt in 1..3) {
$HfUrls = @( if ($Attempt -gt 1) { Warn "Reintento $Attempt de 3..." }
'https://huggingface.co/bartowski/Llama-3.2-3B-Instruct-GGUF/resolve/main/Llama-3.2-3B-Instruct-Q4_K_M.gguf', docker exec @ProxyEnv d0a1-wp-ollama ollama pull llama3.2:3b
'https://huggingface.co/unsloth/Llama-3.2-3B-Instruct-GGUF/resolve/main/Llama-3.2-3B-Instruct-Q4_K_M.gguf' if ($LASTEXITCODE -eq 0) { $PullOk = $true; break }
) Warn 'Descarga interrumpida (red). Reintentando en 5 s...'
Info 'Descargando modelo de IA (llama3.2:3b, ~2 GB)...' Start-Sleep -Seconds 5
foreach ($Url in $HfUrls) {
curl.exe -# -L --retry 3 --max-time 1800 -o "$Gguf" $Url
if ($LASTEXITCODE -eq 0 -and (Test-Path $Gguf) -and (Get-Item $Gguf).Length -gt 1900000000) { break }
Remove-Item "$Gguf" -Force -ErrorAction SilentlyContinue
if ($Url -ne $HfUrls[-1]) { Warn 'Mirror no accesible, probando el siguiente...' }
} }
if ((Test-Path $Gguf) -and (Get-Item $Gguf).Length -gt 1900000000) { if (-not $PullOk) {
Info 'Importando modelo en Ollama...' # --- Fallback: mismo modelo via HuggingFace (otro CDN, no el registry de Ollama) ---
Warn 'Registry de Ollama no accesible. Probando via HuggingFace (mismo modelo)...'
$Gguf = Join-Path $ScriptDir 'llama3.2-3b-q4.gguf'
curl.exe -L -# --retry 3 --max-time 1800 -o "$Gguf" 'https://huggingface.co/bartowski/Llama-3.2-3B-Instruct-GGUF/resolve/main/Llama-3.2-3B-Instruct-Q4_K_M.gguf'
if ($LASTEXITCODE -eq 0 -and (Get-Item $Gguf).Length -gt 1900000000) {
docker cp "$Gguf" d0a1-wp-ollama:/root/.ollama/import.gguf docker cp "$Gguf" d0a1-wp-ollama:/root/.ollama/import.gguf
docker exec d0a1-wp-ollama sh -c 'printf "FROM /root/.ollama/import.gguf\\nPARAMETER num_ctx 16384\\n" > /tmp/mf && ollama create llama3.2:3b -f /tmp/mf' docker exec d0a1-wp-ollama sh -c 'echo FROM /root/.ollama/import.gguf > /tmp/mf && ollama create llama3.2:3b -f /tmp/mf'
$CreateOk = ($LASTEXITCODE -eq 0) $CreateOk = ($LASTEXITCODE -eq 0)
docker exec d0a1-wp-ollama rm -f /root/.ollama/import.gguf | Out-Null docker exec d0a1-wp-ollama rm -f /root/.ollama/import.gguf | Out-Null
Remove-Item "$Gguf" -Force -ErrorAction SilentlyContinue Remove-Item "$Gguf" -Force -ErrorAction SilentlyContinue
$PullOk = $CreateOk if ($CreateOk) { $PullOk = $true }
if (-not $CreateOk) { Err 'Fallo al importar el modelo desde el GGUF.' } else { Err 'Fallo al importar el modelo desde el GGUF.' }
} else { } else {
# Ultimo recurso: pull directo (1 intento, ya sin esperar 3 rondas) Err 'No se pudo descargar el modelo (ni registry ni HuggingFace).'
Warn 'HuggingFace no accesible. Probando el registry de Ollama (ultimo recurso)...'
docker exec @ProxyEnv d0a1-wp-ollama ollama pull llama3.2:3b
if ($LASTEXITCODE -eq 0) {
$PullOk = $true
# Contexto ampliado (el default 4096 da 400 en Open WebUI con prompts largos)
docker exec d0a1-wp-ollama sh -c 'printf "FROM llama3.2:3b\\nPARAMETER num_ctx 16384\\n" > /tmp/mf && ollama create llama3.2:3b -f /tmp/mf'
}
}
if (-not $PullOk) {
Err 'No se pudo descargar el modelo (ni HuggingFace ni registry).'
if (-not $env:HTTPS_PROXY) { if (-not $env:HTTPS_PROXY) {
Write-Host ' Tu red bloquea ambos. Si tienes proxy/VPN:' Write-Host ' Tu red bloquea ambos. Si tienes proxy/VPN:'
Write-Host ' $env:HTTPS_PROXY = "http://127.0.0.1:7890" # (puerto de tu proxy)' Write-Host ' $env:HTTPS_PROXY = "http://127.0.0.1:7890" # (puerto de tu proxy)'
Write-Host ' .\deploy.ps1 vps' Write-Host ' .\deploy.ps1 vps'
} }
exit 1 exit 1
}
} }
# --- Done ------------------------------------------------------------------- # --- Done -------------------------------------------------------------------