레시피

뉴스 애그리게이터

두 번의 batch pass로 여러 뉴스 소스의 헤드라인 집계

2-pass 설계: 각 소스의 홈페이지를 Distill 하여 기사 URL을 발견한 다음, 해당 URL에서 구조화된 헤드라인 레코드를 Extract 합니다.

흐름

  1. Pass 1 — 각 소스 홈페이지에 /batch/distillinclude: ["links"]와 함께 실행
  2. 발견된 링크를 패턴 (예: 오늘 날짜, 기사 경로) 으로 필터링
  3. Pass 2 — 필터링된 URL에 헤드라인 스키마와 함께 /batch/extract 실행
  4. 두 pass가 모두 완료되면 Webhook 발사. 스토어에 수집

스키마

{
  "type": "object",
  "properties": {
    "title":       { "type": "string", "description": "The article headline" },
    "url":         { "type": "string", "description": "Canonical article URL" },
    "publishedAt": { "type": "string", "description": "ISO-8601 publish timestamp" },
    "summary":     { "type": "string", "description": "1-2 sentence summary" }
  },
  "required": ["title", "url"]
}

구현 스케치

import httpx

API = "https://openapi.thunderbit.com/openapi/v1"
H = {"Authorization": "Bearer YOUR_API_KEY"}

# Pass 1: distill homepages, collect article URLs
sources = ["https://news.example.com", "https://blog.example.org"]
home_job = httpx.post(f"{API}/batch/distill",
                      headers=H,
                      json={"urls": sources, "include": ["links"]}).json()
# (poll until COMPLETED — see Batch Job Lifecycle guide)

article_urls = []
for r in home_job["data"]["results"]:
    if r["status"] == "SUCCEEDED":
        article_urls += [u for u in r["links"] if "/article/" in u]

# Pass 2: extract structured headlines
extract_job = httpx.post(f"{API}/batch/extract",
                         headers=H,
                         json={"urls": article_urls, "schema": SCHEMA}).json()

  • 동일한 헤드라인에 크레딧을 낭비하지 않도록 홈페이지 결과를 캐시하세요 (5-10분 TTL)
  • 소스가 IP로 홈페이지를 현지화하는 경우 countryCode를 설정하세요
  • canonical URL 또는 콘텐츠 해시로 중복 제거하세요 — 동일한 헤드라인이 여러 소스에 자주 나타납니다

관련 문서

이 레시피는 완전한 2-pass 오케스트레이터로 확장 중입니다 — 곧 업데이트됩니다.