Examplary is an example-oriented DSL that can be used to construct and compose functions based on prompts and external String->String commands.

Using examplary, one can keep track of their various String->String functions but also:

  • generate prompts from an example generator
  • design prompts using design patterns
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
fifth-generation programming language
5GL
    Any programming language based on problem
    solving using constraints given to the
    program, rather than using an algorithm
    written by a programmer.

    Most constraint-based and logic
    programming languages and some other
    declarative languages are fifth-generation
    languages.

Emacs-lisp implementation

Generate input with :gen when example input is not present.

Use shell or emacs lisp for generators and filters.

1
2
3
4
5
6
7
8
(defprompt ("lines of code" regex)
  :task "Convert lines to regex"
  :gen "examplary-edit-generator shane"
  :filter "grex"
  :examples '(("example 1\nexample2")
              ("example 2\nexample3" "^example [23]$")
              ("pi4\npi5" "^pi[45]$" "pi4\npi5"))
  :lm-command "openai-complete.sh")

With regards to the list of examples, the third argument (if supplied) should be incorrect output (a counterexample).

If the 2nd argument is left out, it will be generated by the command specified by :external.

Leave out :task to have it inferred.

1
2
3
4
5
6
7
(defprompt ("lines of code" regex)
  :gen 'examplary-edit-generator
  :filter "grex"
  :examples '(("example 1\nexample2")
              ("example 2\nexample3" "^example [23]$")
              ("pi4\npi5" "^pi[45]$" "pi4\npi5"))
  :lm-command "openai-complete.sh")

Even leave out :gen to have it inferred from tthe variable name.

1
(defprompt ("short lines of code" regex) :filter "grex")

Clojure implementation

Here are some examples:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
(def lines->regex
  :e "grex"
  "example 1\nexample2" "^example [12]$"
  "example 2\nexample3" "^example [23]$"
  "pi4\npi5" "^pi[45]$")

(def topic->analogy
  ;; Each line is a training example.
  "Neural networks" "Neural networks are like genetic algorithms in that both are systems that learn from experience"
  "Social media" "Social media is like a market in that both are systems that coordinate the actions of many individuals.")

(def topic->field-of-study
  "chemistry" "study of chemicals"
  "biology" "study of living things")

(def cron->natural-language
  :e "interpret-crontab"
  "17 *	* * *" "At minute 17."
  "25 6	* * *" "At 06:25."
  "47 6	* * 7" "At 06:47 on Sunday."
  "52 6	1 * *" "At 06:52 on day-of-month 1.")
syntax description
:g external generator command
:i specifies a source of input (training) strings from a jsonl file
:o specifies an output file for outputting jsonl
external generator command
specifies an external [pipable] command which can generate examples or as a source of truth for query reformulation (when generating prompts)