|
<< Click to Display Table of Contents >> Navigation: »No topics above this level« AIN. - AnythingLLM AI |
MiniRobotLanguage (MRL)
AIN.SetMaxToken
Set the Maximum Token Limit for AnythingLLM API Calls
Intention
SetMaxToken Command: Controlling Response Length
The SetMaxToken command allows you to define the maximum number of tokens (words or word pieces) that the AnythingLLM API can generate in a response.
This helps manage response length and resource usage in your scripts.
It’s part of the AIN - AnythingLLM AI suite.
This command updates the AIN_MaxToken global variable, which caps the token count for API responses.
If set to 0 or omitted, it defaults to 4096 tokens, as defined by %AIN_MaxToken.
Setting a maximum token limit is useful for:
•Efficiency: Limit response size to reduce processing time and resource consumption.
•Relevance: Prevent overly long responses that may dilute key information.
•Control: Tailor output length to fit specific script requirements.
Use this command before making API calls like AIN.Ask or AIN.AskV to control response length.
The value must be a positive integer; otherwise, it defaults to 4096.
Example Usage
AIN.SetMaxToken|100
AIN.Ask|Explain quantum physics|$$EXP
DBP.Short Explanation: $$EXP
This limits the response to 100 tokens for a concise explanation.
Illustration
┌────────────────────┐
│ Max Tokens │
├──────┬─────────────┤
│ 100 │ Short │
│ 4096 │ Default │
└──────┴─────────────┘
Setting max tokens to control response length.
Syntax
AIN.SetMaxToken|P1
AIN.Set_MaxToken|P1
Parameter Explanation
P1 - The maximum token limit (positive integer). If 0 or omitted, defaults to 4096.
Example
AIN.SetMaxToken|500
AIN.Ask|Summarize a book|$$SUM
DBP.Book Summary: $$SUM
ENR.
Remarks
- Verify the current limit with AIN.GetMaxToken.
- The actual token count may vary slightly depending on the model’s tokenization.
Limitations
- The maximum value is model-dependent; exceeding the model’s limit may truncate responses.
- Negative values are not supported and reset to the default (4096).
See also:
• AIN.Ask
• AIN.AskV