AIU. - Artificial Intelligence Utility

<< Click to Display Table of Contents >>

Navigation:  3. Script Language > AI - Artificial Intelligence Commands > AIU. - OpenAI API > !Response Analysis >

AIU. - Artificial Intelligence Utility

AIU.GetFinishReason

Previous Top Next


MiniRobotLanguage (MRL)

 

AIU.GetFinishReason
Retrieve the Reason the AI Stopped Generating

 

Intention

 

GetFinishReason Command: Understanding AI Completion Status
 
The GetFinishReason command retrieves the reason why the AI stopped generating its last response, providing insight into the completion process.

This is useful for debugging or optimizing interactions with the OpenAI API.

It’s part of the AIU - OpenAI API suite.

 

What is the GetFinishReason Command?

 

This command returns a string indicating why the AI stopped generating its last response, such as "stop" (natural end), "length" (token limit reached), or "function_call" (function invoked).

You can store the result in a variable or, if no variable is specified, it will be placed on the Top of Stack (TOS).

 

Why Do You Need It?

 

Knowing why the AI stopped is crucial for:

Debugging: Identify if responses are cut off due to token limits or unexpected stops.

Optimization: Adjust parameters like max tokens or stop sequences based on the reason.

Workflow Control: Adapt script logic based on the AI’s completion behavior.

 

How to Use the GetFinishReason Command?

 

Call this command after an AI operation (e.g., AIU.Chat) with an optional variable to store the result.

Common finish reasons include: "stop" (completed naturally), "length" (hit max tokens), or "function_call" (invoked a function).

 

Example Usage

 

AIU.SetMaxToken|10

AIU.Chat|Tell me a long story|$$STO

AIU.GetFinishReason|$$REA

DBP.Finish Reason: $$REA

 

This example limits the response to 10 tokens, likely resulting in $$REA being "length".

 

Illustration

 

┌────────────────────┐

│ Finish Reason      │

├────────────────────┤

│ "length"           │

└────────────────────┘

Retrieving why the AI stopped due to token limit.

 

Syntax

 

AIU.GetFinishReason[|P1]

AIU.Get_FinishReason[|P1]

 

Parameter Explanation

 

P1 - (Optional) The variable where the finish reason will be stored. If omitted, the reason is placed on the Top of Stack (TOS).

 

Example

 

AIU.Chat|Hi there|$$RES

AIU.GetFinishReason|$$WHY

DBP.Stopped Because: $$WHY

ENR.

 

Remarks

 

- Must follow an AI operation to retrieve a valid reason.

- Returns an empty string or undefined value if no prior operation exists.

 

Limitations

 

- Accepts at most one parameter; additional parameters trigger an error.

- Only reflects the last operation’s finish reason.

 

See also:

 

AIU.Chat

AIU.SetMaxToken

AIU.GetTotalTokens

Response Analysis Getters