Files
Genarrative/view-llm-logs.ps1
2026-04-16 15:45:00 +08:00

43 lines
2.2 KiB
PowerShell

# LLM 日志查看脚本
# 使用方法:右键点击此文件 -> "使用 PowerShell 运行"
$LogDir = "E:\Repos\Genarrative\server-node\logs"
$TodayLog = Get-ChildItem $LogDir -Filter "server.log.*.1" | Sort-Object LastWriteTime -Descending | Select-Object -First 1
if ($TodayLog) {
Write-Host "正在监控日志文件: $($TodayLog.FullName)" -ForegroundColor Green
Write-Host "按 Ctrl+C 退出" -ForegroundColor Yellow
Write-Host ""
Write-Host "=== 只显示 LLM 调试日志 ===" -ForegroundColor Cyan
Write-Host ""
Get-Content $TodayLog.FullName -Wait -Tail 20 | Where-Object { $_ -match "LLM_DEBUG" } | ForEach-Object {
# 尝试解析 JSON 并美化输出
try {
$json = $_ | ConvertFrom-Json
if ($json.msg -eq "[LLM_DEBUG] Request prompt") {
Write-Host "`n[请求 Prompt]" -ForegroundColor Yellow
Write-Host "时间: $($json.time)" -ForegroundColor Gray
Write-Host "标签: $($json.llm_debug_label)" -ForegroundColor Gray
Write-Host "模型: $($json.llm_model)" -ForegroundColor Gray
Write-Host "消息:" -ForegroundColor Gray
$json.llm_messages | ForEach-Object {
Write-Host " [$($_.role)]" -ForegroundColor Cyan
Write-Host " $($_.content.Substring(0, [Math]::Min(200, $_.content.Length)))..." -ForegroundColor White
}
} elseif ($json.msg -eq "[LLM_DEBUG] Response content") {
Write-Host "`n[响应内容]" -ForegroundColor Green
Write-Host "时间: $($json.time)" -ForegroundColor Gray
Write-Host "标签: $($json.llm_debug_label)" -ForegroundColor Gray
Write-Host "长度: $($json.llm_response_length) 字符" -ForegroundColor Gray
Write-Host "内容:" -ForegroundColor Gray
Write-Host " $($json.llm_response_content.Substring(0, [Math]::Min(500, $json.llm_response_content.Length)))..." -ForegroundColor White
}
} catch {
Write-Host $_ -ForegroundColor White
}
}
} else {
Write-Host "未找到日志文件" -ForegroundColor Red
}