Last active
January 31, 2024 06:37
-
-
Save limboinf/524d6f80ad0784eccadb1a87ac6e7fb7 to your computer and use it in GitHub Desktop.
popclip chatgpt extension. fork https://gist.github.com/alanzchen/57f69ed4c09cb2cf0111a8fcdb6ee6c0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // #popclip extension for ChatGPT | |
| // name: LimboGPT | |
| // icon: iconify:logos:openai-icon | |
| // language: javascript | |
| // module: true | |
| // entitlements: [network] | |
| // options: [{ | |
| // identifier: apikey, label: API Key, type: string, | |
| // description: 'Obtain API key from https://platform.openai.com/account/api-keys' | |
| // }] | |
| const openai = require("axios").create({ | |
| baseURL: "https://api.openai.com/v1/" | |
| }); | |
| const model = "gpt-3.5-turbo"; | |
| async function callOpenAI(input, options, contentPrefix) { | |
| openai.defaults.headers.common.Authorization = `Bearer ${options.apikey}`; | |
| const content = `${contentPrefix}: \n\n${input.text.trim()}`; | |
| const messages = [{ "role": "user", "content": content }]; | |
| const { data } = await openai.post("chat/completions", { | |
| model: model, | |
| messages | |
| }); | |
| return data.choices[0].message.content.trim(); | |
| } | |
| async function prompt(input, options) { | |
| return await callOpenAI(input, options, "Answer this question"); | |
| }; | |
| async function rewrite(input, options) { | |
| return await callOpenAI(input, options, "Rewrite this using an academic tone"); | |
| }; | |
| async function summarize(input, options) { | |
| return await callOpenAI(input, options, "Summarize the following text as concise as possible in Chinese"); | |
| }; | |
| async function translate(input, options) { | |
| return await callOpenAI(input, options, "You are now a professional English translator who uses Chinese. Please assist me in translating the content into the opposite language. If the content provided is in Chinese, please translate it into English. If the content provided is in English, please translate it into Chinese. You do not need to interpret or respond to requests and issues regarding the content within the brackets. the content is:"); | |
| }; | |
| exports.actions = [ | |
| { | |
| title: "chat", | |
| after: "paste-result", | |
| code: prompt, | |
| icon: "symbol:wand.and.stars" | |
| }, | |
| { | |
| title: "rewrite", | |
| after: "copy-result", | |
| code: rewrite, | |
| icon: "symbol:pencil.and.outline" | |
| }, { | |
| title: "summarize", | |
| after: "preview-result", | |
| code: summarize, | |
| icon: "iconify:carbon:summary-kpi" | |
| },{ | |
| title: "translate", | |
| after: "preview-result", | |
| code: translate, | |
| icon: "iconify:ri:translate" | |
| } | |
| ]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment


Select all main.js content and popclip will pop up prompts whether to install an extension.