- Offline neural worker based on llama.cpp (fortune-engine.exe) with local Qwen3-4B model support - Native assembly Tarot 3-card spread divination and teacher grade divination mode - Text input dialog in MODE_FORTUNE communicating over anonymous pipes - Clean process lifecycle management, WM_CHAR dispatch and fallback handling - Test suites and packaging tools for offline release
48 lines
2.8 KiB
PowerShell
48 lines
2.8 KiB
PowerShell
param([switch]$DownloadModel, [string]$Cmake = '')
|
|
$ErrorActionPreference = 'Stop'
|
|
$root = (Resolve-Path (Join-Path $PSScriptRoot '../..')).Path
|
|
Push-Location $root
|
|
try {
|
|
$manifest = Get-Content ai/model.json -Raw | ConvertFrom-Json
|
|
$vendor = Join-Path $root 'tools/vendor/llama.cpp'
|
|
if (!(Test-Path -LiteralPath (Join-Path $vendor '.git'))) {
|
|
& git clone --depth 1 https://github.com/ggml-org/llama.cpp.git $vendor
|
|
if ($LASTEXITCODE -ne 0) { throw 'Cannot obtain the inference source' }
|
|
}
|
|
$revision = & git -C $vendor rev-parse HEAD
|
|
if ($revision -ne $manifest.llama_commit) {
|
|
& git -C $vendor fetch --depth 1 origin $manifest.llama_commit
|
|
if ($LASTEXITCODE -ne 0) { throw 'Cannot obtain pinned inference source' }
|
|
& git -C $vendor checkout --detach $manifest.llama_commit
|
|
if ($LASTEXITCODE -ne 0) { throw 'Cannot select pinned inference source' }
|
|
}
|
|
if (!$Cmake) {
|
|
$local = Join-Path $root 'tools/vendor/python/cmake/data/bin/cmake.exe'
|
|
if (Test-Path -LiteralPath $local) { $Cmake = $local }
|
|
else { $Cmake = (Get-Command cmake -ErrorAction Stop).Source }
|
|
}
|
|
$env:VSLANG = '1033'
|
|
& $Cmake -S tools/fortune_ai -B build/fortune-ai -G 'Visual Studio 18 2026' -A x64
|
|
if ($LASTEXITCODE -ne 0) { throw 'Inference configuration failed' }
|
|
& $Cmake --build build/fortune-ai --config Release --target fortune-engine --parallel 8 -- /p:UseStructuredOutput=false
|
|
if ($LASTEXITCODE -ne 0) { throw 'Inference compilation failed' }
|
|
Copy-Item -LiteralPath build/fortune-ai/Release/fortune-engine.exe -Destination ai/fortune-engine.exe
|
|
New-Item -ItemType Directory -Force -Path ai/licenses,ai/models | Out-Null
|
|
Copy-Item -LiteralPath tools/vendor/llama.cpp/LICENSE -Destination ai/licenses/llama.cpp.txt
|
|
$model = Join-Path (Join-Path $root 'ai') $manifest.file
|
|
if ($DownloadModel -and !(Test-Path -LiteralPath $model)) {
|
|
$url = "https://huggingface.co/$($manifest.source)/resolve/$($manifest.revision)/$($manifest.source_file)?download=true"
|
|
& curl.exe --fail --location --retry 2 --output "$model.part" $url
|
|
if ($LASTEXITCODE -ne 0) { throw 'Model download failed' }
|
|
if ((Get-FileHash -LiteralPath "$model.part" -Algorithm SHA256).Hash -ne $manifest.sha256) {
|
|
throw 'Model checksum mismatch; not publishing'
|
|
}
|
|
Move-Item -LiteralPath "$model.part" -Destination $model
|
|
}
|
|
if (!(Test-Path -LiteralPath $model)) { throw 'Distribution is incomplete: missing bundled model' }
|
|
if ((Get-Item -LiteralPath $model).Length -ne $manifest.bytes -or
|
|
(Get-FileHash -LiteralPath $model -Algorithm SHA256).Hash -ne $manifest.sha256) {
|
|
throw 'Bundled model integrity check failed'
|
|
}
|
|
Write-Output 'Built the offline x64 worker and verified the bundled model.'
|
|
} finally { Pop-Location }
|