순차 생성

순차 생성 (Sequential Generations)

AI SDK로 작업할 때, 한 생성의 출력이 다음 생성의 입력이 되는 생성 시퀀스(흔히 "체인"이나 "파이프"라고 함)를 만들고 싶을 수 있습니다. 이는 더 복잡한 AI 기반 워크플로우를 만들거나 큰 작업을 더 작고 관리하기 쉬운 단계로 쪼개는 데 유용합니다.

순차 체인에서 한 생성의 출력은 다음 생성의 입력으로 직접 사용됩니다. 이를 통해 각 단계가 이전 단계를 기반으로 구축되는 일련의 의존적 생성을 만들 수 있습니다.

출처: 공식문서

본문

예시

순차 액션을 구현하는 방법의 예시입니다:

import { generateText } from 'ai';

async function sequentialActions() {
  // Generate blog post ideas
  const ideasGeneration = await generateText({
    model: "xai/grok-4.6",
    prompt: 'Generate 10 ideas for a blog post about making spaghetti.',
  });

  console.log('Generated Ideas:\n', ideasGeneration);

  // Pick the best idea
  const bestIdeaGeneration = await generateText({
    model: "xai/grok-4.6",
    prompt: `Here are some blog post ideas about making spaghetti:
${ideasGeneration}

Pick the best idea from the list above and explain why it's the best.`,
  });

  console.log('\nBest Idea:\n', bestIdeaGeneration);

  // Generate an outline
  const outlineGeneration = await generateText({
    model: "xai/grok-4.6",
    prompt: `We've chosen the following blog post idea about making spaghetti:
${bestIdeaGeneration}

Create a detailed outline for a blog post based on this idea.`,
  });

  console.log('\nBlog Post Outline:\n', outlineGeneration);
}

sequentialActions().catch(console.error);

이 예시에서는 먼저 블로그 포스트 아이디어를 생성하고, 그다음 가장 좋은 아이디어를 고르고, 마지막으로 그 아이디어를 바탕으로 개요를 만듭니다. 각 단계는 이전 단계의 출력을 다음 생성의 입력으로 사용합니다.

더 알아보기