Skip to content

Commit

Permalink
Add syntax reference
Browse files Browse the repository at this point in the history
  • Loading branch information
klntsky committed Nov 14, 2024
1 parent 217c501 commit f24b25f
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 15 deletions.
6 changes: 4 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,15 @@ Quick example:

A module system and a package system enable parameterized prompt reuse and publishing.

`hello.metaprompt`:

```metaprompt
# hello.metaprompt:
Hello, [:what]!
```

`main.metaprompt`:

```metaprompt
# main.metaprompt:
[:use ./hello :what=world]
```

Expand Down
51 changes: 38 additions & 13 deletions docs/syntax.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Text

A prompt is usually a valid metaprompt:
A textual prompt is usually a valid metaprompt:

```metaprompt
Hi, LLM! How are you feeling today?
Expand All @@ -16,8 +16,8 @@ Here's a variable: [:variable_name].
If a variable is used before first assignment, it is treated as a required
prompt parameter automatically.
[:variable_name=it can be reassigned to any value, however.
Including a value containing its old value: [:variable_name] or referencing [:other] variables]
[:variable_name=it can be reassigned to any value, however]
[:variable_name=Including a value containing its old value: [:variable_name]]
```

# Comments
Expand All @@ -40,47 +40,72 @@ Including a value containing its old value: [:variable_name] or referencing [:ot
:then this...
:else that...
]
```

[# ^ This expression will be expanded at runtime.
`:if` expressions will be expanded at runtime.

First, the following text will be fed to an LLM:

```
Please determine if the following statement is true.
Do not write any other output, answer just "true" or "false".
The statement: the sky is sometimes blue
```

The answer will determine the execution branch.
If the answer is not literally "true" or "false",
an exception will be thrown after a few retries
]
```

# Meta-prompting

```metaprompt
LLM says: [$ Hi, LLM! How are you today?]
[# ^^^ this prompt will be executed and its output will be inserted
at its position during expansion ]
```

A more inspiring example:
The `[$` prompt will be executed and its output will be inserted
at its position during expansion. This enables powerful techniques
of prompt rewriting:

```metaprompt
[$ Improve this LLM prompt: [:prompt]]
[$ [$ Improve this LLM prompt: [:prompt]]]
```

Notice the double nesting of `[$` - the improved prompt will be fed back into an LLM.

# Modules

Every `.metaprompt` file is a function.

Unbound variables used in a file are its parameters, that must be provided.

```metaprompt
Hello, [:what]! [# `what` is a parameter ]
[:who=you] [# `who` is NOT a parameter, because it is assigned before first use]
How are [:who] feeling today?
```

## File imports

This expression will include `./relative-import.metaprompt` file (relative to the directory of the file, NOT to the current working dir).

```metaprompt
[:use ./relative-import]
[:use package-name/directory/module]
```

With parameters:
## Package imports

**NOT IMPLEMENTED**

## Passing parameters

```
[:use ./relative-import
:someParameter= arbitrary value, potentially using
any other MetaPrompt constructs
:otherParameter= another value
]
```

## Special variables

- `MODEL` - used to determine active LLM id.
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ markdown_extensions:

nav:
- Home: index.md
- Syntax: syntax.md
# - Getting Started:
# - Introduction: getting_started/introduction.md
# - Installation: getting_started/installation.md
Expand Down

0 comments on commit f24b25f

Please sign in to comment.