• Stars
    star
    224
  • Rank 171,888 (Top 4 %)
  • Language
    Shell
  • License
    MIT License
  • Created 10 months ago
  • Updated 9 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A truly natural scripting language

humanscript

A truly natural scripting language

humanscript is an inferpreter. A script interpreter that infers the meaning behind commands written in natural language using large language models. Human writeable commands are translated into code that is then executed on the fly. There is no predefined syntax, humanscripts just say what they want to happen, and when you execute them, it happens.

The humanscript inferpreter supports a wide range of LLM backends. It can be used with cloud hosted LLMs like OpenAI's GPT-3.5 and GPT-4 or locally running open source LLMs like Llama 2.

Example

This is a humanscript called tidy-screenshots. It takes an unorganised directory of screenshots and organises them into directories based on the month the screenshot was taken.

#!/usr/bin/env humanscript

loop over all files (ignoring directories) in $HOME/Screenshots

move each file into a subdirectory in the format year-month

while the task is running show an ascii loading spinner

show how many files where moved

show the size of each subdirectory

It can be executed like any other script.

$ ./tidy-screenshots
Moved 593 files.
364K    2023-08
2.3M    2023-02
5.4M    2022-09
5.8M    2023-03
6.9M    2022-07
7.4M    2023-04
 10M    2023-01
 12M    2022-01
 13M    2022-10
 14M    2022-03
 16M    2022-11
 16M    2022-12
 18M    2022-02
 19M    2021-11
 20M    2021-12
 23M    2021-09
 23M    2022-05
 28M    2023-07
 30M    2022-04
 30M    2023-05
 30M    2023-06
 35M    2022-06
 38M    2021-10
 66M    2022-08

The LLM inferpreted the humanscript into the following bash script at runtime.

#!/usr/bin/env bash

