통합

LangChain

LangChain 에이전트 안에서 Thunderbit를 Document loader 또는 Tool로 활용

Thunderbit를 LangChain 파이프라인에 Document loader(RAG 수집용) 또는 Tool(에이전트 주도 웹 리서치용)로 끼워 넣으세요.

설치

pip install langchain-core httpx

Document loader로 사용

from langchain_core.documents import Document
import httpx, time

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

class ThunderbitLoader:
    def __init__(self, urls: list[str]):
        self.urls = urls

    def load(self) -> list[Document]:
        # 1. submit batch — POST returns {id, status, total, ...}, no `results` yet
        job_id = httpx.post(f"{API}/batch/distill",
                            headers=H,
                            json={"urls": self.urls}).json()["data"]["id"]
        # 2. poll until terminal — see Batch Job Lifecycle guide
        while True:
            data = httpx.get(f"{API}/batch/distill/{job_id}", headers=H).json()["data"]
            if data["status"] in ("COMPLETED", "FAILED", "CANCELLED"):
                break
            time.sleep(5)
        # 3. read results from GET response (each item: {index, url, status, markdown, error})
        return [
            Document(page_content=r["markdown"], metadata={"source": r["url"]})
            for r in data.get("results", []) if r["status"] == "SUCCEEDED"
        ]

docs = ThunderbitLoader(["https://docs.example.com"]).load()

docs를 평소 사용하던 LangChain text splitter + vector store 로 흘려보내면 됩니다.

에이전트 Tool 로 사용

from langchain_core.tools import tool

@tool
def read_url(url: str) -> str:
    """Fetch a URL and return clean Markdown for the agent to read.

    Use for any web research task: docs, articles, search results, product pages.
    """
    resp = httpx.post(f"{API}/distill",
                      headers=H,
                      json={"url": url, "renderMode": "basic"},
                      timeout=60.0)
    resp.raise_for_status()
    return resp.json()["data"]["markdown"]

# Pass [read_url] into create_react_agent / AgentExecutor / etc.

관련 문서

이 통합은 langchain-thunderbit 패키지로 확장 중입니다 —— 곧 다시 확인하세요.