ai is the shell CLI command to manage the brain(LLM) files and run a PPE script mainly.
- Run script file command
ai run, eg,ai run -f calculator.ai.yaml "{content: '32+12*53'}"-fis used to specify the script file.{content: '32+12*53'}is the optional json input to the script.- Scripts will display intermediate echo outputs during processing when streaming output. This can be controlled with
--streamEcho true|line|false. To keep the displayed echo outputs, use--no-consoleClear. - Script can be single YAML file (
.ai.yaml) or directory.- Directory must have an entry point script file with the same name as the directory. Other scripts in the directory can call each other.
- Manage the brain files command
ai brainincludeai brain download,ai brain list/search. - Run
ai helporai help [command]to get more.
Programmable Prompt Engine (PPE) Language is a message-processing language, similar to the YAML format.
PPE is designed to define AI prompt messages and their input/output configurations. It allows for the creation of a reusable and programmable prompt system akin to software engineering practices.
- Message-Based Dialogue: Defines interactions as a series of messages with roles (system, user, assistant).
- YAML-Like: Syntax is similar to YAML, making it readable and easy to understand.
- Dialogue Separation: Uses triple dashes (
---) or asterisks (***) to clearly mark dialogue turns.
- Input/Output Configuration (Front-Matter): Defines input requirements (using
inputkeyword) and expected output format (usingoutputkeyword with JSON Schema). - Prompt Template: Embeds variables from input configuration or prompt settings into messages using Jinja2 templates (
{{variable_name}}). - Custom Script Types: Allows defining reusable script types (
type: type) for code and configuration inheritance.
- Advanced AI Replacement: Use double brackets (
[[Response]]) to trigger AI execution, store the response in a variable (prompt.Response), and use it within the script. - AI Parameter Control: Fine-tune AI behavior by passing parameters within double brackets (e.g.,
[[Answer:temperature=0.7]]). - Constrained AI Responses: Limit AI outputs to a predefined set of options (e.g.,
[[FRUITS:|Apple|Banana]]).
The role messages can be formatted using Jinja2 templates and advanced replacement features.
- Jinja2 Templates: Reference variables from input configuration or prompt settings using double curly braces (e.g.,
{{name}}). - Advanced AI Replacement: As described above, triggers AI execution and stores the response.
- External Script Replacement: Invoke external scripts using the
@symbol (e.g.,[[@say_hi_script(param1=value1)]]). - Internal Instruction Replacement: Call internal instructions similarly (e.g.,
[[@$instruction(param1=value1)]]). - Regular Expression Replacement: Use
/RegExp/[RegOpts]:Answer[:index_or_group_name]for pattern-based replacement on theAnswervariable.
- Chaining Outputs: The
->operator connect script outputs to subsequent instructions or scripts, creating complex workflows. - Instruction Invocation: The
$prefix calls script instructions (e.g.,$fn: {param1:value1}). - Control Flow: Directives like
$if,$while,$for,$matchprovide control flow mechanisms. - Event-Driven Architecture: Functions like
$on,$once,$emitand$offenable event-based programming for flexible script behavior. - JavaScript Extension: The
!fndirective allows declaring JavaScript functions to extend script functionality.
- Streaming Output: PPE scripts use streaming output by default for LLM responses.
- Auto LLM Execution: If a script contains prompt messages (
system,user) and the LLM ($AI) hasn't been invoked, PPE will automatically call the LLM at the end. - Final Instruction Output: The output of the last instruction in a script determines the script's final return value.
A series of examples are provided in the examples directory for the language learning.
calculator.ai.yaml:
---
# Below is the input/output configuration
input:
# defaults to string if without `type`
- content:
required: true
output:
- type: "string"
# The default value of input
content: "What is 10 + 18?"
---
# Below is the script content
system: "You are a calculator. Output result only."
user: "{{content}}"
assistant: "[[Answer]]"Run it:
ai run -f calculator.ai.yaml "{content: '32+12*53'}"
668PPE provides a series of built-in libraries in the lib directory for common tasks. These libraries can also be regarded as code examples of the language.