AIC. - Artificial Intelligence Command

<< Click to Display Table of Contents >>

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

AIC. - Artificial Intelligence Command

AIC.SetKey

Previous Top Next


MiniRobotLanguage (MRL)

 

AIC.SetKey
Set OpenAI-API Key

 

clip0686

 

Intention

 

SetKey Command: Initiating Your Script with a License Key
 
Before diving into the world of AI scripting, it's essential to set the stage with the SetKey command.

This command is the golden ticket that grants you access to the plethora of AI functionalities offered by OpenAI.

Let's break down how to use it effectively.

 

  What is the SetKey Command?

 

The SetKey command is the first command you need to include at the beginning of your script.

It's like the key to a treasure chest; without it, you can't unlock the AI capabilities you're after.

Specifically, it defines AI - Artificial Intelligence Commands.

 

Why Do You Need It?

You might be wondering why there's a need for such a key.
The reason is that the AI functionalities you are looking to use are not processed locally on your computer.

Instead, they are handled remotely in the high-powered OpenAI Cloud.
This License Key ensures that you have the proper authorization to access these cloud-based services.

 

  How to Obtain the License Key?

To get your hands on this key, you'll need to visit OpenAI's official website.
Once there, follow the instructions to register and obtain the License Key.
Keep this key safe, as you'll need it every time you want to use OpenAI's services.

 

  How to Use the SetKey Command?

Once you have your License Key, it's time to put it to use.
At the very start of your script, include the AIC.SetKey command followed by your License Key.
This will authenticate your script with OpenAI's cloud services.

On the long run you may prefer the second Option (see below) that will encrypt your key into a file and use this file.

 

 

The AIC.Set_Key-Command has multiple Usage Options.

 

1. You can directly set the Key in the Script.

Here is a Sample Script that shows how this is done.

 

' IMPORTANT: This API-Key is a phantasy API-Key it must be replaced with your API-Key.

$$KEY=sk-abcdefghijklmnopqrstuvwxyz123456

 

' Test if we are online, AI-Commands will only work if you are online.

NOL.

 GTO.enx

EIF.

 

' Set OpenAI API-Key

AIC.SetKey|$$KEY

 

' Set Model

AIC.SetModel_Comp|0

 

' 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

 

' Ask Question and receive answer to $$RET

AIC.Ask_Completion|Wieviel Uhr ist es?|$$RET

DBP.$$RET

 

:enx

ENR.

 

2. You can use a saved, encrypted Key, that is stored in the project-folder.

This is the preferred way because this is more save for your key.

The default name for this saved Key is "AIC_License_Key.dat"

If no path is given, the file is created at "?exeloc\" that is the folder where the Script/the executable resides.

This key-file can be created using the AIC.Save_Key|$$KEY[|$$FIL] Command.

 

 

' Script 1: Save the Key to the file "AIC_License_Key.dat".

 

IMPORTANT: This API-Key is a phantasy API-Key it must be replaced with your API-Key.

$$KEY=sk-abcdefghijklmnopqrstuvwxyz123456

 

' Here we save the Keyfile at the default path, that is:

' ?exeloc\AIC_License_Key.dat

AIC.Save_Key|$$KEY

ENR.

 

' Script 2; Using the crypted API-Keyfile

' Test if we are online, AI-Commands will only work if you are online.

NOL.

GTO.enx

EIF.

 

' Set OpenAI API-Key from the saved File

AIC.SetKey|from_File

 

' Set Model

AIC.SetModel_Completion|4

 

' 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

 

' Ask Question and receive answer to $$RET

AIC.Ask_Completion|Wieviel Uhr ist es?|$$RET

DBP.$$RET

 

:enx

ENR.

 

3. You can use a Textfile, that contains your Key.

This is way to go, if you make an Executable that you want to share with the public or other people.

To give them the Option to use your SPR-Script together with their own API-Key, you can offer this Option.

 

The default name for this saved Key in a Textfile is "AIC_License_Key.txt"

If no path is given in P2, the file should be located in "?exeloc\" that is the folder where the Script/the executable resides.

This key-file can be created using any Texteditor (or CTF.-Command).

 

 

' Script 3: Using the API-Keyfile with the API-Key as Text

' Test if we are online, AI-Commands will only work if you are online.

