Skip to content

Commit

Permalink
refactor!: add guide as AI App
Browse files Browse the repository at this point in the history
  • Loading branch information
snowyu committed Aug 31, 2024
1 parent 714e06c commit c0d0e0b
Show file tree
Hide file tree
Showing 12 changed files with 232 additions and 34 deletions.
30 changes: 15 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ $ npm install -g @offline-ai/cli
$ ai COMMAND
running command...
$ ai (--version)
@offline-ai/cli/0.3.8 linux-x64 node-v20.14.0
@offline-ai/cli/0.3.9 linux-x64 node-v20.14.0
$ ai --help [COMMAND]
USAGE
$ ai COMMAND
Expand Down Expand Up @@ -394,7 +394,7 @@ EXAMPLES
$ ai agent publish <agent-name>
```

_See code: [src/commands/agent/index.ts](https://github.com/offline-ai/cli/blob/v0.3.8/src/commands/agent/index.ts)_
_See code: [src/commands/agent/index.ts](https://github.com/offline-ai/cli/blob/v0.3.9/src/commands/agent/index.ts)_

## `ai autocomplete [SHELL]`

Expand Down Expand Up @@ -429,7 +429,7 @@ _See code: [@oclif/plugin-autocomplete](https://github.com/oclif/plugin-autocomp

## `ai brain [NAME]`

🧠 The AI Agent Brains(LLM) Manager.
🧠 The AI Brains(LLM) Manager.

```
USAGE
Expand All @@ -453,10 +453,10 @@ GLOBAL FLAGS
--json Format output as json.
DESCRIPTION
🧠 The AI Agent Brains(LLM) Manager.
🧠 The AI Brains(LLM) Manager.
Manage AI Agent brains 🧠 here.
Manage AI brains 🧠 here.
📜 List downloaded or online brains
🔎 search for brains
📥 download brains
Expand All @@ -473,7 +473,7 @@ _See code: [@offline-ai/cli-plugin-cmd-brain](https://github.com/offline-ai/cli-

## `ai brain dn [NAME]`

🧠 The AI Agent Brains(LLM) Downloader.
🧠 The AI Brains(LLM) Downloader.

```
USAGE
Expand All @@ -500,7 +500,7 @@ GLOBAL FLAGS
--json Format output as json.
DESCRIPTION
🧠 The AI Agent Brains(LLM) Downloader.
🧠 The AI Brains(LLM) Downloader.
📥 download 🧠 brains to brainDir.
Expand All @@ -516,7 +516,7 @@ EXAMPLES

## `ai brain down [NAME]`

🧠 The AI Agent Brains(LLM) Downloader.
🧠 The AI Brains(LLM) Downloader.

```
USAGE
Expand All @@ -543,7 +543,7 @@ GLOBAL FLAGS
--json Format output as json.
DESCRIPTION
🧠 The AI Agent Brains(LLM) Downloader.
🧠 The AI Brains(LLM) Downloader.
📥 download 🧠 brains to brainDir.
Expand All @@ -559,7 +559,7 @@ EXAMPLES

## `ai brain download [NAME]`

🧠 The AI Agent Brains(LLM) Downloader.
🧠 The AI Brains(LLM) Downloader.

```
USAGE
Expand All @@ -586,7 +586,7 @@ GLOBAL FLAGS
--json Format output as json.
DESCRIPTION
🧠 The AI Agent Brains(LLM) Downloader.
🧠 The AI Brains(LLM) Downloader.
📥 download 🧠 brains to brainDir.
Expand Down Expand Up @@ -1171,7 +1171,7 @@ _See code: [@offline-ai/cli-plugin-core](https://github.com/offline-ai/cli-plugi

## `ai test`

🔬 Run simple ai-agent fixtures to test(draft).
🔬 Run simple AI fixtures to test(draft).

```
USAGE
Expand All @@ -1192,7 +1192,7 @@ FLAGS
-d, --dataFile=<value> the data file which will be passed to the ai-agent script
-e, --streamEcho=<option> [default: true] stream echo mode, defaults to true
<options: true|false|line>
-f, --script=<value> the ai-agent fixture file path
-f, --script=<value> the AI fixture file path
-h, --histories=<value> the chat histories folder to record
-i, --[no-]interactive interactive mode
-k, --backupChat whether to backup chat history before start, defaults to false
Expand All @@ -1215,9 +1215,9 @@ GLOBAL FLAGS
--json Format output as json.
DESCRIPTION
🔬 Run simple ai-agent fixtures to test(draft).
🔬 Run simple AI fixtures to test(draft).
Execute fixtures file to test ai-agent script file and check result.
Execute fixtures file to test AI script file and check result.
EXAMPLES
$ ai test -f ./fixture.yaml -l info
Expand Down
24 changes: 15 additions & 9 deletions guide/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Programmable Prompt Engine (PPE) Agent Script Guide
# Programmable Prompt Engine (PPE) Script Guide

## [PPE CLI Command](./cli.md)
## [Programmable Prompt Engine(PPE) CLI Command](./cli.md)

`ai` is the shell CLI command to manage the brain(LLM) files and run a PPE agent script mainly.
`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'}"`
* `-f` is used to specify the script file.
Expand All @@ -19,25 +19,25 @@ Programmable Prompt Engine (PPE) Language is a message-processing language, simi

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.

### [I. Core Structure](./core-lang.md)
### [Programmable Prompt Engine Language - Core Structure](./core-lang.md)

* 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.

### [II. Reusability & Configuration](./lang-reuse.md)
### [Programmable Prompt Engine Language - Reusability & Configuration](./lang-reuse.md)

* **Input/Output Configuration (Front-Matter):** Defines input requirements (using `input` keyword) and expected output format (using `output` keyword 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.

### [III. AI Capabilities](./lang-ai.md)
### [Programmable Prompt Engine Language - AI Capabilities](./lang-ai.md)

* **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]]`).

#### [IV. Message Text Formatting](./lang-formatting.md)
#### [Programmable Prompt Engine Language - Message Text Formatting](./lang-formatting.md)

The role messages can be formatted using Jinja2 templates and advanced replacement features.

Expand All @@ -47,7 +47,7 @@ The role messages can be formatted using Jinja2 templates and advanced replaceme
* **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 the `Answer` variable.

### [V. Script Capabilities](./lang-script.md)
### [V. Programmable Prompt Engine Language Script Capabilities](./lang-script.md)

* **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}`).
Expand All @@ -61,7 +61,9 @@ The role messages can be formatted using Jinja2 templates and advanced replaceme
* **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.

