n8n에서 LLM Chains vs Single Calls: 나의 캡션 생성 실험
발행: (2026년 2월 8일 오전 01:00 GMT+9)
5 분 소요
원문: Dev.to
Source: Dev.to
번역을 진행하려면 원본 텍스트(코드 블록, URL 등을 제외한 본문)를 제공해 주시겠어요? 텍스트를 주시면 그대로 한국어로 번역해 드리겠습니다.
두 가지 접근법
접근법 A: 3‑단계 체인 (하이쿠)
작업을 마이크로‑스텝으로 나눕니다:
- 데이터에서 핵심 포인트 추출.
- 1단계 출력물을 사용해 구조 초안 작성.
- 다듬고 메타데이터 추가 (해시태그, CTA 등).
접근법 B: 소네트 단일 호출
전체 프롬프트를 더 능력 있는 모델에 한 번에 보내어 전체 흐름을 처리하게 합니다.
테스트 스크립트 (n8n 외부)
# Setup
npm init -y
npm i @anthropic-ai/sdk dotenv
export ANTHROPIC_API_KEY="your_key_here"
index.mjs
import "dotenv/config";
import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic({ apiKey: process.env.ANTHROPIC_API_KEY });
// Sample data structure
const image_details = [
{ order: 1, attributeA: "value1", attributeB: "value2" },
{ order: 2, attributeA: "value3", attributeB: "value4" },
];
async function callClaude({ model, system, prompt }) {
const res = await client.messages.create({
model,
max_tokens: 1000,
system,
messages: [{ role: "user", content: prompt }],
});
return res.content?.text ?? "";
}
// Approach A: Haiku 3‑step chain
async function haikuChain() {
const model = "claude-haiku-4-5";
const system = "You are a caption editor. Be concise.";
// Step 1: Extract data
const step1 = await callClaude({
model,
system,
prompt: `Extract key descriptions from this data:\n${JSON.stringify({ image_details }, null, 2)}`,
});
// Step 2: Create structure
const step2 = await callClaude({
model,
system,
prompt: `Based on this, create hook + body + CTA:\n${step1}`,
});
// Step 3: Add tags
const step3 = await callClaude({
model,
system,
prompt: `Add hashtags to this caption:\n${step2}`,
});
return { step1, step2, final: step3 };
}
// Approach B: Sonnet single call
async function sonnetSingle() {
const model = "claude-sonnet-4-5";
const system = "You are a caption editor. Be concise.";
return await callClaude({
model,
system,
prompt: `Create a complete caption (hook + body + bullets + CTA + tags) from:\n${JSON.stringify({ image_details }, null, 2)}`,
});
}
// Run both
const resultA = await haikuChain();
const resultB = await sonnetSingle();
console.log("=== Haiku Chain ===\n", resultA.final);
console.log("\n=== Sonnet Single ===\n", resultB);
n8n 코드 노드에서 데이터 준비하기
// Wrong: LLM can't work with IDs alone
const image_details = transformedImages.map(img => ({ id: img.id }));
// Right: Provide the full content the LLM needs
const image_details = transformedImages.map((img, index) => ({
order: index + 1,
...img, // Spread ALL attributes the LLM needs
}));
return [{ json: { image_details } }];
근본 원인: 이미지 ID만 전달되어 모델이 설명적인 컨텍스트를 전혀 갖지 못함.
해결책: 전체 객체(...img)를 펼쳐서 LLM이 모든 관련 속성을 받도록 함.
메트릭 비교
| 지표 | Haiku 3‑Chain | Sonnet Single |
|---|---|---|
| 맥락 인식 | 단계 사이의 조각 | 전체적인 이해 |
| 톤 일관성 | 조합했지만 고르지 않음 | 시작부터 끝까지 통일됨 |
| 출력 품질 | 정보는 풍부하지만 딱딱함 | 자연스럽고, 흥미로우며, 흐름이 좋음 |
| 비용 | ~3배 저렴 | 비용은 높지만 가치 있음 |
판단: 캡션(또는 모든 창작 글쓰기)에서는 맥락 연속성이 약간의 비용 절감보다 더 중요합니다.
패턴 및 사용‑케이스 안내
| Pattern | Use Case | Examples |
|---|---|---|
| Lower‑model + Chain | 역할 분리가 명확함 | 데이터 추출, 분류, 포맷팅 |
| Mid/upper‑model + Single | 맥락에 의존하는 창의성 | 캡션, 기사, 카피라이팅 |
Key takeaways:
- Context > Cost: 파편화된 체인은 창의적 작업에서 서사 흐름을 방해합니다.
- Data quality matters: 풍부한 정보를 제공하는 것이 필수이며, 체인 방식은 누락된 맥락을 보완할 수 없습니다.
- Haiku’s niche: 속도와 고도로 구조화된 작업에 뛰어나지만, “감성”이 중요한 경우 Sonnet이 우수합니다.
참고 문헌
- n8n 고급 AI 문서
- Claude Sonnet 4.5 발표
- AWS Bedrock에서 Claude Haiku