A PopClip extension for ChatGPT

Hi! Is there any functional for replacing a selected text?

I have an idea: the extension for ChatGPT which sent a selected text with promts (I mean command for ChatGPT what it needs to do with text, for example “Simplify this text so that it’s easier to understand”) to ChatGPT via API and it will be replaced the selected text by the received response.

For example. I’m writing a email and select the text, then click the icon of the extension and the text will be replaced by the generated ChatGPT text.

May I get some advices how to do that?


Great idea; it could be really powerful. What PopClip would need is an API for sending queries to ChatGPT. So the first task is to research whether ChatGPT provides an API.

Edit: Had a look, yes it does, so the next step is to play with the API a bit to figure out how we will use it in PopClip. I’ll certainly take a look later.

1 Like

There is Shortcut example what I use at the moment with PopClip. I hope it’ll be hopeful!

OK wow, so this thing is amazing :sob:

CleanShot 2023-02-02 at 09.36.52

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.

// #popclip
// name: OpenAI
// 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:
CleanShot 2023-02-02 at 09.57.52

Test result :rofl::

When they release ChatGPT to the API, this could presumably be extended to make it maintain a dialogue with a series of invocations.


Hi nice idea !
i will try this code, but i have got a “invalid YAML” in popclip no install message.
thanks !

What PopClip version are your running? You will need the latest, v2022.12.

1 Like