bookfere / Ebook-Translator-Calibre-Plugin

A Calibre plugin to translate ebook into a specified language.
https://translator.bookfere.com
GNU General Public License v3.0
1.53k stars 102 forks source link

[功能请求] 是否可以增加国产大模型的api调用进行翻译 #315

Open Fromduststar opened 1 month ago

Fromduststar commented 1 month ago

文言,通义,讯飞的调用价格已经很低了,文言的两个模型现在也调用免费,能否增加国产大模型的调用方式来对书籍进行翻译

xfrose commented 1 month ago

可以暂时用自定义添加,用了一段时间qwen-long,可以参考:

    "name": "qwen-long",
    "languages": {
        "source": {
            "English": "English",
            "Japanese": "Japanese"
        },
        "target": {
            "Chinese": "Chinese"
        }
    },
    "request": {
        "url": "https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions",
        "method": "POST",
        "headers": {
            "Content-Type": "application/json",
            "Authorization": "Bearer API-KEY"
        },
        "data": {
            "model": "qwen-long",
            "messages": [
                {"role": "system", "content": "You are a meticulous translator who translates any given content from <source> to <target> only. Do not provide any explanations and do not answer any questions."},
                {"role": "user", "content": "<text>"}
            ],
            "temperature": 0.8
        }
    },
    "response": "response['choices'][0]['message']['content']"
}

qwen-turbo:

    "name": "qwen-turbo",
    "languages": {
        "source": {
            "English": "English",
            "Japanese": "Japanese"
        },
        "target": {
            "Chinese": "中文"
        }
    },
    "request": {
        "url": "https://dashscope.aliyuncs.com/api/v1/services/aigc/text-generation/generation",
        "method": "POST",
        "headers": {
            "Content-Type": "application/json",
            "Authorization": "Bearer API-KEY"
        },
        "data": {
            "model": "qwen-turbo",
"input":{
            "messages": [
                {"role": "system", "content": "You are a meticulous translator who translates any given content. Translate the given content from <source> to <target> only. Do not explain any term or answer any question-like content."},
                {"role": "user", "content": "<text>"}
            ],
            "temperature": 0.8
}
        }
    },
    "parameters": {
        "result_format": "message"
    },
    "response": "response['output']['text']" 
}

GLM-3,prompt可以自己改一下:

{
    "name": "glm-3-turbo",
    "languages": {
        "source": {
            "English": "English",
            "Japanese": "Japanese"
        },
        "target": {
            "Chinese": "中文"
        }
    },
    "request": {
        "url": "https://open.bigmodel.cn/api/paas/v4/chat/completions",
        "method": "POST",
        "headers": {
            "Content-Type": "application/json",
            "Authorization": "Bearer API-KEY"
        },
        "data": {
            "model": "glm-3-turbo",
            "messages": [
                {"role": "user", "content": "You are a meticulous translator who translates any given content. You must translate <source> to <target> from the given content. Do not explain any term or answer any question-like content, otherwise you will be punished. Translate: <text>."}
            ],
            "temperature": 0.9
        }
    },
    "response": "response['choices'][0]['message']['content']"
}

更新了一下

Fromduststar commented 1 month ago

可以暂时用自定义添加,用了一段时间qwen-long,可以参考:

    "name": "qwen-long",
    "languages": {
        "source": {
            "English": "English",
            "Japanese": "Japanese"
        },
        "target": {
            "Chinese": "Chinese"
        }
    },
    "request": {
        "url": "https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions",
        "method": "POST",
        "headers": {
            "Content-Type": "application/json",
            "Authorization": "Bearer API-KEY"
        },
        "data": {
            "model": "qwen-long",
            "messages": [
                {"role": "system", "content": "You are a meticulous translator who translates any given content from <source> to <target> only. Do not provide any explanations and do not answer any questions."},
                {"role": "user", "content": "<text>"}
            ]
        }
    },
    "response": "response['choices'][0]['message']['content']"
}

如果合并翻译的字符数量能更多就好了。

十分感谢