AI - Internet Commands

<< Click to Display Table of Contents >>

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

AI - Internet Commands

AIC.Http Request

Previous Top Next


MiniRobotLanguage (MRL)

 

AIC.Http Request
Send an HTTP request and receive the result

 

 

 

Intention

 

The AIC.Http Request command is used to send an HTTP request to a specified URL.

It allows you to perform different types of HTTP operations such as GET, POST, PUT, PATCH, and DELETE.
You can also specify data to be sent and custom headers for the request.

The Command will return the Status of the Request on TOS. If this is "0" there will be additional Information available using

AIC.Get Several|3|$$RET

   this Command will also return the result of the http.request no matter is the call was successful or error.

 
  This command can be used to interface additional AI Services that may not yet be implemented using the SPR.
   It can also be used for things that have nothing to do with AI-Services.

 

Example Usage:

 

 

' Make http-Request and receive answer

$$URL=https://api.openai.com

AIC.http request|get|$$URL||Accept=application/json$crlf$User-Agent=MyApp

POP.$$TOS

AIC.Get Several|3|$$RET

MBX.Received $$TOS: $$RET

ENR.

 

 

Syntax

 

 

AIC.Http Request|P1|P2|P3|P4

AIC.HTP|P1|P2|P3|P4

 

 

Parameter Explanation

 
P1 -  <Type of Operation>: Specifies the HTTP method for the request. Acceptable values are: get, post, put, patch, delete. This parameter is case-insensitive.

P2 - <URL>: Specifies the URL to which the HTTP request is sent. Should be a valid URL string.

P3 - <Data>: Specifies the data to be sent in the request. For GET requests, this should typically be left empty or null. For POST, PUT, and PATCH requests, this can be the data payload.

P4 - <Headers>: Specifies the headers to be included in the HTTP request. Headers should be separated with $crlf$ and each key-value pair should be separated with =.

       If no headers are specified, the default headers will be used:

       content-type set to application/json

   Authorization set to Bearer <AI_OKEY>

    Where <AI_OKEY> is the Open AI API-Key that you have set using the Command AIC.Set Key

 

 

Example

 

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

' EXAMPLE 1: AIC.-Commands

' ' This is just a Syntax Sample the Script does not make anything useful

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

' Set OpenAI API-Key from the saved File

AIC.SetKey|File

 

' 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

 

' Make http-Request and receive answer

$$URL=https://api.openai.com

AIC.http request|get|$$URL||Accept=application/json$crlf$User-Agent=MyApp

POP.$$TOS

AIC.Get Several|3|$$RET

MBX.Received $$TOS: $$RET

 

:enx

ENR.

 

 

Remarks

-

 

Limitations:

-

 

 

See also:

 

  Set_Key

  Ask_Chat

  Ask_Completion