Summary

I include YASnippet in the prompt generation pipeline to enable programmatic manipulation within a prompt using emacs functions and keyboard macros.

In essence, this gives you the ability to make language agnostic prompts.

This is using GPT-J by EleutherAI, via the AIx API.

Demo

The following is the prompting output. The comment was dynamically generated by YASnippet and the LM generated the line after the comment, which contained a valid regex.

1
2
3
4
5
import re

example = "This jug of water being $8.21 is outrageous!"
# regex to match dollar above.
dollar_re = re.compile(r'\$[0-9]*\.\d{1,3}')

Explanation of problem and solution

The issue

The problem with many prompts you will find online is that they are static and a comment in the prompt, for example //, /* or # will be tailored for a specific language, so the prompt is over-specified.

The solution, using YASnippet

emacs has many editing functions, which are language agnostic and these can be used to generate more powerful, dynamic prompting.

In this example, emacs detects the current major mode (i.e. language) before the prompt is run and then when the prompt template expands, an interactive function comment- line is run to put the correct comment syntax into the prompt.

Why it’s important

Custom tailorded comments are important for code generation from comments, however we may want to generate code from a description where no such comment yet exists.

The dynamic prompt

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
title: gpt-j generate regex
include: Generic completion 50 tokens
prompt-version: 3
# lm-command: "openai-complete.sh"
# model: davinci
lm-command: "aix-complete.sh"
model: GPT-J-6B
# this flag instructs pen-aix to add a newline before the response
# The AIx API appears to remove all beginning whitespace, which may be a bug
flags:
- aix-begin-newline
prompt: |+
  <text><:pp>
  regex to match <thing to match> above`(comment-line 1)`.  
vars:
- text
- thing to match
var-defaults:
- "(pen-preceding-text)"
end-yas: on
# The start will not be trimmed
completion: on