Following on from YASnippet combined with Pen.el - Controllable prompt generation // Bodacious Blog, I make another language-agnostic code generator.
Behind the scenes, this prompt generates the comments describing a code snippet. The comments are in the desired language and the comments are removed from the results.
title: code generator from description
doc: Language agnostic
prompt-version: 1
lm-command: "openai-complete.sh"
model: davinci
# lm-command: "aix-complete.sh"
# model: GPT-J-6B
temperature: 0.3
max-tokens: 200
stop-sequences:
- "###"
top-p: 1
# Unfortunately, it's not yet possible to have a prompt which ends in whitespace.
# It would really help with suggesting the comments have finished.
prompt: |+
Language: `(pen-detect-language)``(comment-line 3)`
Description: The following code is an implementation of <code description>:
Code:
>
vars:
- code description
postprocessor: sed 1,3d | sed "/^[^>]/q" | sed -e "\$d" -e "s/^> *//"
end-yas: on
# The start will not be trimmed
insertion: on
# I guess that this would usually be done manually
continuation-prompt: Generic completion 50 tokensquicksort [] = []
quicksort (x:xs) = (quicksort lesser) ++ [x] ++ (quicksort greater)sub quicksort {
my ($left, $right) = @_;
my $pivot = $_[0];
my $pivotIndex = 0;
for ($left; $left <= $right; $left++) {
if ($left == $pivot) {
$pivotIndex = $left;
} else {
$pivotIndex = ($left + $right) / 2;
}
$left = $pivotIndex;
}
$right = $pivotIndex;
return ($left, $right);
}
print "Enter the array to be sorted: ";
my $array = <STDIN>;
print "Enter the number of elements in the array: ";Unfortunately, I ran out of credits, but I don’t think it worked too well anyway.