`isStepCount()`

isStepCount()

완료된 단계 수가 지정된 수와 같아지면 중지하는 중지 조건을 만듭니다.

이 함수는 generateText 와 streamText 의 stopWhen 과 함께 사용되어, 실행된 단계 수에 따라 tool 호출 루프가 언제 멈춰야 할지 제어해요.

import { generateText, isStepCount } from 'ai';
__PROVIDER_IMPORT__;

const result = await generateText({
  model: __MODEL__,
  tools: {
    // your tools
  },
  // Stop after 5 steps
  stopWhen: isStepCount(5),
});

출처: 문서

본문

Import

<Snippet text={import { isStepCount } from "ai"} prompt={false} />

API 시그니처

매개변수 (Parameters)

<PropertiesTable content={[ { name: 'stepCount', type: 'number', description: 'The number of completed steps that should trigger the stop condition.', }, ]} />

반환값 (Returns)

완료된 단계 수가 지정된 수와 같을 때 true 를 반환하는 StopCondition 함수. 이 함수는 generateText 와 streamText 의 stopWhen 매개변수와 함께 사용할 수 있어요.

예제 (Examples)

기본 사용법 (Basic Usage)

3단계 후 중지:

import { generateText, isStepCount } from 'ai';

const result = await generateText({
  model: yourModel,
  tools: yourTools,
  stopWhen: isStepCount(3),
});

다른 조건과 결합하기 (Combining with Other Conditions)

배열에 여러 중지 조건을 결합할 수 있어요:

import { generateText, isStepCount, hasToolCall } from 'ai';

const result = await generateText({
  model: yourModel,
  tools: yourTools,
  // Stop after 10 steps OR when finalAnswer tool is called
  stopWhen: [isStepCount(10), hasToolCall('finalAnswer')],
});

함께 보기 (See also)

더 알아보기 (Learn more)

전체 사이트맵