AI - Direct Access

<< Click to Display Table of Contents >>

Navigation:  3. Script Language > AI - Artificial Intelligence Commands > AIC. - Artificial Intelligence Command > AI - Direct Access >

AI - Direct Access

AIC.Get Finish

Previous Top Next


MiniRobotLanguage (MRL)

 

AIC.Get Finish
Get the Finish Reason of the last Open AI-Command.

 

clip0669

clip0668

 

Intention

 

The "AIC.Get Finish" command returns the "finish_reason" variable*, which specifies the reason that caused the AI to cease generating a response. Typically, this occurs when the AI has successfully completed and formulated the answer.

 

The "stop" and "length" are two possible values for the "Finish_reason" parameter, which indicates why the AI stopped generating the response.
Let's evaluate these two and also discuss other possible values for "Finish_reason":

 

stop: This is the normal case, where the AI has successfully processed your prompt and generated a complete response. It indicates that the AI has reached a logical conclusion or endpoint in the response.

length: This reason indicates that the AI could not complete the response because it reached the maximum token limit set by the user through the "AIC.Set MaxToken" command or by default system constraints. Tokens are chunks of text, and there is a limit to how many tokens can be in a single response. If the response is cut off due to reaching this limit, the "Finish_reason" will be "length".

timeout: This is another possible value for "Finish_reason". It indicates that the AI stopped generating the response because it reached a time limit. This could be due to system constraints or a user-defined timeout setting. It's used to prevent the AI from taking too long to generate a response.

interrupted: This reason would indicate that the generation process was interrupted by an external factor, such as a user manually stopping the generation or a system error.

threshold: In some cases, the AI might stop generating text if the confidence level falls below a certain threshold. This is to ensure that the generated text meets a certain quality standard.

 

Understanding the "Finish_reason" is important as it provides insights into why the AI stopped generating the response and can help in troubleshooting or optimizing the settings for text generation.

 

Some Commands will return their Output in a Variable called "Text", in that case you will get the Output using the "AIC.Get Text"-Command.

The Open AI "Chat-Endpoint" = the "AIC.Ask Chat" Command, returns its Output in a variable called "Content", therefore you need to use "AIC.Get Content"

to get the Output-Text. In total, the Output from the "AIC.Ask Chat" Command will include these fields (these are Array starting with the Index of "0"):

 

Choices (returns a number how many answers are returned, normally equal the number you have set using "AIC.Set Number"

Content - this is the important Part of the Answer.

Role

Finish - this is the "Finish Reason". It will tell you if the answer finished due to "Stop" which is Ok, or due to "insuffcient number of available Tokens".
In the later case you should increase the Number in "AIC.Set MaxToken".
 

In case you have set "AIC.Set Number" to any number higher then "1", you will receive multiple Answers from the AI.

They may be equal (in Text-Generation, if Temperature is high) or not (in Image Generation mostly not).
 

You can use the  

AIC.Get Several|5|$$NUM

  Command to find out how many Answers have been delivered by the AI.

 

You can specify which of these multiple Answers you want to have returned by specifying the Index of the Answer after the Command.

To keep things equal with the underlying JSON Structure, the Index-Number of the first Answer is zero (you can leave it empty or write "0").

 

 

 

Syntax:

 

AIC.Get Finish|<Index Number>|<Variable for Result>

 

Parameters:

<Number>: An integer value starting at zero, valid to the Value that has been specified using  "AIC.Set Number" Minus 1 (because we start with "0").

For example if you have specified to get just 1 Answer - which is the normal case - then the only valid number is "0".

If you are waiting for 2 Answers from the AI, the possible numbers are "0" and "1". This number representing the Array Index of the Output you want to get.

<Variable for Result>: This is a placeholder for the variable where you want to store the content retrieved by the "AIC.Get Content" command.
This variable will hold the data from the specified index in the output array. If omitted, TOS is used.

 

Example Usage:

 
AIC.Set Number|5
AIC.Get Content|4|$$RET

 

This example we have set the number of Results/Answers we want from the AI to 5. So we get 5 Answers,their Index-Numbers range from "0" to"4".

Here we retrieve the last answer which has Index 4.

 

 

 

Syntax

 

 

AIC.Get Finish[|P1][|P2]

AIC.gtf[|P1][|P2]

 

 

Parameter Explanation

 
P1 - opt. Variable or numeric value, this is the number of the alternative results, you want to be returned.  

P2 - opt. Variable for result. If omitted TOS is used.  

 

 

*Here is a Sample of the original returned JSON Data from the Chat-Endpoint.
 

  "id": "chatcmpl-7Zbc78I0ULOEdP1RfHTYPzRxsZSYZ",

  "object": "chat.completion",

  "created": 1688720424,

  "model": "gpt-3.5-turbo-0613",

  "choices": [

    {

      "index": 0,

      "message": {

        "role": "assistant",

        "content": "\"Imagine a world where technology has advanced to the point where humans can live forever. Explore the ethical implications and consequences of immortality on society, relationships"

      },

      "finish_reason": "length"

    }

  ],

  "usage": {

    "prompt_tokens": 20,

    "completion_tokens": 30,

    "total_tokens": 50

  }

}

 

 

Example

 

'*****************************************************

' EXAMPLE 1: AIC.-Commands

'*****************************************************

' Set OpenAI API-Key from the saved File

AIC.SetKey|File

 

' Set Model

AIC.SetModel_Chat|1

 

' Set Model-Temperature

AIC.Set_Temperature|0

 

' Set Max-Tokens (Possible lenght of answer, depending on the Model up to 2000 Tokens which is about ~6000 characters)

' The more Tokens you use the more you need to pay.

AIC.SetMax_Token|25

 

' We will create 4 alternative answers

AIC.Set Number|4

 

' Ask Question and receive answer to $$RET

AIC.Ask_Chat|What is a "Windows Button"?|$$RET

 
' Make a Loop over the number of results

FOR.$$LOP|1|4

  AIC.gtc|$$LOP|$$RET

  DBP.Result No.$$LOP

  DBP.$$RET 

  AIC.gtf|$$LOP|$$RET

  DBP.Finish Reason fort Result No.$$LOP

  DBP.$$RET 

NEX.

MBX.!

 

:enx

ENR.

 

 

Remarks

 

 

 

Limitations:

-

 

 

See also:

 

  Set_Key

  Ask_Chat

  Ask_Completion