feat(crawler): add pixelrag visual evidence lane
Some checks failed
CD Pipeline / deploy (push) Has been cancelled
Some checks failed
CD Pipeline / deploy (push) Has been cancelled
This commit is contained in:
122
scripts/ops/report_pixelrag_crawler_integration.py
Normal file
122
scripts/ops/report_pixelrag_crawler_integration.py
Normal file
@@ -0,0 +1,122 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Report PixelRAG-style crawler integration readiness."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import json
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
if str(ROOT) not in sys.path:
|
||||
sys.path.insert(0, str(ROOT))
|
||||
|
||||
from services.pixelrag_crawler_integration_service import ( # noqa: E402
|
||||
build_pixelrag_crawler_integration_assessment,
|
||||
build_pixelrag_visual_evidence_manifest,
|
||||
)
|
||||
|
||||
|
||||
CAPABILITY_FLAGS = {
|
||||
"no_playwright": ("playwright_artifact_pipeline", False),
|
||||
"ollama_multimodal_ready": ("ollama_multimodal_embedding_ready", True),
|
||||
"pgvector_visual_ready": ("pgvector_visual_index_ready", True),
|
||||
"faiss_allowed": ("faiss_allowed_in_production", True),
|
||||
}
|
||||
|
||||
|
||||
def _size_arg(value: str) -> dict[str, int | str]:
|
||||
try:
|
||||
name, size = value.split("=", 1)
|
||||
except ValueError:
|
||||
name, size = "", value
|
||||
try:
|
||||
width_text, height_text = size.lower().split("x", 1)
|
||||
width = int(width_text)
|
||||
height = int(height_text)
|
||||
except (ValueError, TypeError):
|
||||
raise argparse.ArgumentTypeError("size must be name=WIDTHxHEIGHT or WIDTHxHEIGHT")
|
||||
payload: dict[str, int | str] = {"width": width, "height": height}
|
||||
if name:
|
||||
payload["name"] = name
|
||||
return payload
|
||||
|
||||
|
||||
def main() -> int:
|
||||
parser = argparse.ArgumentParser(
|
||||
description="輸出 PixelRAG 導入現有爬蟲解決方案的機器可讀評估。"
|
||||
)
|
||||
parser.add_argument(
|
||||
"--platform",
|
||||
action="append",
|
||||
dest="platforms",
|
||||
help="限制目標平台,可重複指定;預設 momo + pchome。",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--capability",
|
||||
action="append",
|
||||
choices=sorted(CAPABILITY_FLAGS),
|
||||
default=[],
|
||||
help="覆寫 readiness 假設,用於模擬下一階段條件。",
|
||||
)
|
||||
parser.add_argument("--manifest-url", help="輸出單一 URL 的視覺證據 manifest。")
|
||||
parser.add_argument("--crawler", default="crawler_diagnostics", help="manifest 來源 crawler 名稱。")
|
||||
parser.add_argument(
|
||||
"--trigger-reason",
|
||||
default="parser_empty_or_low_confidence",
|
||||
help="啟動視覺 fallback 的原因。",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--evidence-intent",
|
||||
default="recover_visual_offer_evidence",
|
||||
help="視覺證據用途。",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--viewport",
|
||||
type=_size_arg,
|
||||
help="viewport,例如 desktop-1440=1440x950。",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--page-size",
|
||||
type=_size_arg,
|
||||
help="預估頁面尺寸,例如 page=1440x1900。",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--tile-size",
|
||||
type=_size_arg,
|
||||
help="tile 尺寸,例如 tile=512x512。",
|
||||
)
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.manifest_url:
|
||||
platform = (args.platforms or ["momo"])[0]
|
||||
payload = build_pixelrag_visual_evidence_manifest(
|
||||
url=args.manifest_url,
|
||||
platform=platform,
|
||||
crawler=args.crawler,
|
||||
trigger_reason=args.trigger_reason,
|
||||
evidence_intent=args.evidence_intent,
|
||||
viewport=args.viewport,
|
||||
page_size=args.page_size,
|
||||
tile_size=args.tile_size,
|
||||
)
|
||||
print(json.dumps(payload, ensure_ascii=False, indent=2, sort_keys=True))
|
||||
return 0 if payload.get("success") else 1
|
||||
|
||||
capabilities = {
|
||||
key: value
|
||||
for flag in args.capability
|
||||
for key, value in [CAPABILITY_FLAGS[flag]]
|
||||
}
|
||||
payload = build_pixelrag_crawler_integration_assessment(
|
||||
capabilities=capabilities or None,
|
||||
target_platforms=tuple(args.platforms) if args.platforms else None,
|
||||
)
|
||||
print(json.dumps(payload, ensure_ascii=False, indent=2, sort_keys=True))
|
||||
return 0 if payload.get("success") else 1
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
Reference in New Issue
Block a user