Recipes

Docs to llm.txt

어떤 문서 사이트든 단일 LLM-ready Markdown 파일로 변환

전체 문서 사이트를 하나의 llm.txt로 디스틸하여 어떤 LLM 컨텍스트, RAG 파이프라인, 또는 로컬 모델에든 붙여넣을 수 있습니다. 익숙하지 않은 라이브러리, 사내 위키, 제품 문서에 유용합니다.

흐름

  1. include: ["links"]로 인덱스 페이지를 Distill 하여 모든 링크된 URL 발견
  2. URL 패턴으로 링크 목록 필터링 (예: /docs/, /guide/)
  3. 필터링된 URL을 /batch/distill에 전달
  4. 결과 Markdown을 단일 파일로 연결

구현

import httpx, re

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

# 1. Pull the index page + outbound links
index = httpx.post(f"{API}/distill",
                   headers=H,
                   json={"url": "https://docs.example.com",
                         "include": ["links"]}).json()["data"]

# 2. Filter to docs paths
doc_urls = [u for u in index["links"] if re.search(r"/docs/", u)]

# 3. Batch distill
job = httpx.post(f"{API}/batch/distill",
                 headers=H,
                 json={"urls": doc_urls}).json()["data"]

# 4. Poll, concatenate
# (poll loop omitted; see RAG Knowledge Base recipe)

with open("llm.txt", "w") as f:
    for r in job["results"]:
        if r["status"] == "SUCCEEDED":
            f.write(f"# {r['url']}\n\n{r['markdown']}\n\n---\n\n")

  • 크기 상한을 추가하세요 — llm.txt가 ~1 MB를 초과하면 토큰 예산을 부풀리기 시작합니다
  • 실행 간 안정적인 diff를 위해 URL 또는 섹션별로 정렬하세요
  • CI 작업과 함께 사용하여 원본 문서가 변경될 때 llm.txt를 최신 상태로 유지하세요

관련 문서

이 레시피는 청킹 및 중복 제거 전략으로 확장 중입니다 — 곧 업데이트됩니다.