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 Role

Previous Top Next


MiniRobotLanguage (MRL)

 

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

 

B01003

 

Intention

 

In the input and output JSON structure of the chat endpoint from OpenAI, the "role" field specifies the role of the message sender.
This plays a role with the "AIC.Ask Chat" Command, because it returns some of its Output in a variable called "Role".

Therefore you need to use "AIC.Get Role" to get this information.
 
The possible values for the "role" field are:

 

"system": This value indicates that the message is a system message. System messages are usually used to set the behavior of the assistant at the beginning of the conversation.
For example, a system message might instruct the assistant to speak like Shakespeare.

 

"user": This value indicates that the message is from the user. User messages are the prompts or questions that the user wants the assistant to respond to.

 

"assistant": This value indicates that the message is from the assistant. Assistant messages are the responses generated by the AI in reply to the user's prompts or questions.

 

The "role" field is important as it helps in distinguishing between different types of messages in the conversation and understanding the flow of the conversation.

 

You can set the Role of an "AIC.Ask Chat" Command using the "AIC.Set Role"-Command.

You can use the  

AIC.Get Several|5|$$NUM

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

 

 

Important Note: The "AIC.Set Role" command and the "AIC.Get Role" command operate on different registers; each command has its own dedicated register.

The "AIC.Set Role" command is utilized during a request to set a specific role. On the other hand, the "AIC.Get Role" command is used to retrieve the role that has been returned from the OpenAI server.

This distinction is crucial as the "AIC.Set Role" command is for specifying a role before sending a request, while the "AIC.Get Role" command is for obtaining the role information from the response received from OpenAI.

 

Syntax:

 

AIC.Get Role|<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 Role" 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 Role|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 role from the last answer which has Index 4.

 

 

 

Syntax

 

 

AIC.Get Role[|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

 

Important Note: The "AIC.Set Role" command and the "AIC.Get Role" command operate on different registers; each command has its own dedicated register.

The "AIC.Set Role" command is utilized during a request to set a specific role. On the other hand, the "AIC.Get Role" command is used to retrieve the role that has been returned from the OpenAI server.

This distinction is crucial as the "AIC.Set Role" command is for specifying a role before sending a request, while the "AIC.Get Role" command is for obtaining the role information from the response received from OpenAI.

 

Limitations:

-

 

 

See also:

 

  Set_Key

  Ask_Chat

  Ask_Completion