generated from qber-soft/Ave-React-Template
-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
有没有考虑接入OpenAI的GPT3.5接口来实时翻译呢 #2
Comments
我还没有使用过open ai,那个注册好像比较麻烦,所以目前还没有考虑过用它作为翻译源(没有开发调试的条件)。 不过之前有试过deepl,扩展起来还是比较方便,本地起一个服务器转发请求就可以,比如deepl的: const express = require('express')
const axios = require('axios')
function main() {
const app = express()
app.use(express.json());
app.post('/translate', safe(async function (req, res) {
const text = req.body.text.replace(/\n/g, " ");
console.log("begin translate", { text });
const start = Date.now();
const result = await remoteTranslate(text);
const end = Date.now();
console.log(`translate end in ${end - start}ms`);
res.json({
result: [
{ translation_text: result }
]
});
}))
app.listen(8100);
console.log("server start");
}
main();
async function remoteTranslate(text = "") {
// TODO: this is private api!
const url = "xxx";
const response = await axios.post(url, {
text,
// language table: https://www.deepl.com/docs-api/translate-text/large-volumes/
source_lang: "EN",
target_lang: "ZH"
});
console.log("translate result", { result: response.data });
const result = response.data.data;
return result;
}
function safe(callback) {
return (...args) => {
try {
return callback(...args);
} catch (error) {
console.error(error);
}
};
} |
大概就像这样,注册open api之后,就是替换remoteTranslate里面的实现,用自己的token之类的去请求。 |
想請教替換本機使用的模型換成其他的模型的可能作法🤣❤️🎈 |
Open
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
有没有考虑接入OpenAI的GPT3.5接口来实时翻译呢,只是建议哈。
The text was updated successfully, but these errors were encountered: