mirror of
https://github.com/zhayujie/chatgpt-on-wechat.git
synced 2026-06-02 00:57:41 +08:00
feat(translate): add Youdao as a new translation provider
The translate module previously only supported Baidu translation, and the factory raised a bare RuntimeError for any other type. This change adds Youdao Translation as a second provider and improves the factory's error message. Implementation details: - New YoudaoTranslator class in translate/youdao/youdao_translate.py - Implements Youdao's v3 SHA-256 signature scheme, including the truncate-input rule for queries longer than 20 characters - Maps ISO 639-1 language codes to Youdao-specific codes (zh -> zh-CHS, zh-TW -> zh-CHT, others pass through) - Differentiates network errors, API error codes, and empty translations - factory.create_translator now lists the supported types in its RuntimeError message instead of failing silently - Default config exposes youdao_translate_app_key and youdao_translate_app_secret Adds 17 unit tests covering signature correctness, language code mapping, input truncation edge cases, the full request/response flow, and factory dispatch. All tests pass under Python 3.11.
This commit is contained in:
@@ -123,10 +123,13 @@ available_setting = {
|
||||
"chat_start_time": "00:00", # 服务开始时间
|
||||
"chat_stop_time": "24:00", # 服务结束时间
|
||||
# 翻译api
|
||||
"translate": "baidu", # 翻译api,支持baidu
|
||||
"translate": "baidu", # 翻译api,支持baidu, youdao
|
||||
# baidu翻译api的配置
|
||||
"baidu_translate_app_id": "", # 百度翻译api的appid
|
||||
"baidu_translate_app_key": "", # 百度翻译api的秘钥
|
||||
# youdao翻译api的配置
|
||||
"youdao_translate_app_key": "", # 有道翻译api的应用ID
|
||||
"youdao_translate_app_secret": "", # 有道翻译api的应用密钥
|
||||
# wechatmp的配置
|
||||
"wechatmp_token": "", # 微信公众平台的Token
|
||||
"wechatmp_port": 8080, # 微信公众平台的端口,需要端口转发到80或443
|
||||
|
||||
Reference in New Issue
Block a user