feat: 添加执行日志系统,跟踪各引擎/接口调用耗时和错误信息

新增功能:
- execution_log 模块:自动记录引擎调用耗时、成功/失败、错误详情
- 所有搜索引擎自动跟踪每次调用的性能指标
- CLI 搜索后自动显示执行摘要
- health 命令使用 ParallelSearch 检测所有引擎连通性
- 新增 log 命令查看历史执行日志
This commit is contained in:
openbot authored and GitHub committed 2026-05-21 14:50:34 +08:00
1 parent f2d8919860
commit a60ba71663
18 files changed
+1671 -332

No files matched your search

+79 -12
View File
@@ -1,23 +1,90 @@
#!/usr/bin/env python3
"""
Web Search Skills CLI entry point.
web-search-skills: Open-source diversified search in <5s.
Usage:
python ws.py <command> <query> [options]
Or install and run:
uv tool install -e .
ws <command> <query> [options]
python3 ws.py search <query> [--max-results 5]
python3 ws.py health
python3 ws.py serve # (future) MCP server mode
"""
from __future__ import annotations
import argparse
import asyncio
import json
import sys
import os
import time
# Ensure scripts package is importable
_SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
if _SCRIPT_DIR not in sys.path:
sys.path.insert(0, _SCRIPT_DIR)
from scripts.cli import main
async def cmd_search(args: argparse.Namespace):
from scripts.unified_search import UnifiedSearch
us = UnifiedSearch()
t0 = time.time()
resp = await us.search(args.query, max_results=args.max_results)
elapsed = time.time() - t0
if args.json:
output = {
"query": resp.query,
"sources": [
{
"index": s.index,
"title": s.title,
"url": s.url,
"source": s.source,
}
for s in resp.sources
],
"time_ms": elapsed * 1000,
}
print(json.dumps(output, ensure_ascii=False, indent=2))
else:
print(f"\n🔍 「{resp.query}」 — {elapsed:.2f}s")
print(f" {len(resp.sources)} results from {len(resp.metadata.engines_used)} engines\n")
for i, s in enumerate(resp.sources, 1):
print(f" {i}. [{s.source}] {s.title}")
print(f" {s.url}")
print()
await us.close()
async def cmd_health(args: argparse.Namespace):
from scripts.unified_search import UnifiedSearch
us = UnifiedSearch()
status = await us.health()
if args.json:
print(json.dumps(status, ensure_ascii=False, indent=2))
else:
print("📊 Search Health")
print(f" Status: {status.get('status', 'unknown')}")
print(f" Engines: {', '.join(status.get('engines', []))}")
await us.close()
def main():
parser = argparse.ArgumentParser(description="web-search-skills")
sub = parser.add_subparsers(dest="command", required=True)
# search
sp = sub.add_parser("search", help="Search across multiple sources")
sp.add_argument("query", help="Search query")
sp.add_argument("--max-results", type=int, default=5)
sp.add_argument("--json", action="store_true", help="JSON output")
# health
hp = sub.add_parser("health", help="Check engine health")
hp.add_argument("--json", action="store_true", help="JSON output")
args = parser.parse_args()
if args.command == "search":
asyncio.run(cmd_search(args))
elif args.command == "health":
asyncio.run(cmd_health(args))
if __name__ == "__main__":
main()