Socket
Book a DemoInstallSign in
Socket

english-script

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

english-script

Embed natural language in your code

0.0.9
latest
Source
npmnpm
Version published
Weekly downloads
0
-100%
Maintainers
1
Weekly downloads
 
Created
Source

english-script

Embed natural language in your code.

Allow me to completely take out of context this great Djikstra essay:

It may be illuminating to try to imagine what would have happened if, right from the start our native tongue would have been the only vehicle for the input into and the output from our information processing equipment...

-- Edsger W.Dijkstra

Usage

npm i english-script
const f = await makeFunction({
  apiKey: "your openai key here",
  iterations: 4, // How many "turns" are given for the AI to get the function right.
  description: "determine if prime",
  testCases: [
    [1, false], // By definition
    [2, true],
    [4, false],
  ],
});
[53, 44].map(f); // Gives back [true, false]

Implementation details

  • Caching (https://github.com/uriva/rmmbr) is used to avoid repetitive slow/expensive calls to OpenAI.
  • The generated code is checked for side effects (e.g. network calls or external dependencies), to make sure it is safe to run.
  • The generated code is tested against your provided test cases.

So what is this?

Background

We can now generate code with fairly good quality, depending on the task, using LLMs.

The common developer goes through this cycle:

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

Argument

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.

Problem

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

Solution

english-script is a 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.

FAQs

Package last updated on 15 Nov 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.