## Examples
## [Examples Code Analysis](../examples/)

A series of examples are provided in the `examples` directory for the language learning.

`calculator.ai.yaml`:

Expand Down Expand Up @@ -89,3 +91,7 @@ Run it:
ai run -f calculator.ai.yaml "{content: '32+12*53'}"
668
```

## [Built-in Libraries Code Analysis](../lib/)

PPE 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.
12 changes: 6 additions & 6 deletions guide/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ cd build/bin
./server -t 4 -c 4096 -ngl 33 -m ~/.local/share/ai/brain/your-brain-model.gguf
```

Now you can run your AI agent script:
Now you can run your AI script:

```bash
#you can config the search agent paths in `agentDirs` config or add `-s your_search_path` to argument .
Expand Down Expand Up @@ -154,7 +154,7 @@ EXAMPLES

### `ai brain`

🧠 The AI Agent Brains(LLM) Manager.
🧠 The AI Brains(LLM) Manager.

```
USAGE
Expand All @@ -178,10 +178,10 @@ GLOBAL FLAGS
--json Format output as json.
DESCRIPTION
🧠 The AI Agent Brains(LLM) Manager.
🧠 The AI Brains(LLM) Manager.
Manage AI Agent brains 🧠 here.
Manage AI brains 🧠 here.
📜 List downloaded or online brains
🔎 search for brains
📥 download brains
Expand All @@ -197,7 +197,7 @@ EXAMPLES

## `ai brain download [NAME]`

🧠 The AI Agent Brains(LLM) Downloader.
🧠 The AI Brains(LLM) Downloader.

