I connected GPT-3 to my terminal via Node.js.
Assumptions:
- You are using zsh on a mac
- You are familiar with the basics of node and npm
Let’s say I want a command that lets me get a tldr summary from the command line.
I created a folder for prompts. Installed node stuff, including OpenAIApi. Created a file called tldr.js
const { Configuration, OpenAIApi } = require("openai");
const configuration = new Configuration({
apiKey: process.env.OPENAI_API_KEY,
});
const openai = new OpenAIApi(configuration);
async function start() {
const myArgs = process.argv.slice(2);
const paragraph = myArgs[0];
const response = await openai.createCompletion("text-davinci-002", {
prompt: "Summarize this for a five-year old child:\n\n" + paragraph,
temperature: 0.7,
max_tokens: 200,
top_p: 1,
frequency_penalty: 0,
presence_penalty: 0,
});
console.log(response.data.choices[0].text);
}
start();
I add the following to ~/.zshrc
:
# OpenAI
export OPENAI_API_KEY=(YOUR API KEY HERE)
function tldr() {
if [[ "$1" == "" ]]; then
echo "tell me what to summarize"
else
node ~/(THE PATH TO YOUR FILE HERE)/tldr.js $1
fi
}
Then I run the command (quotes are important!):
tldr “The intent of Ethereum is to create an alternative protocol for building decentralized applications, providing a different set of tradeoffs that we believe will be very useful for a large class of decentralized applications, with particular emphasis on situations where rapid development time, security for small and rarely used applications, and the ability of different applications to very efficiently interact, are important. Ethereum does this by building what is essentially the ultimate abstract foundational layer: a blockchain with a built-in Turing-complete programming language, allowing anyone to write smart contracts and decentralized applications where they can create their own arbitrary rules for ownership, transaction formats and state transition functions. A bare-bones version of Namecoin can be written in two lines of code, and other protocols like currencies and reputation systems can be built in under twenty. Smart contracts, cryptographic “boxes” that contain value and only unlock it if certain conditions are met, can also be built on top of the platform, with vastly more power than that offered by Bitcoin scripting because of the added powers of Turing-completeness, value-awareness, blockchain-awareness and state.”
Response:
Ethereum is a decentralized platform that runs smart contracts: applications that run exactly as programmed without any possibility of fraud or third party interference.
In Ethereum, you can write code that controls money, and build applications accessible anywhere in the world.