<< Click to Display Table of Contents >> Navigation: 3. Script Language > AI - Artificial Intelligence Commands > AI - Artificial Intelligence Commands |
MiniRobotLanguage (MRL)
How to start with AI and the Smart Package Robot
Combine AI's in your Script
Let's use the AI abilities from the smart package robot to make a new script where we are combining several AI features into one script.
1. Make a new Project
This is your New Project Folder when we start
2. From now I assume that you have already saved all your API keys with the Smart Package Robot in the internal folder.
So we can just start and write:
' This Line will prevent our API-Key to be included in a compiled executable
'#SPI:NoAPIKey
' We will use ChatGPT and WHISPER from Open AI
AIC.Set Key|File
' And we will use ElevenLabs Speech Syntesis here
AIS.Set Key|File
' Number of Phrases to get from AI
VIN.$$NUM=50
' Language we want to learn
$$LAN=Spanish
' The language for the translation
$$TAL=english
' Difficulty (How many words a phrase can have)
$$DIF=1 to 3
' This File will be generated from ChatGPT and will contain the Phrases to learn
$$TMP=?path\Myfile.txt
GSB.Get_New
' If number of loaded Lines is <1 something with the AI did not work.
' Need Proxy? Is API-Key valid?
JIV.$$LIZ<1|Error
This is what we get from OpenAI ChatGPT
Split the Lines into pieces
In this part we take randomly a line from the File that the AI has created.
An we split it into the 2 parts, $$LEF = Spanish Text and $$RIG = Translated Text
:Lop
' Get a random Number from 1-Anz. Lines
RND.1|$$NUM|$$LIO
' Pick that Line from the File
TXT.Get Line Trimmed|$$LIO|$$LIN
' Skip empty lines
JNS.$$LIN|Lop
' Remove Number on left side
STR.Remain|$$LIN|.|1|$$ALL
' Split into $$LEF and $$RIG
STR.Split String|$$ALL|,|$$LEF|$$RIG
Talk to the User
In this part we Tell the user what he should say.
:Loa
DBP. We are learning: $$LEF - $$RIG
AIS.Say Text|Please hear the following Text:,
PAU.0.5
AIS.Set Female Voice|1
AIS.Say Text|$$LEF
PAU.1
AIS.Set Female Voice|3
AIS.Say Text|I repeat:,
PAU.0.5
AIS.Set Female Voice|1
AIS.Say Text|$$LEF
PAU.1
AIS.Set Female Voice|3
AIS.Say Text|This Word means:
PAU.0.5
AIS.Set Female Voice|5
AIS.Say Text|$$RIG
AIS.Set Male Voice|4
AIS.Please repeat the word.
Let the User Talk
In this part we use Whisper to let the user say something.
AIC.Set Language for Whisper|Spanish
AIC.Set Positive Prompt|$$LEF
AIC.Dictate Text|$$MYR
VBT.$$MYR|All
VBT.$$MYR|.
VTL.$$MYR
VBT.$$LEF
VTL.$$LEF
Let the User Talk
In this part we use Whisper to let the user say something.
And we check if the user said the right thing.
' This is the Pattern to compare the original spanish Text and the Text the User said.
' We use a Tolerance of 90% due to the usage of characters like ".,-" etc.
VAR.$$PAT={$$LEF&TOLERANT:80}
' We will output the Word/Phrase to learn in the Editors Debugging Window
DBP.It was: $$LEF, You said: $$MYR.
' Here we compare the original spanish phrase and what the user has said.
IVP.$$MYR=$$PAT
' Wort war verstanden
AIS.Set Female Voice|4
AIS.Say Text|Well done!
ELS.
' NewCom is a subprogram that offers the possibility to add user-commands to this Script.
GSB.NewCom
' Wrong word or not understood
AIS.Set Male Voice|4
AIS.Say Text|We should do that again.
' We will do this word/Phrase again
GTO.Loa
EIF.
GTO.Lop
ENR.
Add User-Commands to the Script
In this part i will show a way how to add User-Commands to a Script.
' analyze if the last input was a user-command
:NewCom
$$COA=get new words
$$COB=repeat
$$COC=end
SCS.$$MYR
CAS.$$COA
' User-Command "New Words"
GSB.Get_New
CAS.$$COB
' We will do that anyway
CAE.
GTO.Lab_out
ESC.
:Lab_out
RET.
Add User-Commands to the Script
In this part i will create the Prompt for ChatGPT and ask ChatGPT to generate our list for learning.
To keep our costs low, we will skip this step if a list-file already exists.
:Get_New
' Do not generate a new file if we have one already.
IEF.$$TMP
GTO.Load
EIF.
' This is the prompt we use
' Note the new feature "+" to append to a variable
$$PRO=I want to learn a new language that is $$LAN
$$PRO+ I want you to teach me the $$NUM most used Phrases in $$LAN
$$PRO+ First make a list with the $$NUM most used phrases, each phrase of at least $$DIF words.
$$PRO+ The format of the list should be like this: "¿De dónde eres?,Where are you from?"
$$PRO+ The first part before the comma is in $$LAN the second part after the comma is in $$TAL$crlf$
$$PRO+ Do not write variables: "Soy de [país]. (I'm from [country].)"
$$PRO+ instead write real words like "Soy de Germania.,I'm from Germany."
' This will effectvely call ChatGPT with the prompt
GSB.Ask
' Check for empty output from AI (in case of errors with API Key)
JNS.$$RET|Error
' Copy the words List to the File.
CTF.$$TMP|$$RET
' Here we load the file into Memory so we do not need to access the harddisk from now
:Load
TXT.Load Text File|$$TMP|$$LIZ
RET.
Call ChatGPT and the Error-Handler
Here call ChatGPT and receive the answer.
:Ask
AIC.SetModel Completion|0
' Ask Question and receive answer to $$RET
AIC.Ask_Completion|$$PRO|$$RET
RET.
'-----------------------------------------------------------
:Error
MBX.an Error happened.
ENR.
'-----------------------------------------------------------
This is the complete Script "Vocabulary Trainer"
'#SPI:NoAPIKey
AIC.Set Key|File
AIS.Set Key|File
VIN.$$NUM=50
$$LAN=Spanish
$$TAL=english
$$DIF=1 to 3
$$TMP=?path\Myfile.txt
GSB.Get_New
' If number of loaded Lines is <1
JIV.$$LIZ<1|Error
:Lop
' Get a random Number from 1-Anz. Lines
RND.1|$$NUM|$$LIO
' Pick that Line from the File
TXT.Get Line Trimmed|$$LIO|$$LIN
' Skip empty lines
JNS.$$LIN|Lop
STR.Remain|$$LIN|.|1|$$ALL
STR.Split String|$$ALL|,|$$LEF|$$RIG
:Loa
DBP. We are learning: $$LEF - $$RIG
AIS.Say Text|Please hear the following Text:,
PAU.0.5
AIS.Set Female Voice|1
AIS.Say Text|$$LEF
PAU.1
AIS.Set Female Voice|3
AIS.Say Text|I repeat:,
PAU.0.5
AIS.Set Female Voice|1
AIS.Say Text|$$LEF
PAU.1
AIS.Set Female Voice|3
AIS.Say Text|This Word means:
PAU.0.5
AIS.Set Female Voice|5
AIS.Say Text|$$RIG
AIS.Set Male Voice|4
AIS.Please repeat the word.
AIC.Set Language for Whisper|Spanish
AIC.Set Positive Prompt|$$LEF
AIC.Dictate Text|$$MYR
VBT.$$MYR|All
VBT.$$MYR|.
VTL.$$MYR
VBT.$$LEF
VTL.$$LEF
VAR.$$PAT={$$LEF&TOLERANT:80}
DBP.It was: $$LEF, You said: $$MYR.
IVP.$$MYR=$$PAT
' Wort war verstanden
AIS.Set Female Voice|4
AIS.Say Text|Well done!
ELS.
GSB.NewCom
' Falsches Wort oder nicht verstanden
AIS.Set Male Voice|4
AIS.Say Text|We should do that again.
GTO.Loa
EIF.
GTO.Lop
ENR.
'-----------------------------------------------------------
' Sprachcommandos auswerten
:NewCom
$$COA=get new words
$$COB=repeat
$$COC=end
SCS.$$MYR
CAS.$$COA
GSB.Get_New
CAS.$$COB
' We will do that anyway
CAE.
GTO.Lab_out
ESC.
:Lab_out
RET.
'-----------------------------------------------------------
:Get_New
IEF.$$TMP
GTO.Load
EIF.
$$PRO=I want to learn a new language that is $$LAN
$$PRO+ I want you to teach me the $$NUM most used Phrases in $$LAN
$$PRO+ First make a list with the $$NUM most used phrases, each phrase of at least $$DIF words.
$$PRO+ The format of the list should be like this: "¿De dónde eres?,Where are you from?"
$$PRO+ The first part before the comma is in $$LAN the second part after the comma is in $$TAL$crlf$
$$PRO+ Do not write variables: "Soy de [país]. (I'm from [country].)"
$$PRO+ instead write real words like "Soy de Germania.,I'm from Germany."
GSB.Ask
' Check for empty output from AI (in case of errors with API Key)
JNS.$$RET|Error
' Copy the words List to Tempfile.
CTF.$$TMP|$$RET
:Load
TXT.Load Text File|$$TMP|$$LIZ
RET.
'-----------------------------------------------------------
:Error
MBX.an Error happened.
ENR.
'===========================================================
:Ask
AIC.SetModel Completion|0
' Ask Question and receive answer to $$RET
AIC.Ask_Completion|$$PRO|$$RET
RET.
See also:
•