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 Content

Previous Top Next


MiniRobotLanguage (MRL)

 

AIC.Get Content
Get the Text Result of the Ask-Chat Command.

 

B01003

 

Intention

 

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 Content|<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 Content[|P1][|P2]

AIC.gtc[|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 

NEX.

MBX.$$RET

 

:enx

ENR.

 

 

 

 

 

Remarks

 

 

 

Limitations:

-

 

 

See also:

 

  Set_Key

  Ask_Chat

  Ask_Completion