|
<< Click to Display Table of Contents >> Navigation: »No topics above this level« AIN. - AnythingLLM AI |
MiniRobotLanguage (MRL)
AIN.GetFinishReason
Get the Finish Reason
Intention
GetFinishReason Command: Retrieve Completion Status
The AIN.GetFinishReason command retrieves the reason why an AI request (e.g., chat or vision completion) terminated, such as "stop" (natural end), "length" (token limit reached), or "error" (failure).
This is useful for debugging or understanding the outcome of interactions with the AnythingLLM API, especially when paired with commands like AIN.Ask or AIN.AskV.
It’s part of the AIN - AnythingLLM AI suite.
The AIN.GetFinishReason command extracts the finish reason from the most recent AnythingLLM API response, typically stored in the raw JSON response after a chat or vision request.
Common finish reasons include "stop" (completed naturally), "length" (hit max tokens), or "error" (processing failed), reflecting the status of the underlying model (e.g., llava via Ollama).
This command is essential for:
•Debugging: Identify why a response was incomplete or failed.
•Workflow Control: Adjust script behavior based on completion status.
•Monitoring: Track AI performance in automation tasks.
Use AIN.GetFinishReason after an API request to retrieve the finish reason, storing it in a specified variable.
It relies on the raw response from the last AIN.Ask or AIN.AskV call, typically stored in AIN_Raw_Return.
Example Usage
AIN.SetKey|your_api_key_here
AIN.SetModel|llava
AIN.AskV|What’s in this?|C:\Screenshots\screen.jpg|$$RES
AIN.GetFinishReason|$$REA
DBP.Finish Reason: $$REA
After a vision request, retrieves the finish reason (e.g., "stop") into $$REA.
Syntax
AIN.GetFinishReason|P1
Parameter Explanation
P1 - Variable to store the finish reason (required), e.g., "$$REA".
Example
AIN.Ask|Tell me a story|$$STORY
AIN.GetFinishReason|$$WHY
DBP.Why it stopped: $$WHY
ENR.
Checks why a text chat request ended, storing the reason in $$WHY.
Remarks
- Must follow an API request (e.g., AIN.Ask or AIN.AskV) to have a valid response to parse.
- Returns an empty string if no prior request exists or the reason is unavailable.
Limitations
- Depends on the raw JSON response format; changes in AnythingLLM’s API may affect compatibility.
- Only reflects the last request’s status.
See also:
• AIN.Ask
• AIN.AskV