Write JavaScript functions but leave out the body. Describe the function's operation in a (currently single-line) comment prefixed by autofn:
. Let ChatGPT do the rest!
Note: This is a proof-of-concept.
import "autofn-runtime";
// autofn: Groups `todos` into `categories`. Then, return todos as a flattened array in the order specified by `categories`.
async function sortTodos(todos, categories) {}
const result = await sortTodos(
[
"dishes",
"laundry",
"submit performance review",
"call mom",
"make dr appointment",
],
["phone", "house chores", "work"]
);
console.log(result);
// ['call mom', 'make dr appointment', 'dishes', 'laundry', 'submit performance review']
See the example project for a working example.
Is this a good idea?
There are a number of other ways of accomplishing this that may be better. In particular, it would be worth investigating a decorator / reflection-based implementation. (Babel is a big hammer.)
Is it production ready?
Ooooooooh no. The code is a proof-of-concept (AKA "trash") that I hacked together in an afternoon.
Are you accepting PRs?
Absolutely! I'll try to review with a light touch.
autofn
requires Node and Babel.
- Add
autofn-babel
as a babel plugin. - Add
autofn-runtime
as a project dependency and addimport "autofn-runtime";
to the top of your app's entrypoint. - Set the
OPENAI_API_KEY
environment variable. - Have fun!
Some ideas:
- Memoize results
- In-process memoization
- Filesystem-backed memoization
- Use TypeScript and Flow type information as hints
- Convert to TypeScript project
- Design mechanism for configuring model on a per-fn basis
- Come up with way to quickly "expand" a remote function into a local one