59 lines
2.6 KiB
PowerShell
59 lines
2.6 KiB
PowerShell
[CmdletBinding()]
|
||
param(
|
||
[string]$LayaRoot = 'E:\LayaAI',
|
||
[switch]$AllowUncalibrated,
|
||
[switch]$CheckOnly
|
||
)
|
||
$ErrorActionPreference = 'Stop'
|
||
$repoRoot = Split-Path -Parent $PSScriptRoot
|
||
$env:SOPHELPER_VISION_PROVIDER = 'laya'
|
||
$env:SOPHELPER_VISION_ENDPOINT = 'http://127.0.0.1:8000/v1/vision/decide'
|
||
$env:SOPHELPER_LAYA_ALLOW_UNCALIBRATED = if ($AllowUncalibrated) { 'true' } else { 'false' }
|
||
|
||
function Get-VisionHealth {
|
||
try {
|
||
$health = Invoke-RestMethod -Uri 'http://127.0.0.1:8000/health/vision' -TimeoutSec 3
|
||
if ($health.status -eq 'ok' -and $health.model -eq 'vega-U/Qwen3.5-0.8B') { return $health }
|
||
} catch { }
|
||
return $null
|
||
}
|
||
|
||
$health = Get-VisionHealth
|
||
if ($null -eq $health) {
|
||
$python = Join-Path $LayaRoot '.venv\Scripts\python.exe'
|
||
$server = Join-Path $LayaRoot 'server.py'
|
||
if (!(Test-Path -LiteralPath $python) -or !(Test-Path -LiteralPath $server)) {
|
||
throw "Laya 服务文件缺失:$LayaRoot"
|
||
}
|
||
$logs = Join-Path $repoRoot 'artifacts\laya-integration'
|
||
New-Item -ItemType Directory -Path $logs -Force | Out-Null
|
||
$stamp = Get-Date -Format 'yyyyMMdd-HHmmss-fff'
|
||
$process = Start-Process -FilePath $python -ArgumentList @('-u', ('"' + $server + '"')) `
|
||
-WorkingDirectory $LayaRoot -WindowStyle Hidden -PassThru `
|
||
-RedirectStandardOutput (Join-Path $logs "$stamp.stdout.log") `
|
||
-RedirectStandardError (Join-Path $logs "$stamp.stderr.log")
|
||
# 与 Laya 自带 stop.bat/stop.ps1 共享运行时 PID 记录。
|
||
Set-Content -LiteralPath (Join-Path $LayaRoot 'server.pid') -Value $process.Id -Encoding ascii
|
||
Write-Host "正在启动 Laya 服务,PID=$($process.Id),日志:$logs"
|
||
$deadline = [DateTime]::UtcNow.AddSeconds(120)
|
||
do {
|
||
$health = Get-VisionHealth
|
||
if ($null -ne $health) { break }
|
||
if ($process.HasExited) { throw "Laya 启动失败,请查看 $logs" }
|
||
Start-Sleep -Milliseconds 500
|
||
} while ([DateTime]::UtcNow -lt $deadline)
|
||
if ($null -eq $health) { throw "等待 Laya 就绪超时,请查看 $logs" }
|
||
}
|
||
Write-Host "Laya 视觉接口已就绪,模型:$($health.model),已加载:$($health.loaded)"
|
||
if ($AllowUncalibrated) {
|
||
Write-Host '当前使用未标定工位实验模式;模型拒答或结果无界时仍不会推进步骤。'
|
||
} else {
|
||
Write-Host '当前保留模型复核状态,未标定 review 结果不会自动推进步骤。'
|
||
}
|
||
if ($CheckOnly) { return }
|
||
Push-Location $repoRoot
|
||
try {
|
||
& dotnet run --project src/SopHelper.Avalonia -p:BundlePythonRuntime=false
|
||
if ($LASTEXITCODE -ne 0) { throw "SOP 程序退出,代码:$LASTEXITCODE" }
|
||
} finally { Pop-Location }
|