spinner() {
    local i sp n
    sp='⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏'
    n=${#sp}
    while sleep 0.1; do
        printf "%s\r" "${sp:i++%n:1}"
    done
}

spinner &

spinner_pid=$!

moved_count=0

for file in "$HOME/Screenshots"/*; do
    if [ -f "$file" ]; then
        dir="$HOME/Screenshots/$(date -r "$file" "+%Y-%m")"
        mkdir -p "$dir"
        mv "$file" "$dir"
        ((moved_count++))
    fi
done

kill "$spinner_pid"

echo "Moved $moved_count files."

du -sh "$HOME/Screenshots"/* | sed "s|$HOME/Screenshots/||"

The code is streamed out of the LLM during inferpretation and executed line by line so execution is not blocked waiting for inference to finish. The generated code is cached on first run and will be executed instantly on subsequent runs, bypassing the need for reinferpretation.

You can see it in action here:

Usage

Install humanscript

You can run humanscript in a sandboxed environment via Docker:

docker run -it lukechilds/humanscript

Alternatively you can install it natively on your system with Homebrew:

brew install lukechilds/tap/humanscript

Or manually install by downloading this repository and copy/symlink humanscript into your PATH.

Be careful if you're running humanscript unsandboxed. The inferpreter can sometimes do weird and dangerous things. Speaking from experience, unless you want to be doing a system restore at 2am on a saturday evening, you should atleast run humanscripts initially with HUMANSCRIPT_EXECUTE="false" so you can check the resulting code before executing.

Write and execute a humanscript

humanscript is configured out of the box to use OpenAI's GPT-4, you just need to add your API key.

We need to add it to ~/.humanscript/config

mkdir -p ~/.humanscript/
echo 'HUMANSCRIPT_API_KEY="<your-openai-api-key>"' >> ~/.humanscript/config

Now you can create a humanscript and make it executable.

echo '#!/usr/bin/env humanscript
print an ascii art human' > asciiman
chmod +x asciiman

And then execute it.

./asciiman
  O
 /|\
 / \

Configuration

All environment variables can be added to ~/.humanscript/config to be applied globally to all humanscripts:

$ cat ~/.humanscript/config
HUMANSCRIPT_API_KEY="sk-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
HUMANSCRIPT_MODEL="gpt-4"

or on a per script basis:

$ HUMANSCRIPT_REGENERATE="true" ./asciiman

HUMANSCRIPT_API

Default: https://api.openai.com/v1

A server following OpenAI's Chat Completion API.

Many local proxies exist that implement this API in front of locally running LLMs like Llama 2. LM Studio is a good option.

HUMANSCRIPT_API="http://localhost:1234/v1"

HUMANSCRIPT_API_KEY

Default: unset

The API key to be sent to the LLM backend. Only needed when using OpenAI.

HUMANSCRIPT_API_KEY="sk-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"

HUMANSCRIPT_MODEL

Default: gpt-4

The model to use for inference.

HUMANSCRIPT_MODEL="gpt-3.5"

HUMANSCRIPT_EXECUTE

Default: true

Whether or not the humanscript inferpreter should automatically execute the generated code on the fly.

If false the generated code will not be executed and instead be streamed to stdout.

HUMANSCRIPT_EXECUTE="false"

HUMANSCRIPT_REGENERATE

Default: false

Whether or not the humanscript inferpreter should regenerate a cached humanscript.

If true the humanscript will be reinferpreted and the cache entry will be replaced with the newly generated code. Due to the nondeterministic nature of LLMs each time you reinferpret a humanscript you will get a similar but slightly different output.

HUMANSCRIPT_REGENERATE="true"

License

MIT © Luke Childs

More Repositories

1

zsh-nvm

Zsh plugin for installing, updating and loading nvm
Shell
2,077
star
2

reverse-shell

Reverse Shell as a Service
JavaScript
1,732
star
3

dockerpi

A Virtualised Raspberry Pi inside a Docker image
Dockerfile
1,677
star
4

merge-images

Easily compose images together without messing around with canvas
JavaScript
1,611
star
5

gifgen

Simple high quality GIF encoding
Shell
527
star
6

zsh-better-npm-completion

Better completion for npm
Shell
450
star
7

when-dom-ready

$(document).ready() for the 21st century
JavaScript
334
star
8

refind-ambience

Minimal theme for the rEFInd boot manager
308
star
9

htconvert

Convert .htaccess redirects to nginx.conf redirects
JavaScript
186
star
10

browser-env

Simulates a global browser environment using jsdom
JavaScript
171
star
11

coinlist

Comprehensive list of cryptocurrencies with metadata
JavaScript
155
star
12

coinflict-of-interest

Browser extension to show user biases on Crypto Twitter.
JavaScript
144
star
13

chest

Bash glue to encrypt and hide files
Shell
129
star
14

create-test-server

Creates a minimal Express server for testing
JavaScript
121
star
15

docker-electrumx

Run an Electrum server with one command
Dockerfile
101
star
16

base64-async

Non-blocking chunked Base64 encoding
JavaScript
98
star
17

doge-seed

Dank mnemonic seed phrases
HTML
86
star
18

onionite

Explore the Tor network
JavaScript
76
star
19

window

Exports a jsdom window object.
JavaScript
74
star
20

expired

Calculate when HTTP cache headers expire
JavaScript
74
star
21

github-custom-tab-size

Chrome extension - Set custom tab size for code view on GitHub.com
JavaScript
67
star
22

howmanyconfs.com

How many confirmations are equivalent to 6 Bitcoin confirmations?
JavaScript
60
star
23

create-cert

Super simple self signed certificates
JavaScript
43
star
24

react-jsdom

Render React components to actual DOM nodes in Node.js
JavaScript
33
star
25

byte-range

Returns integer ranges for C data types
JavaScript
32
star
26

parcel-plugin-ogimage

Set absolute URL for og:image meta tags.
JavaScript
22
star
27

build-output-script

Builds a P2PKH Bitcoin transaction output script
JavaScript
21
star
28

create-xpub

Create a BIP32 extended public key
JavaScript
21
star
29

onionoo-node-client

Node.js client library for the Tor Onionoo API
JavaScript
20
star
30

autoscale-do-block-storage

Autoscale Digital Ocean block storage volumes
Shell
20
star
31

my-name-is-url

Intelligent URL parser
JavaScript
17
star
32

docker-vertcoind

Run a full Vertcoin node with one command
Dockerfile
9
star
33

tippin-badge

Readme badge generator for tippin.me
HTML
8
star
34

docker-bitcoind

Run a full Bitcoin node with one command
Dockerfile
7
star
35

create-node

Converts an HTML string to a dom node
JavaScript
7
star
36

this

Traverses up the directory tree and returns the first module found
JavaScript
7
star
37

requirable

Enables a module to require itself by name
JavaScript
6
star
38

docker-ledger-sdk

Build a Ledger app with one command
Dockerfile
6
star
39

ephemeral-electrum

A quick throwaway text based Electrum instance.
Dockerfile
5
star
40

notary-node-utils

Utilities for running a notary node
Shell
5
star
41

electrs-next

Docker configuration for testing the `next` branch of electrs.
Dockerfile
4
star
42

docker-electrum-vertcoin

Run a Vertcoin Electrum server with one command
4
star
43

docker-barterdex-api

Shell
4
star
44

vainjs

A JavaScript vanity address generator
JavaScript
4
star
45

sign-release

Easy automated release signing
Shell
3
star
46

test

test repo for testing git/GitHub related things
1
star
47

vercel-bug

JavaScript
1
star
48

arrows

My custom ZSH theme
Shell
1
star
49

eslint-config-lukechilds

My personal eslint preferences
JavaScript
1
star
50

eslint-config-xo-lukechilds

My personal XO overrides
JavaScript
1
star
51

Extension

Browser extension to show user influence on Crypto Twitter.
JavaScript
1
star
52

morethan140

View and send tweets over 140 characters
JavaScript
1
star
53

pirateproxy

Proxy site for thepiratebay.org
JavaScript
1
star
54

b64golf

JavaScript
1
star
55

AtHash

Social text parser
JavaScript
1
star
56

javascript

How we like to JavasScript at Unsplash.
JavaScript
1
star
57

umbrel-apps-test-2

1
star
58

syringe

Search and inject packages from npm
JavaScript
1
star
59

blog-clj

Clojure
1
star
60

anonlytics-express

Privacy respecting analytics for express apps
JavaScript
1
star
61

tor-hs-issue-repro

Shell
1
star
62

trim

Rust
1
star
63

hyperdex-bugtracker

1
star
64

homebrew-tap

My Homebrew tap
Ruby
1
star
65

bip39-versioned

Proof of concept adding versioning to BIP39 compatible seeds
JavaScript
1
star