|
<< Click to Display Table of Contents >> Navigation: »No topics above this level« AIN. - AnythingLLM AI |
MiniRobotLanguage (MRL)
AIN.GetTotalTokens
Get the Total Tokens Used in the Last Response
Intention
GetTotalTokens Command: Measuring Token Usage
The GetTotalTokens Command retrieves the total number of tokens used in the last response generated by an AnythingLLM Command, such as AIN.ExecuteChat.
This is useful for tracking usage, optimizing prompts, or monitoring costs in token-based systems.
It�s part of the AIN - AnythingLLM AI suite.
This Command calculates and returns the total token count from the most recent response stored in the system, typically from a chat or query operation.
Tokens are units of text (words, punctuation, etc.) as processed by the underlying language model.
Use this Command to:
�Monitor Usage: Track token consumption for cost management.
�Optimize Responses: Adjust prompts to reduce token counts.
�Debugging: Analyze response efficiency in automated workflows.
Execute this Command after a response-generating operation. Optionally specify a variable to store the token count; otherwise, it�s placed on the stack.
No additional API key setup is required beyond the initial AIN.SetKey.
Example Usage
AIN.SetKey|your_api_key_here
AIN.ExecuteChat|my-workspace|What is AI?|query|$$RES
AIN.GetTotalTokens|$$TOK
DBP.Token Count: $$TOK
This retrieves the token count of the response to "What is AI?" and displays it.
Illustration
+------------------------------+
� Get Token Count � � � � � � ��
+------------------------------�
� Last Response: "AI is..." � ��
� Tokens: $$TOK � � � � � � � ��
+------------------------------+
Retrieving the token count from the last response.
Syntax
AIN.GetTotalTokens[|P1]
Parameter Explanation
P1 - Result variable (optional). Stores the total token count; if omitted, it�s placed on the stack.
Example
AIN.SetKey|your_api_key_here
AIN.ExecuteChat|my-workspace|Tell me about AI|chat|$$RES
AIN.GetTotalTokens|$$TOK
DBP.Tokens Used: $$TOK
ENR.
Remarks
- Requires a prior response-generating Command to have been executed.
- Token count includes all tokens in the response, as defined by the language model.
Limitations
- Only reflects the last response; earlier responses are not accessible.
- Token definition depends on the underlying model�s tokenizer.
See also: