- 카테고리:
문자열 및 이진 함수 (AI 함수)
AI_COUNT_TOKENS¶
참고
AI_COUNT_TOKENS 은 COUNT_TOKENS(SNOWFLAKE.CORTEX) 의 업데이트된 버전입니다. 최신 기능의 경우 AI_COUNT_TOKENS 를 사용하십시오.
지정된 대규모 언어 모델 또는 작업별 함수에 대한 프롬프트의 예상 토큰 수를 반환합니다. 모델 이름 또는 카테고리/레이블과 같이 토큰 수에 영향을 미치는 추가 입력을 받을 수 있는 함수의 경우 해당 입력도 지정할 수 있습니다.
구문¶
구문은 사용되는 함수에 따라 다를 수 있습니다. 일반적으로 함수 이름, 해당하는 경우 모델 이름, 입력 텍스트, 토큰 수에 영향을 미치는 추가 옵션을 제공합니다.
AI_COUNT_TOKENS(<function_name>, <input_text> )
AI_COUNT_TOKENS( <function_name>, <model_name> , <input_text> )
AI_COUNT_TOKENS( <function_name>, <input_text>, <options> )
AI_COUNT_TOKENS( <function_name>, <model_name>, <input_text>, <options> )
AI_COUNT_TOKENS는 일부 함수에 대해 특정 구문 변형을 사용합니다. 예:
AI_COUNT_TOKENS( 'ai_similarity', <input_text_1>, <input_text_2>, <options> )
AI_COUNT_TOKENS( 'ai_classify', <input_text>, <categories> )
AI_COUNT_TOKENS( 'ai_translate', <input_text>, <source_language>, <target_language> )
함수별 사용량 패턴은 `예제`_를 참조하세요.
인자¶
필수:
function_name토큰 수의 기준으로 삼을 함수의 이름이 포함된 문자열(예:
'ai_complete'또는'ai_sentiment')입니다. 함수의 이름은 “ai_”로 시작해야 하며 소문자만 사용해야 합니다.지원되는 함수의 전체 목록은 리전 가용성 테이블에서 확인할 수 있습니다.
input_text또는input_text_1,input_text_2토큰 수를 계산할 입력 텍스트입니다.
선택 사항:
model_name토큰 내용의 기반이 될 모델의 이름이 포함된 문자열입니다. :samp:`{function_name}`에서 지정한 함수에서 AI_COMPLETE 또는 AI_EMBED 등과 같은, 사용할 모델을 선택해야 하는 경우에 필요합니다.
A list of available LLM models is available in the 리전 가용성 table. However, not all models are currently supported. Snowflake intends to add support for additional models over time.
AI_COMPLETE의 경우 다음 모델은 지원되지 않습니다.
claude-4-opus
claude-4-sonnet
claude-3-7-sonnet
claude-3-5-sonnet
openai-gpt-4.1
openai-o4-mini
categories이 데이터가 필요한 함수에 사용할 하나 이상의 범주 또는 레이블을 지정하는 VARIANT 값의 배열입니다. 카테고리는 입력 토큰 수에 포함됩니다.
options함수가 입력을 처리하는 방법에 영향을 미치는 추가 옵션을 지정하는 VARIANT입니다. AI_SIMILARITY과 같이 두 개의 텍스트 입력을 받는 함수의 경우, 옵션은 모델을 지정하는 데 사용됩니다.
반환¶
입력 텍스트의 토큰 수인 INTEGER 값으로, 주어진 매개 변수 값을 사용하여 계산됩니다.
사용법 노트¶
Although function names are usually written in all uppercase, use only lowercase letters in function and model names.
COUNT_TOKENS does not work with LLM functions in the SNOWFLAKE.CORTEX namespace or with fine-tuned models. You must specify a function name that begins with “ai_”.
COUNT_TOKENS accepts only text, not image, audio, or video inputs.
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"');
응답:
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"');
응답:
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'}
]
);
응답:
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'
};
응답:
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'
}
]
}
);
응답:
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');
응답:
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'}
]
);
응답:
148
AI_SIMILARITY examples¶
The following SQL statement counts the number of tokens in an AI_SIMILARITY call that uses the default model.
SELECT AI_COUNT_TOKENS('ai_similarity',
'The plot is fast and the characters feel real. This book kept me awake all night
because the mystery is so deep. I love how the author handles the ending. It is a
great read for anyone who likes suspense.',
'The story is quick and the people feel true. This novel kept me awake all night
because the puzzle is so big. I love how the writer handles the finale. It is a
solid choice for anyone who enjoys suspense.');
응답:
101
The following SQL statement counts the number of tokens in an AI_SIMILARITY that uses the e5-base-v2 model:
SELECT AI_COUNT_TOKENS('ai_similarity',
'The plot is fast and the characters feel real. This book kept me awake all night
because the mystery is so deep. I love how the author handles the ending. It is a
great read for anyone who likes suspense.',
'The story is quick and the people feel true. This novel kept me awake all night
because the puzzle is so big. I love how the writer handles the finale. It is a
solid choice for anyone who enjoys suspense.', {'model': 'e5-base-v2'})
응답:
92
AI_TRANSLATE example¶
The following SQL statement counts the number of tokens used by AI_TRANSLATE when translating text from English to German.
SELECT AI_COUNT_TOKENS('ai_translate',
'The plot is fast and the characters feel real. This book kept me awake all night
because the mystery is so deep. I love how the author handles the ending. It is a
great read for anyone who likes suspense.', 'en', 'de');
응답:
51
법적 고지¶
Snowflake AI 및 ML 섹션을 참조하십시오.