Repository navigation
Expand file tree
/
Copy pathstart.ps1
More file actions
64 lines (56 loc) · 3.12 KB
/
Copy pathstart.ps1
File metadata and controls
64 lines (56 loc) · 3.12 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
# 战国·多国 AI 对战 · 一键启动(Windows PowerShell)
# 需要机器上已有 Python 3.10+(py 启动器或 python 都行);依赖装进程序目录 .venv,不污染系统。
# 用法:
# .\start.ps1 # 读档续局(无档则新开)
# .\start.ps1 --new --turns 10 # 开新局跑 10 回合;Ctrl-C 存档退出
$ErrorActionPreference = "Stop"
Set-Location $PSScriptRoot
# 国内用户:pip 默认走清华镜像(离海外的用户可改)
$PipMirror = "https://pypi.tuna.tsinghua.edu.cn/simple"
# ---- 找 Python ----
$py = $null
foreach ($c in @("python", "py")) {
try { & $c --version *> $null; if ($LASTEXITCODE -eq 0) { $py = $c; break } } catch { }
}
if (-not $py) { Write-Host "[错误] 未找到 Python(需 3.10+),请先安装" -ForegroundColor Red; Read-Host "回车退出"; exit 1 }
if ($py -eq "py") { $py = @("py", "-3") }
$ConfigPath = "mp_config.json"
for ($index = 0; $index -lt $args.Count; $index++) {
if ($args[$index] -eq "--config" -and $index + 1 -lt $args.Count) { $ConfigPath = $args[$index + 1] }
elseif ($args[$index] -like "--config=*") { $ConfigPath = $args[$index].Substring(9) }
}
# ---- 配置:没有 mp_config.json 就从模板生成并提示填写 ----
if (-not (Test-Path $ConfigPath)) {
if ($ConfigPath -ne "mp_config.json") { throw "找不到配置 $ConfigPath" }
Copy-Item mp_config.example.json mp_config.json
Write-Host "[初始化] 已从模板生成 mp_config.json —— 请先填好每国的 base_url / api_key / model 再运行(provider 可选,只有 openai / anthropic 两种,缺省 openai)。" -ForegroundColor Yellow
Read-Host "回车退出"
exit 1
}
# ---- 虚拟环境:默认装在程序目录(.venv) ----
$venvPy = Join-Path $PSScriptRoot ".venv\Scripts\python.exe"
if (-not (Test-Path $venvPy)) {
Write-Host "[初始化] 创建虚拟环境 .venv(仅首次)…"
& $py -m venv .venv
}
# ---- 依赖(装进 .venv,缺才装) ----
& cmd.exe /c "`"$venvPy`" -c ""import openai"" >nul 2>&1"
if ($LASTEXITCODE -ne 0) {
Write-Host "[初始化] 安装依赖(清华镜像,版本由 requirements.txt 控制)…"
& $venvPy -m pip install -i $PipMirror --timeout 60 -r requirements.txt
if ($LASTEXITCODE -ne 0) {
Write-Host "[提示] 清华镜像拉取失败(网络/分流原因),改用官方源重试…"
& $venvPy -m pip install --timeout 60 -r requirements.txt
}
}
$StockConfig = Get-Content -Raw -LiteralPath $ConfigPath | ConvertFrom-Json
if ([System.IO.Path]::GetFileName([string]$StockConfig.mods) -eq "mods.stock.toml") {
& $venvPy -c "from importlib.metadata import version; import pams; assert version('pams') == '0.3.0'"
if ($LASTEXITCODE -ne 0) {
& $venvPy -m pip install -i $PipMirror --timeout 60 -r requirements-stock.txt
if ($LASTEXITCODE -ne 0) { & $venvPy -m pip install --timeout 60 -r requirements-stock.txt }
if ($LASTEXITCODE -ne 0) { throw "无法安装股票后端依赖" }
}
}
Write-Host "[启动] 战国·多国 AI 对战(看海模式:终端实时流 + mp_journal.md)…" -ForegroundColor Green
& $venvPy mp_run.py @args