From d648913f6626e38179f9d62e51ae274d33d48927 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=81=8D=E5=85=AE=E6=83=9A=E5=85=AE?= <101191390+HIllya51@users.noreply.github.com> Date: Mon, 6 May 2024 17:42:40 +0800 Subject: [PATCH] issues/719 --- .../translator/basetranslator.py | 21 ++++++++++--------- .../files/defaultconfig/config.json | 18 ++++++++++------ 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/LunaTranslator/LunaTranslator/translator/basetranslator.py b/LunaTranslator/LunaTranslator/translator/basetranslator.py index 705b02e4..56468dbb 100644 --- a/LunaTranslator/LunaTranslator/translator/basetranslator.py +++ b/LunaTranslator/LunaTranslator/translator/basetranslator.py @@ -59,6 +59,8 @@ def timeoutfunction( class basetrans(commonbase): def langmap(self): + # The mapping between standard language code and API language code, if not declared, defaults to using standard language code. + # But the exception is cht. If api support cht, if must be explicitly declared the support of cht, otherwise it will translate to chs and then convert to cht. return {} def inittranslator(self): @@ -159,13 +161,17 @@ class basetrans(commonbase): @property def is_gpt_like(self): - try: - return globalconfig["fanyi"][self.typename]["is_gpt_like"] - except: - return False + # Don't use short-term cache, only use long-term cache, useful for gpt like apis to modify prompt + return globalconfig["fanyi"][self.typename].get("is_gpt_like", False) + + @property + def onlymanual(self): + # Only used during manual translation, not used during automatic translation + return globalconfig["fanyi"][self.typename].get("manual", False) @property def needzhconv(self): + # The API does not support direct translation to Traditional Chinese, only Simplified Chinese can be translated first and then converted to Traditional Chinese l = static_data["language_list_translator_inner"][globalconfig["tgtlang3"]] return l == "cht" and "cht" not in self.langmap() @@ -175,6 +181,7 @@ class basetrans(commonbase): @property def transtype(self): + # free/dev/api/offline/pre return globalconfig["fanyi"][self.typename].get("type", "free") def gettask(self, content): @@ -263,12 +270,6 @@ class basetrans(commonbase): return res - @property - def onlymanual(self): - if "manual" not in globalconfig["fanyi"][self.typename]: - return False - return globalconfig["fanyi"][self.typename]["manual"] - def _iterget(self, __callback, rid, __res): succ = True for i, _res in enumerate(__res): diff --git a/LunaTranslator/files/defaultconfig/config.json b/LunaTranslator/files/defaultconfig/config.json index ba086ede..7e56483b 100644 --- a/LunaTranslator/files/defaultconfig/config.json +++ b/LunaTranslator/files/defaultconfig/config.json @@ -984,7 +984,8 @@ "type": "api", "use": false, "color": "blue", - "name": "gemini" + "name": "gemini", + "is_gpt_like": true }, "jb7": { "type": "offline", @@ -1159,13 +1160,15 @@ "type": "api", "use": false, "color": "blue", - "name": "cohere" + "name": "cohere", + "is_gpt_like": true }, "claude": { "type": "api", "use": false, "color": "blue", - "name": "claude" + "name": "claude", + "is_gpt_like": true }, "chatgpt-3rd-party": { "type": "api", @@ -1204,19 +1207,22 @@ "use": false, "type": "offline", "color": "blue", - "name": "Sakura大模型" + "name": "Sakura大模型", + "is_gpt_like": true }, "chatgpt-offline": { "use": false, "type": "offline", "color": "blue", - "name": "ChatGPT_离线" + "name": "ChatGPT_离线", + "is_gpt_like": true }, "TGW": { "use": false, "type": "offline", "color": "blue", - "name": "TGW语言模型" + "name": "TGW语言模型", + "is_gpt_like": true } }, "magpiepath": "",