|
<< Click to Display Table of Contents >> Navigation: 3. Script Language > AI - Artificial Intelligence Commands > AIX. - Grok / X - API > !Output Formatting and Delivery > AIX - Artificial Intelligence and X Platform Utility |
MiniRobotLanguage (MRL)
AIX.Get FinishReason
Retrieve the Reason the AI Stopped Generating
Intention
Get FinishReason Command: Access Completion Details
The Get FinishReason command retrieves the reason the Grok AI stopped generating the latest response, as determined by the HTP_AnalyzeGrokResponse subroutine.
This helps understand the response termination context.
It’s part of the AIX - Grok / X - API suite.
The Get FinishReason command returns the value of the AIX_FinishReason global variable, which contains a string (e.g., "stop", "length", or "tool_calls") indicating why the AI stopped generating.
If no reason is found, it defaults to "unknown".
Retrieving the finish reason is beneficial for:
•Debugging: Identifies why a response ended (e.g., max tokens reached).
•Optimization: Adjusts settings based on termination reasons.
•Workflow: Triggers different actions based on the stop reason.
Use the command to retrieve the finish reason after executing an AI query with AIX.Ask or AIX.AskVision.
Store the result in a variable for further processing or display.
Example Usage
AIX.SetKey|""your_api_key_here""
AIX.SetModel|""grok-3""
AIX.Ask|""Write a short story.""
AIX.Get FinishReason|$$REASON
DBP.Finish reason: $$REASON
This example sets up the system, sends a query, retrieves the finish reason, and displays it.
Illustration
┌────────────────────┐
│ Finish Reason │
├────────────────────┤
│ Input: Response │
│ Process: Extract │
│ Output: Reason │
└────────────────────┘
A visual of extracting the finish reason from the response.
Syntax
AIX.Get FinishReason|$$variable
AIX_Get_FinishReason|$$variable
Parameter Explanation
$$variable - (Required) A variable (e.g., $$REASON) of type WSTRING where the finish reason string will be stored.
Remarks
- The finish reason is extracted from the choices[0].finish_reason field, with fallbacks to the root-level finish_reason or "unknown" if absent.
- Requires a prior call to AIX.Ask or AIX.AskVision to populate the response data.
Limitations
- Returns "unknown" if the finish reason is not provided in the response.
- Reflects only the latest response analysis; previous finish reasons are overwritten.
See also:
• AIX.Ask