Skip to content

Instantly share code, notes, and snippets.

@nailuoGG
Last active February 2, 2023 10:21
Show Gist options
  • Save nailuoGG/859d73e48d4989fe50b935c272609416 to your computer and use it in GitHub Desktop.
Save nailuoGG/859d73e48d4989fe50b935c272609416 to your computer and use it in GitHub Desktop.
// #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-chat-davinci-002-20230126',
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;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment