# Avvia il cervello linguistico di Neuronal via llama-server, tutto in locale (non più usato dal motore). # API compatibile OpenAI su http://127.0.0.1:/v1 # Il runtime è in runtime/llama (copia autonoma). param( [int]$Port = 8089, [int]$Context = 16384, [switch]$NoVision, # risparmia ~0.9 GB di VRAM [switch]$LowVram, # lascia a llama.cpp la scelta degli strati su GPU (più lento, ~14 tok/s) [switch]$Supervise # riavvia automaticamente il server se termina ) $ErrorActionPreference = 'Stop' $root = Split-Path -Parent $PSScriptRoot $server = Join-Path $root 'runtime\llama\llama-server.exe' $model = Join-Path $root 'neuronal.gguf' $mmproj = Join-Path $root 'neuronal-visione.gguf' foreach ($f in @($server, $model) + $(if (-not $NoVision) { $mmproj })) { if (-not (Test-Path $f)) { throw "File mancante: $f" } } function Test-Health { try { (Invoke-RestMethod "http://127.0.0.1:$Port/health" -TimeoutSec 2).status -eq 'ok' } catch { $false } } if (Test-Health) { Write-Host "llama-server già attivo sulla porta $Port."; exit 0 } if (Get-NetTCPConnection -LocalPort $Port -State Listen -ErrorAction SilentlyContinue) { throw "La porta $Port è occupata da un altro processo." } # Parametri imposti lato server, così nessun client può dimenticarli (misurati il 2026-09-26): # - reasoning off: altrimenti ogni risposta parte con centinaia di token di ragionamento (~7 s) # - temp 0.3: col default del GGUF (1.0) il modello 1-bit scivola in spagnolo/inglese # - 1 solo slot: 4 slot (default) sprecano VRAM e spingono strati sulla CPU (40 -> 14 tok/s) # - CORS solo localhost: nessun sito web aperto nel browser può comandare l'IA $llamaArgs = @( '-m', "`"$model`"", '-c', $Context, '-np', '1', '--host', '127.0.0.1', '--port', $Port, '--cors-origins', 'localhost', '--jinja', '--no-webui', '--reasoning', 'off', '--temp', '0.3', '--top-p', '0.95', '--top-k', '20' ) $llamaArgs += if ($LowVram) { @('--fit', 'on') } else { @('-ngl', '99') } if (-not $NoVision) { $llamaArgs += @('--mmproj', "`"$mmproj`"") } $restarts = 0 do { $p = Start-Process -FilePath $server -ArgumentList $llamaArgs -NoNewWindow -PassThru $null = $p.Handle # senza questo, in PowerShell 5.1 ExitCode resta vuoto $p.WaitForExit() if (-not $Supervise) { exit $p.ExitCode } $restarts++ $delay = [math]::Min(60, 2 * $restarts) Write-Warning "llama-server terminato (codice $($p.ExitCode)). Riavvio #$restarts tra $delay s." Start-Sleep -Seconds $delay } while ($true)