Skip to content

Instantly share code, notes, and snippets.

@limboinf
Last active January 31, 2024 06:37
Show Gist options
  • Save limboinf/524d6f80ad0784eccadb1a87ac6e7fb7 to your computer and use it in GitHub Desktop.
Save limboinf/524d6f80ad0784eccadb1a87ac6e7fb7 to your computer and use it in GitHub Desktop.
// #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(temperature, 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,
temperature: temperature,
messages
});
return data.choices[0].message.content.trim();
}
async function prompt(input, options) {
return await callOpenAI(
0.7, input, options, "You are an encyclopedia, please explain this question concisely and reply in Chinese.");
};
async function rewrite(input, options) {
return await callOpenAI(
0.2, input, options, "Please rewrite the following text using a professional tone in the language of this text.");
};
async function summarize(input, options) {
return await callOpenAI(
0.7, input, options, "Summarize the following text as concise as possible in Chinese:");
};
async function translate(input, options) {
return await callOpenAI(
0, 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 make any interpretations, just translate. the content is:");
};
exports.actions = [
{
title: "explain",
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"
}
];
@limboinf
Copy link
Author

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

@limboinf
Copy link
Author

image

@limboinf
Copy link
Author

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment