Skip to content

Instantly share code, notes, and snippets.

@confluencepoint
Forked from limboinf/main.js
Created June 28, 2023 20:42
Show Gist options
  • Save confluencepoint/9e98964350c23937a13375a4c9ec54d5 to your computer and use it in GitHub Desktop.
Save confluencepoint/9e98964350c23937a13375a4c9ec54d5 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 be brief and concise to answer this question:");
};
async function rewrite(input, options) {
return await callOpenAI(
0.7, input, options, "Rewrite this using an academic tone:");
};
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: "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