OK wow, so this thing is amazing
OpenAI has an API that is simple to use. It doesn’t offer access to ChatGPT itself yet, but it does offer the GPT-3 model, which is what ChatGPT is built on. There are so many capabilities and options you could go to town with it. But here, I have made a simple example that completes a prompt you give it. Have a go, let me know any feedback, and I’ll probably release it as a pre-packaged extension soon too.
You’ll need to get your own API key from https://platform.openai.com/account/api-keys.
(Update 1 Mar 2023: New API just dropped, see below updated script for ChatGPT)
// #popclip
// name: GPT-3
// icon: iconify:eos-icons:ai
// language: javascript
// after: paste-result
// entitlements: [network]
// options: [{identifier: apikey, label: API Key, type: string,
// description: 'Obtain API key from https://platform.openai.com/account/api-keys'}]
const axios = require("axios");
// base object for communicating with OpenAI
const openai = axios.create({
baseURL: 'https://api.openai.com/v1/',
headers: { Authorization: `Bearer ${popclip.options.apikey}` }
});
// use the GPT-3 model (note - can change/add other params here)
const data = {
model: 'text-davinci-003',
max_tokens: 512,
prompt: popclip.input.text
};
// send query to OpenAI's `completions` service
const response = await openai.post('completions', data);
// return the first text in the response
return popclip.input.text + response.data.choices[0].text;
(The above block is an extension snippet - select the text it then click “Install Extension” when PopClip appears.)
How to install this:
Test result :
When they release ChatGPT to the API, this could presumably be extended to make it maintain a dialogue with a series of invocations.