AIG. - AI Google Gemini Integration

<< Click to Display Table of Contents >>

Navigation:  3. Script Language > AI - Artificial Intelligence Commands > AIG. - Google AI > 8. Results & Analysis >

AIG. - AI Google Gemini Integration

AIG.GetFinishReason

Previous Top Next


MiniRobotLanguage (MRL)

 

AIG.GetFinishReason
Retrieve the Finish Reason of the Last Response

 

Intention

 

GetFinishReason Command: Understand why generation stopped
 
The GetFinishReason command retrieves the metadata indicating why the Google Gemini API stopped generating text for the last request.

This allows your script to programmatically determine if the answer was completed successfully ("STOP"), cut off due to length limits ("MAX_TOKENS"), or blocked by safety filters ("SAFETY").

 

What is the GetFinishReason Command?

 

It fetches the status string stored in the global variable AIG_FinishReason. This variable is updated automatically after every AIG.Ask or AIG.AskVision call.

 

Common Return Values

STOP : Natural completion. The model finished the answer.

MAX_TOKENS : The output was cut off because it reached the limit set by AIG.Set MaxToken.

SAFETY : The content was blocked by the safety settings (e.g., harassment, hate speech).

RECITATION : The model stopped to avoid reciting copyrighted material verbatim.

OTHER : Unknown or other error.

 

Why Do You Need It?

 

Checking the finish reason is critical for robust scripts:

Detect truncated answers and potentially request continuation.

Handle safety blocks gracefully instead of crashing on empty content.

Verify that the "Success" status of the script was genuine.

 

Example Usage

 

AIG.Set MaxToken|50

AIG.Ask|Write a very long poem about the universe.

AIG.GetFinishReason|$$RSN

IVV.$$RSN=MAX_TOKENS

 � DBP.The poem was cut off!

ELSE

 � DBP.The poem finished normally.

EIF.

 

Illustration

 

Response +------------+

Status: �� MAX_TOKENS � ? (Incomplete)

 � � � � +------------+

 

Syntax

 

AIG.GetFinishReason[|P1]

AIG.gfr[|P1]

 

Parameter Explanation

 

P1 - (Optional) Variable to store the finish reason string (e.g., "STOP"). If omitted, the value is placed on the Top of Stack (TOS).

 

Remarks

 

- Requires a prior API call (e.g., AIG.Ask) to update the status.

- The value is overwritten by every new generation request.

 

Limitations

 

- Returns an empty string if no request has been made or if the API failed to return a reason.

 

See also:

 

? AIG.Get Content

? AIG.GetTokens

? AIG.Set MaxToken