Categories:

String & binary functions (AI Functions)

COUNT_TOKENS (SNOWFLAKE.CORTEX)

Note

is the latest version of this function. Use AI_COUNT_TOKENS for the latest functionality. You can continue to use COUNT_TOKENS (SNOWFLAKE.CORTEX).

返回实参中指定的大型语言模型或任务特定函数的提示符中的令牌数。此函数不支持微调模型。

语法

SNOWFLAKE.CORTEX.COUNT_TOKENS( <model_name> , <input_text> )

实参

必填:

model_name

要作为令牌计数基础的模型的名称。指定以下值之一:

  • deepseek-r1
  • e5-base-v2
  • e5-large-v2
  • llama3-70b
  • llama3-8b
  • llama3.1-405b
  • llama3.1-70b
  • llama3.1-8b
  • llama3.3-70b
  • llama4-maverick
  • llama4-scout
  • mistral-7b
  • mistral-large
  • mistral-large2
  • mixtral-8x7b
  • nv-embed-qa-4
  • snowflake-arctic-embed-l-v2.0
  • snowflake-arctic-embed-m-v1.5
  • snowflake-arctic-embed-m
  • snowflake-arctic
  • snowflake-llama-3.1-405b
  • snowflake-llama-3.3-70b
  • voyage-multilingual-2
input_text

输入文本,计算其中的令牌。

返回

Returns an INT , INTEGER , BIGINT , SMALLINT , TINYINT , BYTEINT type that is the number of tokens in the input text based on the model or function specified.

使用说明

  • 如果指定了函数名称,令牌数将基于函数使用的模型。
  • 在函数名称中使用小写字母。

Note

COUNT_TOKENS does not account for the managed system prompt that is automatically added to the beginning of the input text when using a Cortex Cortex AI functions. As a result, the value returned by COUNT_TOKENS is lower than the actual number of tokens processed by these functions.

示例

The following example returns the token count for the specified prompt using the llama3.1-70b model:

SELECT SNOWFLAKE.CORTEX.COUNT_TOKENS( 'llama3.1-70b', 'what is a large language model?' );
+---+
| 6 |
+---+

法律声明

Refer to Snowflake AI and ML.