카테고리:

문자열 및 이진 함수 (AI 함수)

AI_COUNT_TOKENS

참고

AI_COUNT_TOKENS 은 COUNT_TOKENS(SNOWFLAKE.CORTEX) 의 업데이트된 버전입니다. 최신 기능의 경우 AI_COUNT_TOKENS 를 사용하십시오.

지정된 대규모 언어 모델 또는 작업별 함수에 대한 프롬프트의 토큰 수를 반환합니다.

구문

AI_COUNT_TOKENS(<function_name>, <model_name> , <input_text> )
AI_COUNT_TOKENS(<function_name>, <input_text> )
AI_COUNT_TOKENS(<function_name>, <input_text>, <categories> )
Copy

인자

필수:

function_name

토큰 수의 기준으로 삼을 함수의 이름이 포함된 문자열(예: 'ai_complete' 또는 'ai_sentiment')입니다. 함수의 이름은 “ai_”로 시작해야 하며 소문자만 사용해야 합니다.

지원되는 함수의 전체 목록은 리전 가용성 테이블에서 확인할 수 있습니다.

input_text

토큰 수를 계산할 입력 텍스트입니다.

선택 사항:

model_name

토큰 내용의 기반이 될 모델의 이름이 포함된 문자열입니다. :samp:`{function_name}`에서 지정한 함수에서 AI_COMPLETE 또는 AI_EMBED 등과 같은, 사용할 모델을 선택해야 하는 경우에 필요합니다.

사용 가능한 LLM 모델 목록은 리전 가용성 테이블에서 확인할 수 있습니다. 그러나 현재 모든 모델이 지원되는 것은 아닙니다.

AI_COMPLETE의 경우 다음 모델은 지원되지 않습니다.

  • claude-4-opus

  • claude-4-sonnet

  • claude-3-7-sonnet

  • claude-3-5-sonnet

  • openai-gpt-4.1

  • openai-o4-mini

AI_EMBED의 경우 다음 모델은 지원되지 않습니다.

  • snowflake-arctic-embed-l-v2.0-8k

categories

이 데이터가 필요한 함수에 사용할 하나 이상의 범주 또는 레이블을 지정하는 VARIANT 값의 배열입니다. 카테고리는 입력 토큰 수에 포함됩니다.

반환

입력 텍스트의 토큰 수인 INTEGER 값으로, 주어진 매개 변수 값을 사용하여 계산됩니다.

사용법 노트

  • 함수 및 모델 이름에는 소문자만 사용하세요.

  • COUNT_TOKENS는 SNOWFLAKE.CORTEX 네임스페이스의 LLM 함수 또는 미세 조정된 모델과 함께 작동하지 않습니다. “AI_”로 시작하는 함수 이름을 지정해야 합니다.

  • COUNT_TOKENS는 이미지나 오디오 입력이 아닌 텍스트만 허용합니다.

  • COUNT_TOKENS는 토큰 기반 청구를 사용하지 않으며 컴퓨팅 비용만 발생합니다.

  • COUNT_TOKENS는 모든 리전에서 사용할 수 있습니다. 특정 리전에서 사용할 수 없는 모델에 대해서도 사용 가능합니다.

AI_COMPLETE 예제

다음 SQL 문은 AI_COMPLETE 및 llama3.3-70b 모델에 대한 프롬프트의 토큰 수를 계산합니다.

SELECT AI_COUNT_TOKENS('ai_complete', 'llama3.3-70b', 'Summarize the insights from this
call transcript in 20 words: "I finally splurged on these after months of hesitation about
the price, and I\'m mostly impressed. The Nulu fabric really is as buttery-soft as everyone says,
and they\'re incredibly comfortable for yoga and lounging. The high-rise waistband stays put
and doesn\'t dig in, which is rare for me. However, I\'m already seeing some pilling after
just a few wears, and they definitely require gentle care. They\'re also quite delicate -
I snagged them slightly on my gym bag zipper. Great for low-impact activities, but I wouldn\'t
recommend for high-intensity workouts. Worth it for the comfort factor"');
Copy

응답:

158

AI_EMBED 예제

다음 SQL 문은 AI_EMBED 함수 및 nv-embed-qa-4' 모델을 사용하여 포함되는 텍스트의 토큰 수를 계산합니다.

SELECT AI_COUNT_TOKENS('ai_embed', 'nv-embed-qa-4', '"I finally splurged on these after months
of hesitation about the price, and I\'m mostly impressed. The Nulu fabric really is as buttery-soft
as everyone says, and they\'re incredibly comfortable for yoga and lounging. The high-rise waistband
stays put and doesn\'t dig in, which is rare for me. However, I\'m already seeing some pilling after
just a few wears, and they definitely require gentle care. They\'re also quite delicate - I snagged
them slightly on my gym bag zipper. Great for low-impact activities, but I wouldn\'t recommend for
high-intensity workouts. Worth it for the comfort factor"');
Copy

응답:

142

AI_CLASSIFY 예

이 예에서는 주어진 입력 및 레이블을 사용하여 텍스트 분류에 필요한 총 입력 토큰 수를 계산합니다.

SELECT AI_COUNT_TOKENS('ai_classify',
  'One day I will see the world and learn to cook my favorite dishes',
  [
      {'label': 'travel'},
      {'label': 'cooking'},
      {'label': 'reading'},
      {'label': 'driving'}
  ]
);
Copy

응답:

187

이전 예에 레이블별 설명과 전체 작업 설명을 추가한 예는 다음과 같습니다.

SELECT AI_COUNT_TOKENS('ai_classify',
  'One day I will see the world and learn to cook my favorite dishes',
  [
    {'label': 'travel', 'description': 'content related to traveling'},
    {'label': 'cooking','description': 'content related to food preparation'},
    {'label': 'reading','description': 'content related to reading'},
    {'label': 'driving','description': 'content related to driving a car'}
  ],
  {
    'task_description': 'Determine topics related to the given text'
  };
Copy

응답:

254

다음 예는 앞선 두 예를 바탕으로 레이블 예를 추가한 것입니다.

SELECT AI_COUNT_TOKENS('ai_classify',
  'One day I will see the world and learn to cook my favorite dishes',
  [
    {'label': 'travel', 'description': 'content related to traveling'},
    {'label': 'cooking','description': 'content related to food preparation'},
    {'label': 'reading','description': 'content related to reading'},
    {'label': 'driving','description': 'content related to driving a car'}
  ],
  {
    'task_description': 'Determine topics related to the given text',
    'examples': [
      {
        'input': 'i love traveling with a good book',
        'labels': ['travel', 'reading'],
        'explanation': 'the text mentions traveling and a good book which relates to reading'
      }
    ]
  }
);
Copy

응답:

298

AI_SENTIMENT 예

다음 SQL 문은 AI_SENTIMENT 함수를 사용하여 감정을 분석하는 텍스트의 토큰 수를 계산합니다.

SELECT AI_COUNT_TOKENS('ai_sentiment',
  'This place makes the best truffle pizza in the world! Too bad I cannot afford it');
Copy

응답:

139

다음 예는 이전 예에 레이블을 추가한 것입니다.

SELECT AI_COUNT_TOKENS('ai_sentiment',
  'This place makes the best truffle pizza in the world! Too bad I cannot afford it',
  [
    {'label': 'positive'},
    {'label': 'negative'},
    {'label': 'neutral'}
  ]
);
Copy

응답:

148