Skip to content

Instantly share code, notes, and snippets.

@kmurray1000
Forked from limboinf/main.js
Created January 31, 2024 06:37
Show Gist options
  • Select an option

  • Save kmurray1000/675b82f4e5c476673184c37fc6d3f9ca to your computer and use it in GitHub Desktop.

Select an option

Save kmurray1000/675b82f4e5c476673184c37fc6d3f9ca 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"
}
];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment