新增功能: - execution_log 模块:自动记录引擎调用耗时、成功/失败、错误详情 - 所有搜索引擎自动跟踪每次调用的性能指标 - CLI 搜索后自动显示执行摘要 - health 命令使用 ParallelSearch 检测所有引擎连通性 - 新增 log 命令查看历史执行日志
91 lines
2.5 KiB
Python
91 lines
2.5 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
web-search-skills: Open-source diversified search in <5s.
|
|
|
|
Usage:
|
|
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 time
|
|
|
|
|
|
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()
|