EnglishScript — embed natural language in your js code

Uri Valevski
2 min readApr 17, 2023

--

EnglishScript (https://github.com/uriva/english-script) is a small js library that helps you embed natural language alongisde your code.

LLM advancements are for the first time enabling us to generate code with fairly good quality, depending on the task.

The common developer goes through this cycle:

  1. Prompt LLM to get some code to do some task
  2. Copy the code into their IDE
  3. Read it to make sure it makes sense
  4. Write some tests and running them to make sure it works as expected
  5. Commit the code into the repo

But committing code generated by a machine doesn’t feel right because it’s kind of like committing a compiled binary.

If I compile some code and save the binaries, I now have in my repo two things which are coupled together, and it’s unclear if the versions match, how they match, which derives from which, and therefore it becomes unclear which I need to iterate on in order to improve.

This is why it’s a common practice to commit only the “topmost” work, i.e. the one others derive from. This has always been high level code, until now. We’ve now reached the point where at least in some cases the topmost form is a prompt in natural language description, and so we should commit that form instead.

Furthermore most of what LLMs generating code are really good at is code that already exists in some form in the web, in the form of libraries or code examples in stackoverflow. So it’s unlikely that adding generated code into our repo will contribute any concrete innovation, rather than provide more duplication.

How do we commit natural language alongside code and iterate on it using our source control tools, so that we can avoid duplication, benefit from the LLMs incredible abilities and have a workflow that makes sense?

english-script (https://github.com/uriva/english-script) is an js library that allows you to embed natural language descriptions of pure functions inside your code seamlessly. It calls an LLM API in the background to get code and replace it on the fly.

To install it:

npm i english-script

It expects your OpenAI key to be in an environment variable openai_key.

You can then use it like so:

const f = await makeFunction({
description: "determine if prime",
testCases: [
[1, false], // By definition
[2, true],
[4, false],
],
});
[53, 44].map(f); // Gives back [true, false]

And that’s basically it 🤷.

--

--