NOL.

GTO.enx

EIF.

 

' Set OpenAI API-Key from the saved File

AIC.SetKey|from Text

 

' Set Model

AIC.SetModel_Completion|4

 

' 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

 

' Ask Question and receive answer to $$RET

AIC.Ask_Completion|Wieviel Uhr ist es?|$$RET

DBP.$$RET

 

:enx

ENR.

 

 

Syntax

 

 

AIC.SetKey|P1[|P2]

AIC.Set_Key|P1[|P2]

 

 

Parameter Explanation

P1 - Can be directly an Open AI API-Key or:

      from File - if given as P1, there should be a encrypted Keyfile with the name "AIC_License_Key.dat" at ?exeloc\ or if specified, at Path P2. This file can only be created using the AIC.Save Key - Command.

      from Text - if given as P1, there should be a Textfile that contains the API-Key with the name "AIC_License_Key.txt" at ?exeloc\ or if specified, at Path P2. This file can be created using any Text-Editor.

      Load Any Key - if given as P1, the command will load any available API-Key.

 

P2 - opt. if specified this is the Path (and filename) of the Keyfile to use with the two options above. It can be either a Crypted or a Textfile. The System will decide with the Extension ".txt" or ".dat" how it is loaded.

 

 

Example

 

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

' EXAMPLE 1: AIC.-Commands

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

' IMPORTANT: This API-Key is a phantasy API-Key it must be replaced with your API-Key

$$KEY=sk-san4gh3j43h543k3HzpGbZbCq6PeVbSZy69H

' Test if we are online, AI-Commands will only work if you are online.

NOL.

GTO.enx

EIF.

 

' Set OpenAI API-Key

AIC.SetKey|$$KEY

 

' Set Model

AIC.SetModel_Completion|4

 

' 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

 

' Ask Question and receive answer to $$RET

AIC.Ask_Completion|Wieviel Uhr ist es?|$$RET

DBP.$$RET

 

:enx

ENR.

 

 

Remarks

 

A Word of Caution: Safeguarding Your API Key 🚨

 

Dear Valued User,

 

🔒 This Encryption is Not Impenetrable 🔒

 

Even if your API Key is encrypted within a file, the Decryption is hereby done without a Password, means anybody can decrypt it if he has the SPR at hand.

It's akin to a treasure locked in a chest.

The chest provides an added layer of security and invisibility, but should it fall into the hands of a pirate with the SPR and Knowledge, the treasure can be plundered.

You may ask: "Why did we not use a Password?"

The answer is simple, even then you would need to provide that Password in Cleartext in the code, because the SPR needs to decrypt the keyfile anyway.
So there would be no advantage. In case you want to enter the Password each time and have an unbreakable Encrytion, you can instead do something using the GUT. and the GEC.-Command.

 

🚫 Do Not Distribute the Key, Even Encrypted 🚫

 

Distributing executables or scripts along with the file containing your encrypted API Key is akin to sending your treasure chest out to sea on an unmanned ship. Anyone who gets hold of this file and has access to an SPR (Script Processing Runtime) can potentially decrypt and misuse your API Key.

 

💡 Why is This a Big Deal? 💡

 

Your API Key is not just a string; it's your identity and access within the OpenAI realm. It's linked to your account, your resources, and your privileges. In the wrong hands, it can be used to access services and consume quotas associated with your account. This can have both financial and security implications.

 

🛡️ What Should You Do? 🛡️

 

Never Distribute the Key: Do not include your API Key, even if encrypted, in any files or executables that you distribute.

 

Access Control: If your application requires the use of the API Key, consider implementing a backend service that your application can call. The service can then use the API Key server-side, where it's not exposed to the end-user.

 

Vigilance: Regularly monitor the usage of your API Key and be vigilant for any unauthorized or unexpected activity.

 

Set Usage Limits: Visit the OpenAI website and access your account settings. Here, you can set limits on the usage of your API Key. This is a wise precaution to ensure that even if the unthinkable happens, the potential damage is contained. It's like setting a magical barrier around your treasure chest!

 

Remember, with great power comes great responsibility. Your API Key is a powerful tool; wield it wisely and guard it well.

 

Safe coding!

 

Limitations:

 

-

 

 

See also:

 

  Save_Key