Skip to content
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

Open
wrxx2019 opened this issue Mar 12, 2023 · 4 comments
Open

有没有考虑接入OpenAI的GPT3.5接口来实时翻译呢 #2

wrxx2019 opened this issue Mar 12, 2023 · 4 comments

Comments

@wrxx2019
Copy link

有没有考虑接入OpenAI的GPT3.5接口来实时翻译呢,只是建议哈。

@rerender2021
Copy link
Owner

rerender2021 commented Mar 12, 2023

我还没有使用过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);
        }
    };
}

@rerender2021
Copy link
Owner

大概就像这样,注册open api之后,就是替换remoteTranslate里面的实现,用自己的token之类的去请求。

@rerender2021
Copy link
Owner

rerender2021 commented Mar 16, 2023

有没有考虑接入OpenAI的GPT3.5接口来实时翻译呢,只是建议哈。

感谢建议,已尝试,真香:

image

之后会尝试用它API开发试试,不知道请求延迟如何就是。

@weweaaa
Copy link

weweaaa commented Apr 3, 2024

想請教替換本機使用的模型換成其他的模型的可能作法🤣❤️🎈
例如:OpenAPI 推出的語音識別&語言翻譯模型 whisper-large-v3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants