28 lines
1.7 KiB
PowerShell
28 lines
1.7 KiB
PowerShell
# Bound the bundled llama-server prompt cache; preserve model and context size.
|
|
param([switch]$Restart)
|
|
$ErrorActionPreference='Stop'
|
|
$settings=@{LLAMA_ARG_CACHE_RAM='512';LLAMA_ARG_CTX_CHECKPOINTS='4'}
|
|
foreach($key in $settings.Keys){[Environment]::SetEnvironmentVariable($key,$settings[$key],'User');[Environment]::SetEnvironmentVariable($key,$settings[$key],'Process')}
|
|
$root=Join-Path $env:USERPROFILE 'Tools\AzerothAI'
|
|
$supervisor=Join-Path $root 'recovery.ps1'
|
|
if(Test-Path $supervisor){
|
|
$text=Get-Content -Raw $supervisor
|
|
if($text -notmatch 'LLAMA_ARG_CACHE_RAM'){
|
|
Copy-Item $supervisor "$supervisor.before-cache-limit" -Force
|
|
$prefix='$env:LLAMA_ARG_CACHE_RAM="512"; $env:LLAMA_ARG_CTX_CHECKPOINTS="4"'
|
|
Set-Content $supervisor ($prefix+"`r`n"+$text)
|
|
}
|
|
}
|
|
if($Restart){
|
|
$task=Get-ScheduledTask -TaskName 'AzerothAI-Recovery' -ErrorAction SilentlyContinue
|
|
if($task){Stop-ScheduledTask -InputObject $task}
|
|
try{Invoke-RestMethod -Method Post -Uri http://127.0.0.1:11434/api/generate -ContentType 'application/json' -Body '{"model":"qwen3.5:4b","keep_alive":0}' -TimeoutSec 45 | Out-Null}catch{Write-Warning $_.Exception.Message}
|
|
$binary=Join-Path $env:USERPROFILE 'Tools\Ollama\ollama.exe'
|
|
Get-Process ollama -ErrorAction SilentlyContinue | Where-Object {$_.Path -eq $binary} | Stop-Process
|
|
$logs=Split-Path $binary
|
|
foreach($file in @('server.out.log','server.err.log')){if(Test-Path "$logs\$file"){Copy-Item "$logs\$file" "$logs\$file.before-cache-limit" -Force}}
|
|
Start-Process $binary -ArgumentList 'serve' -WindowStyle Hidden -RedirectStandardOutput "$logs\server.out.log" -RedirectStandardError "$logs\server.err.log"
|
|
if($task){Start-ScheduledTask -InputObject $task}
|
|
}
|
|
Write-Output 'Prompt cache capped at 512 MiB; at most four context checkpoints per slot.'
|