koodo-reader / koodo-reader

A modern ebook manager and reader with sync and backup capacities for Windows, macOS, Linux and Web
https://koodoreader.com
GNU Affero General Public License v3.0
19.27k stars 1.49k forks source link

翻译插件能支持 openai 吗 #1258

Open wayhome opened 1 month ago

wayhome commented 1 month ago

我已经搜索了 Issue 列表,没有找到类似的需求

我已经试用最新开发版,同样没找到这个功能

如果您有不止一个需求,请在多个 issue 里分别提交.

简单介绍

希望可以支持 openai 来翻译,搞不懂这里的插件是怎样校验的,自己参考实现总是校验失败

细节描述

{ "identifier":"openai-translate-plugin", "type":"translation", "displayName":"OpenAI", "icon":"openai", "version":"1.0.0", "autoValue":"", "config":{ "url":"https://api.openai.com/v1/chat/completions", "apiKey":"", "model":"gpt-3.5-turbo" }, "langList":{"":"Automatic","en":"English","zh":"Chinese","es":"Spanish","fr":"French","de":"German","ja":"Japanese","ko":"Korean","ru":"Russian","ar":"Arabic","hi":"Hindi","pt":"Portuguese","it":"Italian"}, "scriptSHA256":"66f87a53dd5276d2a20f41d0526078ee8089841c1834aaae4cd4e7ad86b1682f", "script":"async function translate(t,e,n,a,r){if(!r.url||!r.apiKey)return\"Error: Missing URL or API Key\";const s=Translate the following ${e||\"auto-detected language\"} text to ${n}:\n\n${t}\n\nTranslation:;try{const t=await a.post(r.url,{model:r.model||\"gpt-3.5-turbo\",messages:[{role:\"user\",content:s}]},{headers:{\"Content-Type\":\"application/json\",Authorization:Bearer ${r.apiKey}}});return 200===t.status&&t.data.choices&&t.data.choices.length>0?t.data.choices[0].message.content.trim():\"Error: Unexpected response from OpenAI API\"}catch(t){return console.error(\"Translation error:\",t),\"Error: Failed to translate using OpenAI API\"}}window.translate=translate;" }

troyeguo commented 1 month ago

感谢您的建议,会考虑的