-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathstart.ps1
More file actions
115 lines (103 loc) · 4.03 KB
/
Copy pathstart.ps1
File metadata and controls
115 lines (103 loc) · 4.03 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# ========================================
# TRPG Agent 一键启动脚本
# 用法: .\start.ps1
# ========================================
$ErrorActionPreference = "Stop"
$originalEncoding = [Console]::OutputEncoding
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
Write-Host "========================================" -ForegroundColor Cyan
Write-Host " TRPG Agent 启动器" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan
Write-Host ""
# 检查 Python
try {
$pythonVersion = python --version 2>&1
Write-Host "[✓] $pythonVersion" -ForegroundColor Green
} catch {
Write-Host "[✗] 未找到 Python,请先安装 Python 3.13+" -ForegroundColor Red
Read-Host "按回车键退出"
exit 1
}
# 检查 Node.js
try {
$nodeVersion = node --version 2>&1
Write-Host "[✓] Node.js $nodeVersion" -ForegroundColor Green
} catch {
Write-Host "[提示] 未找到 Node.js,尝试自动安装..." -ForegroundColor Yellow
$winget = Get-Command winget -ErrorAction SilentlyContinue
if ($winget) {
Write-Host "正在通过 winget 安装 Node.js LTS..." -ForegroundColor Cyan
winget install OpenJS.NodeJS.LTS --silent --accept-package-agreements --accept-source-agreements
if ($LASTEXITCODE -eq 0) {
Write-Host "[✓] Node.js 安装成功,请重新运行此脚本" -ForegroundColor Green
} else {
Write-Host "[✗] Node.js 安装失败,请手动安装: https://nodejs.org" -ForegroundColor Red
}
} else {
Write-Host "[✗] 未找到 Node.js 且 winget 不可用,请手动安装: https://nodejs.org" -ForegroundColor Red
}
Read-Host "按回车键退出"
exit 1
}
# 从 .env 文件加载 API Key(如果环境变量未设置)
if ((-not $env:DEEPSEEK_API_KEY) -and (Test-Path ".env")) {
Get-Content ".env" | ForEach-Object {
if ($_ -match '^\s*DEEPSEEK_API_KEY\s*=\s*(.+)\s*$') {
$env:DEEPSEEK_API_KEY = $matches[1].Trim()
}
}
}
# 检查 API Key
if (-not $env:DEEPSEEK_API_KEY) {
Write-Host "[提示] 未设置 DEEPSEEK_API_KEY,请在 .env 文件中配置或设置环境变量" -ForegroundColor Yellow
$apiKey = Read-Host "请输入你的 DeepSeek API Key"
if (-not $apiKey) {
Write-Host "[错误] API Key 不能为空" -ForegroundColor Red
Read-Host "按回车键退出"
exit 1
}
$env:DEEPSEEK_API_KEY = $apiKey
Write-Host "[✓] API Key 已设置(本次会话有效)" -ForegroundColor Green
} else {
Write-Host "[✓] DEEPSEEK_API_KEY 已设置" -ForegroundColor Green
}
Write-Host ""
# 安装 Python 依赖
Write-Host "[1/4] 安装 Python 依赖..." -ForegroundColor Cyan
try {
pip install fastapi uvicorn -q 2>$null
Write-Host "[✓] Python 依赖就绪" -ForegroundColor Green
} catch {
Write-Host "[!] Python 依赖安装失败,将继续启动..." -ForegroundColor Yellow
}
# 安装前端依赖
Write-Host "[2/4] 安装前端依赖..." -ForegroundColor Cyan
Push-Location web
try {
npm install --silent 2>$null
Write-Host "[✓] 前端依赖就绪" -ForegroundColor Green
} catch {
Write-Host "[!] 前端依赖安装失败,将继续启动..." -ForegroundColor Yellow
}
Pop-Location
# 构建前端
Write-Host "[3/4] 构建前端..." -ForegroundColor Cyan
Push-Location web
try {
npm run build 2>$null | Out-Null
Write-Host "[✓] 前端构建完成" -ForegroundColor Green
} catch {
Write-Host "[!] 前端构建失败,请手动运行 'cd web && npm run build'" -ForegroundColor Yellow
}
Pop-Location
# 启动服务
Write-Host ""
Write-Host "[4/4] 启动服务..." -ForegroundColor Cyan
Write-Host ""
Write-Host "========================================" -ForegroundColor Green
Write-Host " 浏览器打开: http://localhost:8000" -ForegroundColor Green
Write-Host " 按 Ctrl+C 可停止服务" -ForegroundColor Green
Write-Host "========================================" -ForegroundColor Green
Write-Host ""
$env:HF_ENDPOINT = "https://hf-mirror.com"
python -m trpg_agent.api_server