-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.ps1
More file actions
76 lines (65 loc) · 2.85 KB
/
Copy pathstart.ps1
File metadata and controls
76 lines (65 loc) · 2.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# MRAG Enhanced NPC Simulator - 启动脚本
# 用法: powershell -ExecutionPolicy Bypass -File start.ps1
$Host.UI.RawUI.WindowTitle = "MRAG Enhanced NPC Simulator"
Write-Host ""
Write-Host " ╔══════════════════════════════════════════════╗" -ForegroundColor Cyan
Write-Host " ║ MRAG Enhanced NPC Simulator ║" -ForegroundColor Cyan
Write-Host " ║ 多层记忆增强型 NPC 行为模拟系统 ║" -ForegroundColor Cyan
Write-Host " ╚══════════════════════════════════════════════╝" -ForegroundColor Cyan
Write-Host ""
Set-Location $PSScriptRoot
# 检查 Python
if (-not (Get-Command python -ErrorAction SilentlyContinue)) {
Write-Host " [错误] 未找到 Python,请先安装 Python 3.10+" -ForegroundColor Red
Read-Host "按回车退出"
exit 1
}
Write-Host " [OK] Python 已就绪" -ForegroundColor Green
# 激活虚拟环境(如果存在)
if (Test-Path ".venv\Scripts\Activate.ps1") {
Write-Host " [*] 激活虚拟环境..." -ForegroundColor Yellow
& ".venv\Scripts\Activate.ps1"
}
# 检查关键依赖
python -c "import fastapi, uvicorn" 2>$null
if ($LASTEXITCODE -ne 0) {
Write-Host " [*] 安装依赖中,请稍候..." -ForegroundColor Yellow
pip install -r requirements.txt -q
if ($LASTEXITCODE -ne 0) {
Write-Host " [错误] 依赖安装失败,请手动运行: pip install -r requirements.txt" -ForegroundColor Red
Read-Host "按回车退出"
exit 1
}
Write-Host " [OK] 依赖安装完成" -ForegroundColor Green
} else {
Write-Host " [OK] 依赖已就绪" -ForegroundColor Green
}
# 检查 API 配置
if (Test-Path "api_config.json") {
$cfg = Get-Content "api_config.json" | ConvertFrom-Json
Write-Host " [OK] API 配置: $($cfg.provider) / $($cfg.model)" -ForegroundColor Green
} else {
Write-Host " [警告] 未找到 api_config.json,请在游戏内 '设置' 中配置 API Key" -ForegroundColor Yellow
}
# 自动选择可用端口(优先 8080,备选 8888、9000)
$port = 8080
foreach ($p in @(8080, 8888, 9000)) {
$inUse = netstat -ano | Select-String ":$p\s" | Select-String "LISTENING"
if (-not $inUse) {
$port = $p
break
}
}
Write-Host ""
Write-Host " [*] 启动服务器(端口 $port)..." -ForegroundColor Cyan
Write-Host " [*] 访问地址: http://localhost:$port" -ForegroundColor White
Write-Host " [*] 按 Ctrl+C 停止服务" -ForegroundColor White
Write-Host ""
# 延迟2秒后打开浏览器
Start-Job -ScriptBlock {
param($p)
Start-Sleep 2
Start-Process "http://localhost:$p"
} -ArgumentList $port | Out-Null
# 启动 FastAPI 服务
python -m uvicorn backend.api_server:app --host 127.0.0.1 --port $port --reload