0.0.1 • Published 2 years ago

@ouija/ouija v0.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Ouija

For anyone reading this: you're early to the party. This is still work in progress.

Ouija is a language and CLI tool for prompt design. It is based on Markdown and features an approachable syntax that closes the gap between code and natural language.

Requirements

Ouija requires that you have NodeJS installed.

Usage

You can invoke the CLI tool by running the following command in your terminal:

npx @ouija/cli ./prompt.md

Syntax

Ouija is easy to pick up, since it is just an extension of Markdown. Blockquotes are treated as [comments] and are omitted from the final prompt. [Directives] are instructions to Ouija interpreter.

# This is a heading

This is a paragraph of text about {{ topic }}.

> This is a comment.

::print[This is a directive]

Now you know how to read Ouija! But the power of Ouija really comes from the way that the markdown is interpreted and composed into modular, reusable and scalable architectures. Keep reading.

Directives

Directives are commands to the Ouija interpreter that usually manipulate the [context] or invoke completions.

A directive may accept a single string argument...

::use[./file.md]

...and/or a { key=value } object with additional parameters after the closing bracket.

::use[./file.md]{ some=param }

A directive can have many methods separated by a colon.

::print:info[This will be printed in blue text]
::print:warn[This will be printed in orange text]

Most importantly, directives are extendable. You can easily [create your own directives] and install them by invoking the install directive:

export default defineDirective({
  name: 'hello',
  methods: {
    async default (node, ctx) {
      // TODO:
    }
  }
})
::install[./HelloDirective.ts]
::hello[world]

Staging your prompt

Ouija always works against a stage. Think of the stage as an in-progress prompt that can be appended manipulated before being invoked by the LLM.

@ouija/cli will load markdown files add each paragraph to the stage. In the process, directives may be invoked that manipulate the current stage. For example, the ::use directive imports text from a file and adds it to the current stage.

::use[./Questions.md]

Please answer the aforementioned questions.

Here's a more advanced example where the consume directive is used to replace the current stage with a summary. We then stash the summary to give us a clean slate, write some new instructions and re-apply the stashed summary.

> import the recipe
::use[./Recipe.md]

Please list all the ingredients i this recipe.

> summarize and stash the stage
::yield:consume
::stage:stash

What is the extimated calorie count of the following ingredients?

> re-insert the old stage (the summary of the recipe)
::stage:apply

Although a simple example, it demonstrates how we can rearrange the stage and compose a series of instructions in a flexible way to yield the desired prompt.

Yield

You can use the yield directive to invoke an LLM programmatically.

::yield:complete (or simply ::yield)

Invokes a completion that takes the current stage as it's input and appends the output to the current stage.

::yield:consume

Invokes a completion that takes the current stage as it's input and replaces the current stage.

Use

The use directive is used to load documents into the current Ouija session.

::use[path/to/file]

Loads the text content of a markdown file.

::use:leaf[path/to/file#heading]{ headings=include }

Only inserts the text nested under a specific heading. Headings with a lower hierarchy are also included.

::use:trunk[path/to/file#heading]{ headings=include }

Inserts the text nested under a specific heading and all parent headings.

Frontmatter