Control flow
Set Variable
Creates or sets a variable that can be used later in the NTL expression. For example,
Parameters
- Name: The name of the variable to set.
- Value: The optional (override) value to set to the variable.
No Returns
Use Variable
Syntax to use / expand a variable into the environment.
Parameters
- Name: The name of the variable
- Prompt: If set to true, the UI will prompt for the value for this variable. If set to false, the UI will avoid prompting for this variable.
Returns
- The contents of the variable.
Note about variables
When the variable is NOT found but used in << >> notation, the variable is considered as user input, and mAIstro will prompt for the value prior to evaluation.
For example, if you have << name: new >>
or << name: new, prompt: true >>
and there is not such thing as {{ variable|name: "new" }}
in the expression, mAIstro will ask for it like this:
Stop
Stops all further processing. Full stop.
Loops: Start, End, Break
Start Loop
Denotes the beginning of a loop, and declares the maximum number of loops to perform.
End Loop
Denotes the end of a loop. This does not stop the loop, but rather sends the execution back to the beginning if the total number of loops have not yet been reached.
Break Loop
Stops a loop early. Useful with the condition node.
Example Usage
{{ variable | name: "count" | mode: "" | value: "0" }}
{{ startLoop | count: "5" }}
{{ math | equation: "<< name: count >> + 1" }}=>{{ variable | name: "count" }}
{{ endLoop }}
The count is now: << name: count >>
Will Yield:
Note
The number of loops assigned in startLoop
is the number of additional times the nodes will be executed. As seen above, the middle node (math) will be executed a total of 6 times - Once to begin, and then 5 more times (the number of loops set).
Variable Loop
The Variable Loop function allows us to loop arrays, nested arrays, or JSON objects. You can use this feature to format arrays nicely or to take action on the contents during each loop.
Example Usage 1
{"looper": ["a","b","c"]}=>{{ jsonToVars }}
{{ variableLoop | variable: "looper" | loopType: "" }}
was the passed input.
{{ variable | name: "myVar" | mode: "append" }}
{{ endLoop }}
<< name: myVar, prompt: false >>
Will yield:
Example Usage 2
{"messages": [
{
"message": "Hello, how can I assist you today?",
"sender": "Assistant",
"timestamp": "2023-04-12T10:30:00Z"
},
{
"message": "I'm doing well, thanks for asking. How can I help you?",
"sender": "User",
"timestamp": "2023-04-12T10:30:15Z"
},
{
"message": "I'm afraid I don't have a specific task for you at the moment. I'm just here to chat and help out however I can.",
"sender": "Assistant",
"timestamp": "2023-04-12T10:30:30Z"
},
{
"message": "That's great, I appreciate your availability. I was wondering if you could help me with a project I'm working on.",
"sender": "User",
"timestamp": "2023-04-12T10:30:45Z"
},
{
"message": "Absolutely, I'd be happy to assist you with your project. Please go ahead and provide me with the details, and I'll do my best to help.",
"sender": "Assistant",
"timestamp": "2023-04-12T10:31:00Z"
}
]}=>{{ jsonToVars }}
{{ variableLoop | variable: "messages" | loopType: "array-objects" }}
[<< name: loopObject.timestamp, prompt: false >>] << name: loopObject.sender, prompt: false >>: << name: loopObject.message, prompt: false >>
{{ variable | name: "messagesFormatted" | mode: "append" }}
{{ endLoop }}
<< name: messagesFormatted, prompt: false >>
Will yield:
[2023-04-12T10:30:00Z] Assistant: Hello, how can I assist you today?
[2023-04-12T10:30:15Z] User: I'm doing well, thanks for asking. How can I help you?
[2023-04-12T10:30:30Z] Assistant: I'm afraid I don't have a specific task for you at the moment. I'm just here to chat and help out however I can.
[2023-04-12T10:30:45Z] User: That's great, I appreciate your availability. I was wondering if you could help me with a project I'm working on.
[2023-04-12T10:31:00Z] Assistant: Absolutely, I'd be happy to assist you with your project. Please go ahead and provide me with the details, and I'll do my best to help.
Video Loop
The Video Loop function allows us to process videos by extracting and looping through individual frames. This is particularly useful when you need to analyze specific moments from a video, generate frame-based insights, or create frame-by-frame descriptions using AI models.
Example Usage 1
{{ variable | name: "instructions" | value: "This picture is a frame from a video of a person knitting. Your job is to describe in detail the breakdancer's each of the objects in the frame describing each of them
" | mode: "overwrite" }}
{{ videoLoop | video: "" | url: "https://www.pexels.com/download/video/29890007" | fps: "0.31000000000000005" | framesPerLoop: "5" }}
{{ condition | value: "'<< name: videoLoopImage0, prompt: false >>' != ''" }}=>{{ LLM | prompt: "<< name: instructions, prompt: false >>" | cache: "false" | images: "<< name: videoLoopImage0, prompt: false >>" }}=>{{ variable | name: "frame0" | mode: "overwrite" }}
{{ condition | value: "'<< name: videoLoopImage1, prompt: false >>' != ''" }}=>{{ LLM | prompt: "<< name: instructions, prompt: false >>" | cache: "false" | images: "<< name: videoLoopImage1, prompt: false >>" }}=>{{ variable | name: "frame1" | mode: "overwrite" }}
{{ condition | value: "'<< name: videoLoopImage2, prompt: false >>' != ''" }}=>{{ LLM | prompt: "<< name: instructions, prompt: false >>" | cache: "false" | images: "<< name: videoLoopImage2, prompt: false >>" }}=>{{ variable | name: "frame2" | mode: "overwrite" }}
{{ condition | value: "'<< name: videoLoopImage3, prompt: false >>' != ''" }}=>{{ LLM | prompt: "<< name: instructions, prompt: false >>" | cache: "false" | images: "<< name: videoLoopImage3, prompt: false >>" }}=>{{ variable | name: "frame3" | mode: "overwrite" }}
{{ condition | value: "'<< name: videoLoopImage4, prompt: false >>' != ''" }}=>{{ LLM | prompt: "<< name: instructions, prompt: false >>" | cache: "false" | images: "<< name: videoLoopImage4, prompt: false >>" }}=>{{ variable | name: "frame4" | mode: "overwrite" }}
{{ condition | value: "'<< name: videoLoopImage0, prompt: false >>' != ''" }}=>
Frame: << name: videoLoopFrame0, prompt: false >>
<< name: frame0, prompt: false >>=>{{ variable | name: "frameTotal" | mode: "append" }}
{{ condition | value: "'<< name: videoLoopImage1, prompt: false >>' != ''" }}=>
Frame: << name: videoLoopFrame1, prompt: false >>
<< name: frame1, prompt: false >>=>{{ variable | name: "frameTotal" | mode: "append" }}
{{ condition | value: "'<< name: videoLoopImage2, prompt: false >>' != ''" }}=>
Frame: << name: videoLoopFrame2, prompt: false >>
<< name: frame2, prompt: false >>=>{{ variable | name: "frameTotal" | mode: "append" }}
{{ condition | value: "'<< name: videoLoopImage3, prompt: false >>' != ''" }}=>
Frame: << name: videoLoopFrame3, prompt: false >>
<< name: frame3, prompt: false >>=>{{ variable | name: "frameTotal" | mode: "append" }}
{{ condition | value: "'<< name: videoLoopImage4, prompt: false >>' != ''" }}=>
Frame: << name: videoLoopFrame4, prompt: false >>
<< name: frame4, prompt: false >>=>{{ variable | name: "frameTotal" | mode: "append" }}
{{ endLoop }}
{{ LLM | prompt: "You will be given descriptions of frames from a person knitting video. Take this series of described frames and determine all the objects present in the video with their descriptions.
Here are the frames:
<< name: frameTotal, prompt: false >>" | cache: "true" | maxTokens: "3000" }}
Will yield:
Hands - The hands of the person knitting or crocheting are the main focus in all the frames.
Knitting needles/Crochet hooks - The person is using either knitting needles or crochet hooks to create the textile project.
Yarn/Thread - The person is manipulating yarn or thread to create the knitted or crocheted item.
Textile project - In each frame, the person is working on a knitted or crocheted textile project, such as a piece of fabric, a square, or an unfinished item.
Cup/Mug - In most frames, there is a cup or mug on the table, containing what appears to be tea, coffee, or a red beverage like wine.
Table - The knitting or crocheting is taking place on a table or other surface.
Couch/Soft surface - In one frame, the knitting or crocheting is taking place on a couch or other soft surface.
The overall scene depicts a relaxing, cozy activity of knitting or crocheting, with the person focused on the needlework and enjoying a warm beverage.
PDF Loop
The PDF Loop function allows us the processing of PDF files on a page-by-page basis. This feature extracts the content of each page individually and stores it in the pdfLoopText0
variable. The extracted text can then be utilized for further processing, such as making LLM calls.
Example Usage 1
{{ variable | name: "instructions" | value: "Summarize the provided text into 5 concise bullet points that capture the main ideas. Do not include explanations or add any information that isn’t in the original text. Your response should only contain the text itself, formatted appropriately. Do not interpret or explain the content." }}
{{ pdfLoop | file: "somatosensory.pdf" | pagesPerLoop: "1" }}
{{ LLM | prompt: "<< name: instructions, prompt: false >>
<< name: pdfLoopText0, prompt: false >>" | cache: "false" }}=>{{ variable | name: "output" | mode: "append" | value: "" }}
{{ endLoop }}
{{ LLM | prompt: "Each section of the text below corresponds to a page in a pdf. Format it correctly listing the bullet points for each section.
<< name: output, prompt: false >>" | cache: "true" }}
Will yield:
Page 1:
The somatosensory system consists of sensors in the skin, muscles, tendons, and joints.
Cutaneous receptors in the skin provide information about temperature, pressure, texture, and pain.
Receptors in muscles and joints provide information about muscle length, tension, and joint angles.
Meissner corpuscles and rapidly adapting afferents help adjust grip force when lifting objects.
The skin contains various types of mechanoreceptors, both free receptors and encapsulated receptors.
Page 2:
Mammalian muscle spindles have sensory endings that detect stretch and provide feedback for motor control.
Rapidly adapting afferent activity from touch receptors triggers reflexive muscle force increases.
Slowly adapting Merkel's receptors mediate form and texture perception, with higher density in digits and around the mouth.
Pacinian corpuscles detect vibration, while Ruffini corpuscles respond to lateral skin movement or stretching.
Nociceptors are free nerve endings that detect high-threshold mechanical or thermal stimuli as pain.
Page 3:
Rapidly adapting and slowly adapting surface receptors (e.g., hair receptors, Meissner's corpuscle, Merkel's receptor) detect different types of mechanical stimuli.
Deep receptors with large receptive fields (e.g., Pacinian corpuscle, Ruffini's corpuscle) detect diffuse vibrations and skin stretch.
Polymodal receptors respond to intense mechanical, thermal, and chemical stimuli, and transmit pain signals.
Pain signals can be separated into different components (first pain, second pain, deep pain) based on transmission speed and localization.
Muscle spindles are stretch receptors scattered throughout striated muscles, consisting of intrafusal fibers attached to extrafusal fibers.
Page 4:
Force control signal
Length control signal
Load and external forces
Tendon organs and muscle force/length feedback
Muscle spindles and joint receptors
Condition
The Conditional function allows us to direct the flow of operations.
Parameters
- Value: The conditional / logic to evaluate. Supports the following:
- Common comparison operators like
==
,!=
,>
,<
,>=
,<=
,<>
. - Common mathematical operators like
+
,-
,/
,*
wrapped within parenthesis()
. - Logical functions:
- IF: Ternary operator:
IF(condition or function, truevalue, falsevalue)
- NOT: Inverse operator:
NOT(condition)
- AND: Logical and:
AND(condition, condition)
- Accepts 2 or more conditions - OR: Logical or:
OR(condition, condition)
- Accepts 2 or more conditions
- IF: Ternary operator:
- String comparisons:
- Using single-quoted strings, you can use equality conditions
==
and!=
. - CONTAINS: You can check for substrings:
CONTAINS('long string to check', 'string')
- LENGTH: You can evaluate the length of a string to use in conditions:
LENGTH('string')
(this example evaluates to 6) - Variables must be wrapped in single quotes for comparison or substring check.
- Using single-quoted strings, you can use equality conditions
Returns
No returns, however:
- A condition that evaluates to 'true' will continue the horizontal chain.
- A condition that evaluates to 'false' will stop the horizontal chain from executing and continue to the next flow step.
Example usage
Example set 1: Basic
Will yield the output text: This is true!
Will yield the output text: This is true!
Example set 2: OR, AND
Will continue the chain and yield the output text: This is true!
.
Will continue the chain and yield the output text: This is true!
.
Will stop the chain and yield no output, as the chain was blocked with a false condition.
Example set 3: Strings
Will yield the output text: This is true!
{{ condition | value: "CONTAINS('<< name: variableContainingTest, prompt: false >>', 'test')" }}=>This is true!
Both will yield the output text: This is true!
Will yield the output text: This is true!
{{ condition | value: "(LENGTH('<< name: variableContainingTest, prompt: false >>') + 12) > 10" }}=>This is true!
Will yield the output text: This is true!
For more: See the "Conditional Logic" Example Template for a working example on routing chains based on a variable value: