Fix start.bat (ASCII-only, guaranteed window stays open) + add start.ps1
- start.bat: remove all Chinese characters (caused silent failure when Windows batch parser ran before chcp 65001 took effect); add :error label so window stays open with pause on any failure - start.ps1: PowerShell alternative launcher with coloured output, works without worrying about cmd.exe encoding issues Co-Authored-By: Claude Sonnet 4 <noreply@anthropic.com>
This commit is contained in:
102
start.bat
102
start.bat
@@ -1,99 +1,113 @@
|
||||
@echo off
|
||||
chcp 65001 >nul
|
||||
setlocal enabledelayedexpansion
|
||||
setlocal
|
||||
|
||||
echo.
|
||||
echo ============================================================
|
||||
echo Siemens RAGAS 评估控制台 启动脚本
|
||||
echo Siemens RAGAS Console - Starting...
|
||||
echo ============================================================
|
||||
echo.
|
||||
|
||||
:: ---- 切换到脚本所在目录(即 siemens_ragas/)-------------------
|
||||
:: Change to the directory where this script lives (siemens_ragas/)
|
||||
cd /d "%~dp0"
|
||||
echo Working directory: %CD%
|
||||
echo.
|
||||
|
||||
:: ---- 检查 Python ---------------------------------------------------
|
||||
:: ----------------------------------------------------------------
|
||||
:: 1. Check Python
|
||||
:: ----------------------------------------------------------------
|
||||
python --version >nul 2>&1
|
||||
if errorlevel 1 (
|
||||
echo [错误] 未找到 Python,请确认已安装 Python 3.12+ 并加入 PATH。
|
||||
pause
|
||||
exit /b 1
|
||||
echo [ERROR] Python not found. Please install Python 3.12+ and add it to PATH.
|
||||
goto :error
|
||||
)
|
||||
for /f "tokens=*" %%v in ('python --version 2^>^&1') do set PY_VER=%%v
|
||||
echo [OK] %PY_VER%
|
||||
for /f "tokens=*" %%v in ('python --version 2^>^&1') do echo [OK] %%v
|
||||
|
||||
:: ---- 检查 FastAPI / uvicorn ---------------------------------------
|
||||
:: ----------------------------------------------------------------
|
||||
:: 2. Check FastAPI / uvicorn
|
||||
:: ----------------------------------------------------------------
|
||||
python -c "import fastapi, uvicorn" >nul 2>&1
|
||||
if errorlevel 1 (
|
||||
echo [提示] 正在安装 FastAPI 和 uvicorn...
|
||||
echo [INFO] Installing fastapi and uvicorn...
|
||||
pip install fastapi uvicorn --quiet
|
||||
if errorlevel 1 (
|
||||
echo [错误] 安装依赖失败,请手动运行: pip install fastapi uvicorn
|
||||
pause
|
||||
exit /b 1
|
||||
echo [ERROR] Failed to install fastapi/uvicorn.
|
||||
echo Run manually: pip install fastapi uvicorn
|
||||
goto :error
|
||||
)
|
||||
echo [OK] FastAPI / uvicorn 安装完成。
|
||||
echo [OK] fastapi and uvicorn installed.
|
||||
) else (
|
||||
echo [OK] FastAPI / uvicorn 已就绪。
|
||||
echo [OK] fastapi / uvicorn ready.
|
||||
)
|
||||
|
||||
:: ---- 检查 ragas 版本 ----------------------------------------------
|
||||
:: ----------------------------------------------------------------
|
||||
:: 3. Check ragas version
|
||||
:: ----------------------------------------------------------------
|
||||
python -c "import ragas; assert ragas.__version__ == '0.4.3', ragas.__version__" >nul 2>&1
|
||||
if errorlevel 1 (
|
||||
echo [提示] 正在安装 ragas==0.4.3(评估引擎依赖)...
|
||||
echo [INFO] Installing ragas==0.4.3 ...
|
||||
pip install "ragas==0.4.3" --quiet
|
||||
if errorlevel 1 (
|
||||
echo [警告] ragas 安装失败。
|
||||
echo 控制台仍可启动:报告看板可用,触发评估功能将显示错误。
|
||||
echo.
|
||||
echo [WARN] ragas install failed. Dashboard still works; evaluation trigger will show an error.
|
||||
) else (
|
||||
echo [OK] ragas 0.4.3 安装完成。
|
||||
echo [OK] ragas 0.4.3 installed.
|
||||
)
|
||||
) else (
|
||||
echo [OK] ragas 0.4.3 已就绪。
|
||||
echo [OK] ragas 0.4.3 ready.
|
||||
)
|
||||
|
||||
:: ---- 检查是否有示例数据,没有则自动生成 ---------------------------
|
||||
set SAMPLE_META=outputs\kba-knowledge-base-offline-baseline\2026-06-15T08-30-00+00-00\metadata.json
|
||||
if not exist "%SAMPLE_META%" (
|
||||
echo [提示] 未找到示例运行数据,正在生成...
|
||||
:: ----------------------------------------------------------------
|
||||
:: 4. Seed demo data if no runs exist yet
|
||||
:: ----------------------------------------------------------------
|
||||
if not exist "outputs\kba-knowledge-base-offline-baseline" (
|
||||
echo [INFO] No run data found. Generating demo data...
|
||||
python scripts\seed_sample_run.py
|
||||
if errorlevel 1 (
|
||||
echo [警告] 示例数据生成失败,看板可能为空。继续启动...
|
||||
echo [WARN] Demo data generation failed. Dashboard may be empty.
|
||||
) else (
|
||||
echo [OK] 示例数据已生成。
|
||||
echo [OK] Demo data generated.
|
||||
)
|
||||
) else (
|
||||
echo [OK] 已有运行数据,跳过示例生成。
|
||||
echo [OK] Run data found, skipping demo generation.
|
||||
)
|
||||
|
||||
:: ---- 检查端口是否已占用 ------------------------------------------
|
||||
:: ----------------------------------------------------------------
|
||||
:: 5. Pick an available port
|
||||
:: ----------------------------------------------------------------
|
||||
set PORT=8800
|
||||
netstat -ano | findstr /r ":%PORT%[^0-9]" | findstr "LISTENING" >nul 2>&1
|
||||
netstat -ano 2>nul | findstr ":8800" | findstr "LISTENING" >nul 2>&1
|
||||
if not errorlevel 1 (
|
||||
echo [警告] 端口 %PORT% 已被占用,尝试使用 8801...
|
||||
echo [WARN] Port 8800 in use, trying 8801...
|
||||
set PORT=8801
|
||||
netstat -ano | findstr /r ":8801[^0-9]" | findstr "LISTENING" >nul 2>&1
|
||||
netstat -ano 2>nul | findstr ":8801" | findstr "LISTENING" >nul 2>&1
|
||||
if not errorlevel 1 (
|
||||
echo [错误] 端口 8800 和 8801 均被占用,请手动指定端口:
|
||||
echo python webmain.py --port ^<端口号^>
|
||||
pause
|
||||
exit /b 1
|
||||
echo [ERROR] Ports 8800 and 8801 are both in use.
|
||||
echo Run manually: python webmain.py --port 8802
|
||||
goto :error
|
||||
)
|
||||
)
|
||||
|
||||
echo.
|
||||
echo ============================================================
|
||||
echo 启动控制台:http://127.0.0.1:%PORT%
|
||||
echo 按 Ctrl+C 停止服务
|
||||
echo Console URL : http://127.0.0.1:%PORT%
|
||||
echo Press Ctrl+C to stop the server
|
||||
echo ============================================================
|
||||
echo.
|
||||
|
||||
:: ---- 稍等 1 秒后在默认浏览器打开页面 ----------------------------
|
||||
:: Open browser after 2-second delay (non-blocking)
|
||||
start /b cmd /c "timeout /t 2 >nul && start http://127.0.0.1:%PORT%"
|
||||
|
||||
:: ---- 启动 uvicorn -------------------------------------------------
|
||||
:: Launch uvicorn (blocking — window stays open while server runs)
|
||||
python webmain.py --host 127.0.0.1 --port %PORT%
|
||||
|
||||
echo.
|
||||
echo 服务已停止。
|
||||
echo Server stopped.
|
||||
pause
|
||||
exit /b 0
|
||||
|
||||
:error
|
||||
echo.
|
||||
echo ============================================================
|
||||
echo Startup failed. See error above.
|
||||
echo ============================================================
|
||||
pause
|
||||
exit /b 1
|
||||
|
||||
111
start.ps1
Normal file
111
start.ps1
Normal file
@@ -0,0 +1,111 @@
|
||||
# start.ps1 — Siemens RAGAS Console launcher for Windows PowerShell
|
||||
# Usage: Right-click -> "Run with PowerShell", or: powershell -ExecutionPolicy Bypass -File start.ps1
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
Set-Location $PSScriptRoot
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "============================================================" -ForegroundColor Cyan
|
||||
Write-Host " Siemens RAGAS Console - Starting..." -ForegroundColor Cyan
|
||||
Write-Host "============================================================" -ForegroundColor Cyan
|
||||
Write-Host ""
|
||||
Write-Host "Working directory: $PSScriptRoot"
|
||||
Write-Host ""
|
||||
|
||||
# ----------------------------------------------------------------
|
||||
# 1. Check Python
|
||||
# ----------------------------------------------------------------
|
||||
try {
|
||||
$pyver = & python --version 2>&1
|
||||
Write-Host "[OK] $pyver" -ForegroundColor Green
|
||||
} catch {
|
||||
Write-Host "[ERROR] Python not found. Please install Python 3.12+ and add to PATH." -ForegroundColor Red
|
||||
Read-Host "Press Enter to exit"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# ----------------------------------------------------------------
|
||||
# 2. Check FastAPI / uvicorn
|
||||
# ----------------------------------------------------------------
|
||||
$check = & python -c "import fastapi, uvicorn" 2>&1
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
Write-Host "[INFO] Installing fastapi and uvicorn..." -ForegroundColor Yellow
|
||||
& pip install fastapi uvicorn --quiet
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
Write-Host "[ERROR] Failed to install fastapi/uvicorn. Run: pip install fastapi uvicorn" -ForegroundColor Red
|
||||
Read-Host "Press Enter to exit"
|
||||
exit 1
|
||||
}
|
||||
Write-Host "[OK] fastapi / uvicorn installed." -ForegroundColor Green
|
||||
} else {
|
||||
Write-Host "[OK] fastapi / uvicorn ready." -ForegroundColor Green
|
||||
}
|
||||
|
||||
# ----------------------------------------------------------------
|
||||
# 3. Check ragas version
|
||||
# ----------------------------------------------------------------
|
||||
$check = & python -c "import ragas; assert ragas.__version__ == '0.4.3', ragas.__version__" 2>&1
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
Write-Host "[INFO] Installing ragas==0.4.3 (evaluation engine)..." -ForegroundColor Yellow
|
||||
& pip install "ragas==0.4.3" --quiet
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
Write-Host "[WARN] ragas install failed. Dashboard works; evaluation trigger will show error." -ForegroundColor Yellow
|
||||
} else {
|
||||
Write-Host "[OK] ragas 0.4.3 installed." -ForegroundColor Green
|
||||
}
|
||||
} else {
|
||||
Write-Host "[OK] ragas 0.4.3 ready." -ForegroundColor Green
|
||||
}
|
||||
|
||||
# ----------------------------------------------------------------
|
||||
# 4. Seed demo data if missing
|
||||
# ----------------------------------------------------------------
|
||||
if (-not (Test-Path "outputs\kba-knowledge-base-offline-baseline")) {
|
||||
Write-Host "[INFO] No run data found. Generating demo data..." -ForegroundColor Yellow
|
||||
& python scripts\seed_sample_run.py
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
Write-Host "[WARN] Demo data generation failed. Dashboard may be empty." -ForegroundColor Yellow
|
||||
} else {
|
||||
Write-Host "[OK] Demo data generated." -ForegroundColor Green
|
||||
}
|
||||
} else {
|
||||
Write-Host "[OK] Run data found, skipping demo generation." -ForegroundColor Green
|
||||
}
|
||||
|
||||
# ----------------------------------------------------------------
|
||||
# 5. Pick an available port
|
||||
# ----------------------------------------------------------------
|
||||
$PORT = 8800
|
||||
$inUse = netstat -ano 2>$null | Select-String ":$PORT\s" | Select-String "LISTENING"
|
||||
if ($inUse) {
|
||||
Write-Host "[WARN] Port $PORT in use, trying 8801..." -ForegroundColor Yellow
|
||||
$PORT = 8801
|
||||
$inUse = netstat -ano 2>$null | Select-String ":$PORT\s" | Select-String "LISTENING"
|
||||
if ($inUse) {
|
||||
Write-Host "[ERROR] Ports 8800 and 8801 are both in use." -ForegroundColor Red
|
||||
Write-Host " Run manually: python webmain.py --port 8802"
|
||||
Read-Host "Press Enter to exit"
|
||||
exit 1
|
||||
}
|
||||
}
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "============================================================" -ForegroundColor Cyan
|
||||
Write-Host " Console URL : http://127.0.0.1:$PORT" -ForegroundColor Green
|
||||
Write-Host " Press Ctrl+C to stop the server" -ForegroundColor Cyan
|
||||
Write-Host "============================================================" -ForegroundColor Cyan
|
||||
Write-Host ""
|
||||
|
||||
# Open browser after 2-second delay
|
||||
Start-Job -ScriptBlock {
|
||||
param($port)
|
||||
Start-Sleep 2
|
||||
Start-Process "http://127.0.0.1:$port"
|
||||
} -ArgumentList $PORT | Out-Null
|
||||
|
||||
# Launch uvicorn (blocking)
|
||||
& python webmain.py --host 127.0.0.1 --port $PORT
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "Server stopped."
|
||||
Read-Host "Press Enter to exit"
|
||||
Reference in New Issue
Block a user