```
USAGE
Expand All @@ -224,7 +224,7 @@ GLOBAL FLAGS
--json Format output as json.
DESCRIPTION
🧠 The AI Agent Brains(LLM) Downloader.
🧠 The AI Brains(LLM) Downloader.
📥 download 🧠 brains to brainDir.
Expand Down
48 changes: 48 additions & 0 deletions guide/guide.ai.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
version: 0.0.1
name: "Guide"
description: |-
The AI guide for the PPE examples and lib scripts.
autoRunLLMIfPromptAvailable: false
Welcome: |-
I am an AI guide instructor, I will guide you to use Programmable Prompt Engine(PPE) scripts.
IsServerRunning: Please make sure the brain(LLM) server has been started. Are you sure it's running?
---
- !fn# |-
function lang(iso6391) {
return this.languages.find(l => l.value === iso6391)?.name
}
- !fn |-
async function toChoices({files}) {
let result = files.map(f => ({name: f.title, value: f.filepath}))
const target = this.$lang(this.preferLang)
if (this.preferLang !== 'en') {
for (let i = 0; i < result.length; i++) {
const item = result[i]
const trans = await this.$translate({content: item.name, target, lang: 'English'})
item.name = trans.split('\n')[0].trim()
}
}
result.push({name: await this.$translate({content: 'Exit', target, lang: 'English'}), value: 'quit'})
return result
}
- $if: "!this.preferLang"
then:
- $if: "@input(inputType='confirm', content={{Welcome+'\n'+IsServerRunning}}, value=true, format=(answer) => answer ? 'Yes' : 'No')"
then:
- $set:
languages: "@support_langs"
- $set:
preferLang: "@input(inputType='AutoComplete', content='Which language do you prefer?', choices=languages, limit=10)"
- $if: "preferLang !== 'en'"
then:
# - $set:
# ENV.USER_ENV.userPreferredLanguage: ?=preferLang
- $set:
GiveMeGoodBrain: "#I would translate content to {{preferLang | lang}} automatically. \\nBut remember an expert should have a good brain(LLM)."
- -> translator(content=GiveMeGoodBrain, target=preferLang) -> $print
- -> guide_lib_list(file="README.md") -> $set('catalog', content)
- $echo: ?=catalog.summary
# Choose a topic
- -> translator(content=content+"\nPlease select what you want to know:", target=preferLang) -> $set('question')
- -> $toChoices(files=catalog.files) -> input(inputType='AutoComplete', content=question, choices=result, limit=10, memoized=false) -> guide_lib_explain(file=content, lang=preferLang)
13 changes: 13 additions & 0 deletions guide/guide_catalog.ai.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
version: 0.0.1
description: |-
The AI Guide Catalog
input:
- lang
---
- -> guide_lib_list(file="README.md")
# save the catalog into `catalog` variable
- $|set: catalog
- $echo: ?=catalog.summary
# -> translator(target=lang)
# - "$print": "?='\\n🚀 ~ 🚀 ~ 🚀 ~ Hello: ' + catalog.summary"
29 changes: 29 additions & 0 deletions guide/guide_lib_explain.ai.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
version: 0.0.1
type: instructor
name: instructor
description: |-
Explain a file in the guide.
input:
- file
- lang # the target language
file: "README.md"
---
- $if: "this.file === 'quit'"
then:
- user: "Thank you."
- assistant: "Good bye. It was a pleasure speaking with you. About the Programmable Prompt Engine(PPE) Language[[bye]]"
- -> trans(lang, content=messages[messages.length-1].content) -> $ret
- $if: "this.file !== 'README.md'"
then:
- user: |-
@file({{__dirname+file}})
---
Summarize the content in detail, capturing the key points and essence of it.
- assistant: "[[summary:temperature=0.01]]"
- -> trans(lang) -> $print(content)
- -> translator(content="\nDo you have any questions?", target=lang) -> $set('question')
- $if: "@input(inputType='confirm', content=question, memoized=false)"
then:
- -> translator(content="What do you want to know?", target=lang) -> input(memoized=false)
- $echo: "@guide"
45 changes: 45 additions & 0 deletions guide/guide_lib_list.ai.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
version: 0.0.1
type: lib
description: |-
List all urls for the AI Guide
input:
- file
output:
type: 'object'
properties:
summary:
type: 'string'
description: extract the summary part from the content.
files:
type: 'array'
items:
type: 'object'
properties:
filepath:
type: 'string'
description: the file path from the markdown link.
title:
type: 'string'
description: the title from markdown link
description:
type: 'string'
description: the description for the link
instruction: |-
- Summary the key points and essence of it
- Extract all links with title and description base on the markdown links from it
file: "README.md"
---
# - system: |-
# - Summarize the following file provided by the user in detail, capturing the key points and essence of it.
# - Extract all links with title and description base on the markdown links in the file
# - Output JSON format, following the JSON schema:
# {{output}}
# ---
# @file({{__dirname + file}})
# - user: Output all urls with title in markdown format from the README.md
# - assistant: "[[urls:temperature=0.01]]"
# - -> summary(file={{__dirname + file}}, content)
- -> summary(file={{__dirname + file}}, content=instruction) -> json(output=output)
# - $|echo: ["summary", "links[0]"]

Loading

0 comments on commit c0d0e0b

Please sign in to comment.