ergo-agentic-langfuse-retest / scripts /test_image_analyzer.py
1zero24's picture
Upload latest hosted langfuse retest snapshot
290ff9e verified
Raw
History Blame Contribute Delete
1.61 kB
"""Smoke test for the Image Analyzer node.
Runs the analyzer on the sample images from datasources/report-sample.json
using the real API. Requires ANTHROPIC_API_KEY (or whichever provider is
configured in the default model config).
Usage:
uv run python scripts/test_image_analyzer.py
"""
from __future__ import annotations
import json
import sys
from pathlib import Path
from dotenv import load_dotenv
REPORT_SAMPLE_FILE = (
Path(__file__).resolve().parents[1] / "docs" / "datasources" / "report-sample.json"
)
from ergo_agentic.nodes.image_analyzer import analyze_image
from ergo_agentic.state import ImageInput
def main() -> int:
load_dotenv()
with REPORT_SAMPLE_FILE.open() as f:
report = json.load(f)
urls = report.get("uploadedImages", [])
if not urls:
print("No images in sample report", file=sys.stderr)
return 1
print(f"Analyzing {len(urls)} images sequentially...\n")
for i, url in enumerate(urls, start=1):
image: ImageInput = {
"image_id": f"img_{i}",
"url": url,
"label": None,
}
print(f"--- Image {i}: {url} ---")
try:
result = analyze_image(
{"image": image, "model_id": "google_genai:gemini-2.5-flash"}
)
manifest = result["image_manifests"][0]
print(manifest.model_dump_json(indent=2))
except Exception as e:
print(f"ERROR: {e}")
print()
return 0
if __name__ == "__main__":
sys.exit(main())