A PopClip extension for ChatGPT

I think a fixed prompt version of this may be very useful. Just as a proof of concept:

// #popclip
// name: OpenAI - Fixed Prompt
// icon: P
// 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'}
// - {identifier: prompt, label: Prompt, type: string,
//    defaultValue: "Summarise the following in fewer words"}
const openai = require("axios").create({
  baseURL: 'https://api.openai.com/v1/',
  headers: { Authorization: `Bearer ${popclip.options.apikey}` }
});
const data = {
  model: 'text-davinci-003',
  max_tokens: 512,
  prompt: popclip.options.prompt + ":\n\n" + popclip.input.text
};
const response = await openai.post('completions', data);
return response.data.choices[0].text.trim();

Example (with the default prompt “Summarise the following in fewer words”):

CleanShot 2023-02-22 at 12.56.12

I used this same concept to make a German Sentence Case extension.

2 Likes