|
DIY一个popclip扩展-AI写手
介绍
这是一个和chatgpt交互的popclip扩展,通过该扩展你能轻松在mac上选中文字并即时得到内容修改反馈
目前diy的扩展功能如下:
公众号爆款标题:选中一段文字标题或内容改写为吸引人眼球的标题
小红书风格:独特的Emoji 风格润色润色内容
总结内容:归纳总结内容,同时用列表列出要点
中英互译:将发送的文字内容都翻译成中文,如果内容是中文则翻译成标准的英文
内容润色:检查接收到的文字的拼写、语法错误,对其进行润色
注意:开启扩展后需要填写自己的api key,安装方式为选中所有代码自动识别安装或将代码保存本地为js文件并拖入popclip启用
代码如下:
// #popclip extension for ChatGPT
// name: smart writer
// icon: iconify:fluent:calligraphy-pen-24-regular
// 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 prefixes = {
"polish": "你是我的写作助手,检查接收到的文字的拼写、语法错误,对其进行润色:\n",
"xiaohongshu": "扮演文本助理,使用小红书的 Emoji 风格润色我的内容,特点是每行开头都是一个相关表情符号,达到引人入胜的目的:\n",
"Summarize": "归纳总结这些文字,同时用列表列出要点:\n",
"translate": "将发送的文字内容都翻译成中文,如果内容是中文则翻译成标准的英文:\n",
"Official": "你将扮演专业的微信公众号运营者,优化润色我给的内容成为爆款标题:\n",
}
async function chat (input, options, lang, prefixName) {
const openai = require("axios").create({
baseURL: "https://api.openai.com/v1",
headers: { Authorization: `Bearer ${options.apikey}` },
});
let messages
switch (lang) {
case "en":
messages = [
{"role": "system", "content": "I want you act as a proofreader. I will provide you texts and I would like you to review them for any spelling, grammar, or punctuation errors."},
{"role": "user", "content": `Proofread the following content and give me the result without extra delarations or comments:\n\n${input.text}`},
]
break;
case "zh":
messages = [
{"role": "system", "content": "你是我的写作助手,检查接收到的文字的拼写、语法错误,向我提供修改后的文字。"},
{"role": "user", "content": `修改下面的文字,直接输出修改后的结果,不需要额外的声明:\n${input.text}`}
]
break;
}
if (prefixName) {
messages = [{"role": "user", "content": `${prefixes[prefixName]}${input.text}`}]
}
const { data } = await openai.post("/chat/completions", {
model: "gpt-3.5-turbo",
messages,
});
const result = data.choices[0].message;
return input.text.trimEnd() + "\n\n" + result.content.trim();
};
exports.actions = [
{
title: "公众号爆款标题",
icon: "circle 标题",
after: "paste-result",
code: async (input, options) => chat(input, options, "", "Official"),
},
{
title: "小红书风格",
icon: "circle 红书",
after: "paste-result",
code: async (input, options) => chat(input, options, "", "xiaohongshu"),
},
{
title: "总结内容",
icon: "circle 总结",
after: "paste-result",
code: async (input, options) => chat(input, options, "", "Summarize"),
},
{
title: "中英互译",
icon: "square 翻译",
after: "paste-result",
code: async (input, options) => chat(input, options, "", "translate"),
},
{
title: "润色",
icon: "square 润色",
after: "paste-result",
code: async (input, options) => chat(input, options, "", "polish"),
},
];
代码解释:
代码使用JavaScript编写,主要功能是使用OpenAI的ChatGPT模型作为文本内容修改校验工具。
定义了一个名为"prefixes"的对象,它包含了一些预定义的文本前缀,用于不同的校对任务。
定义了一个名为"chat"的异步函数,它接受输入文本、选项、语言和前缀名称作为参数。在函数内部,它使用提供的API密钥创建了一个基于Axios的OpenAI实例。然后,根据语言和前缀名称,构造了不同的对话消息数组。最后,使用OpenAI的Chat Completions API向模型发送请求,并返回校对结果。
导出了一个包含多个动作的数组"exports.actions"。每个动作都有一个标题、图标和代码块。代码块调用了"chat"函数,并根据不同的动作类型传递了相应的参数。
prompt说明
system: 你是我的写作助手,检查接收到的文字的拼写、语法错误,向我提供修改后的文字
user: 修改下面的文字,直接输出修改后的结果,不需要额外的声明
system和user代表对话角色,通过该设定加入prefixes预设的不同任务使ai可以按不同预设进行修改回复
其中在prefixes数组中你可以自行修改为不同的预设
功能介绍
引入的示例文本:
延时摄影(Time-lapse photography)是以一种将时间压缩的拍摄技术。其拍摄的是一组照片或是视频,后期通过照片串联或是视频抽帧,把几分钟、几小时甚至是几天几年的过程压缩在一个较短的时间内以视频的方式播放。分为固定机位与大范围场景,其中固定机位又包含完全固定与小范围(通过电控滑轨、云台实现机位的小范围移动),大范围场景按移动方向分为纵向移动、横向移动,按焦点划分为固定焦点与移动焦点
|
|