From 9782360215ef1f262656721dc8139f02f7f86fb5 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: Fri, 19 Jul 2024 20:02:36 +0800 Subject: [PATCH] fix --- .../LunaTranslator/gui/setting_translate.py | 221 +++++++++++++++++- .../LunaTranslator/gui/usefulwidget.py | 5 + .../LunaTranslator/translator/baiduqianfan.py | 132 +++++++++++ .../LunaTranslator/translator/gptcommon.py | 61 +---- .../LunaTranslator/translator/txhunyuan.py | 185 +++++++++++++++ .../files/defaultconfig/config.json | 14 ++ .../defaultconfig/translatorsetting.json | 114 ++++++++- LunaTranslator/files/lang/ar.json | 6 +- LunaTranslator/files/lang/cht.json | 6 +- LunaTranslator/files/lang/en.json | 6 +- LunaTranslator/files/lang/es.json | 6 +- LunaTranslator/files/lang/fr.json | 6 +- LunaTranslator/files/lang/it.json | 6 +- LunaTranslator/files/lang/ja.json | 6 +- LunaTranslator/files/lang/ko.json | 6 +- LunaTranslator/files/lang/pl.json | 6 +- LunaTranslator/files/lang/ru.json | 6 +- LunaTranslator/files/lang/th.json | 6 +- LunaTranslator/files/lang/tr.json | 6 +- LunaTranslator/files/lang/uk.json | 6 +- LunaTranslator/files/lang/vi.json | 6 +- LunaTranslator/files/lang/zh.json | 6 +- docs/style.css | 15 +- docs/zh/guochandamoxing.md | 32 ++- docs/zh/sidebar.md | 2 +- plugins/CMakeLists.txt | 4 +- 26 files changed, 777 insertions(+), 98 deletions(-) create mode 100644 LunaTranslator/LunaTranslator/translator/baiduqianfan.py create mode 100644 LunaTranslator/LunaTranslator/translator/txhunyuan.py diff --git a/LunaTranslator/LunaTranslator/gui/setting_translate.py b/LunaTranslator/LunaTranslator/gui/setting_translate.py index 079802d4..ec35dcac 100644 --- a/LunaTranslator/LunaTranslator/gui/setting_translate.py +++ b/LunaTranslator/LunaTranslator/gui/setting_translate.py @@ -1,17 +1,23 @@ from qtsymbols import * import functools, os, time, hashlib -import requests, gobject +import requests, gobject, qtawesome, uuid, shutil from myutils.wrapper import threader from myutils.config import globalconfig, translatorsetting from myutils.subproc import subproc_w -from myutils.config import globalconfig -from myutils.utils import selectdebugfile, splittranslatortypes, checkportavailable +from myutils.utils import ( + selectdebugfile, + splittranslatortypes, + checkportavailable, + dynamiclink, +) from gui.pretransfile import sqlite2json from gui.inputdialog import autoinitdialog, autoinitdialog_items from gui.usefulwidget import ( D_getspinbox, - getspinbox, + getIconButton, D_getcolorbutton, + getcolorbutton, + getsimpleswitch, D_getIconButton, D_getsimpleswitch, selectcolor, @@ -27,19 +33,183 @@ def hashtext(a): return hashlib.md5(a.encode("utf8")).hexdigest() -def initsome11(self, l, label=None): +def deepcopydict(d): + if isinstance(d, dict): + nd = {} + for k in d: + nd[k] = deepcopydict(d[k]) + return nd + elif isinstance(d, list): + nd = [] + for k in d: + nd.append(deepcopydict(k)) + return nd + else: + return d + + +def splitapillm(l): + not_is_gpt_like = [] + is_gpt_likes = [] + for fanyi in l: + is_gpt_like = globalconfig["fanyi"][fanyi].get("is_gpt_like", False) + if is_gpt_like: + is_gpt_likes.append(fanyi) + else: + not_is_gpt_like.append(fanyi) + return is_gpt_likes, not_is_gpt_like + + +def loadvisinternal(skipid=False, skipidid=None): + __vis = [] + __uid = [] + lixians, pre, mianfei, develop, shoufei = splittranslatortypes() + is_gpt_likes, not_is_gpt_like = splitapillm(shoufei) + for _ in is_gpt_likes: + _f = "./Lunatranslator/translator/{}.py".format(_) + if not os.path.exists(_f): + continue + __vis.append(globalconfig["fanyi"][_]["name"]) + __uid.append(_) + return __vis, __uid + + +def getalistname(parent, callback, skipid=False, skipidid=None): + __d = {"k": 0, "n": ""} + __vis, __uid = loadvisinternal(skipid, skipidid) + + def __wrap(callback, __d, __uid): + if len(__uid) == 0: + return + + uid = __uid[__d["k"]] + callback(uid, __d["n"]) + + autoinitdialog( + parent, + "复制", + 600, + [ + { + "type": "combo", + "name": "目标", + "d": __d, + "k": "k", + "list": __vis, + }, + { + "name": "名称", + "type": "lineedit", + "d": __d, + "k": "n", + }, + { + "type": "okcancel", + "callback": functools.partial(__wrap, callback, __d, __uid), + }, + ], + ) + + +def selectllmcallback(self, countnum, btn, fanyi, name): + uid = str(uuid.uuid4()) + _f1 = "./Lunatranslator/translator/{}.py".format(fanyi) + _f2 = "./Lunatranslator/translator/{}.py".format(uid) + shutil.copy(_f1, _f2) + globalconfig["fanyi"][uid] = deepcopydict(globalconfig["fanyi"][fanyi]) + globalconfig["fanyi"][uid]["use"] = False + + if not name: + name = globalconfig["fanyi"][fanyi]["name"] + "_copy" + globalconfig["fanyi"][uid]["name"] = name + if fanyi in translatorsetting: + translatorsetting[uid] = deepcopydict(translatorsetting[fanyi]) + + layout: QGridLayout = self.damoxinggridinternal + + items = autoinitdialog_items(translatorsetting[uid]) + last = getIconButton( + callback=functools.partial( + autoinitdialog, + self, + (globalconfig["fanyi"][uid]["name"]), + 800, + items, + ), + icon="fa.gear", + ) + + name = LLabel(globalconfig["fanyi"][uid]["name"]) + swc = getsimpleswitch( + globalconfig["fanyi"][uid], + "use", + callback=functools.partial(gobject.baseobject.prepare, uid), + ) + color = getcolorbutton( + globalconfig["fanyi"][uid], + "color", + parent=self, + name="fanyicolor_" + uid, + callback=functools.partial( + selectcolor, + self, + globalconfig["fanyi"][uid], + "color", + None, + self, + "fanyicolor_" + uid, + ), + ) + + if len(countnum) % 3 == 0: + layout.addWidget(btn, layout.rowCount(), 0, 1, 1) + layout.addWidget(self.btnquestion, layout.rowCount() - 1, 1, 1, 1) + offset = 5 * (len(countnum) % 3) + layout.addWidget(name, layout.rowCount() - 2, offset + 0) + layout.addWidget(swc, layout.rowCount() - 2, offset + 1) + layout.addWidget(color, layout.rowCount() - 2, offset + 2) + layout.addWidget(last, layout.rowCount() - 2, offset + 3) + if len(countnum) % 3 != 2: + layout.addWidget(QLabel(), layout.rowCount() - 2, offset + 4) + + countnum.append(0) + + +def btnpluscallback(self, countnum, btn): + getalistname(self, functools.partial(selectllmcallback, self, countnum, btn)) + + +def createbtn(self, countnum): + btn = QPushButton(self) + btn.setIcon(qtawesome.icon("fa.plus")) + btn.clicked.connect(functools.partial(btnpluscallback, self, countnum, btn)) + return btn + + +def createbtnquest(self): + btn = QPushButton(self) + btn.setIcon(qtawesome.icon("fa.question")) + btn.clicked.connect( + lambda: os.startfile(dynamiclink("{docs_server}/#/zh/guochandamoxing")) + ) + self.btnquestion = btn + return btn + + +def initsome11(self, l, label=None, btnplus=False): grids = [] if label: grids.append([(label, 8)]) i = 0 line = [] + countnum = [] for fanyi in l: _f = "./Lunatranslator/translator/{}.py".format(fanyi) if not os.path.exists(_f): continue i += 1 - + countnum.append(0) if fanyi in translatorsetting: items = autoinitdialog_items(translatorsetting[fanyi]) @@ -92,6 +262,43 @@ def initsome11(self, l, label=None): line += [""] if len(line): grids.append(line) + if btnplus: + grids.append( + [ + (functools.partial(createbtn, self, countnum), 1), + (functools.partial(createbtnquest, self), 1), + ] + ) + + return grids + + +def initsome2(self, l, label=None): + is_gpt_likes, not_is_gpt_like = splitapillm(l) + not_is_gpt_like = initsome11(self, not_is_gpt_like, label) + is_gpt_likes = initsome11(self, is_gpt_likes, label, btnplus=True) + grids = [ + [ + ( + dict(type="grid", title="传统", grid=not_is_gpt_like), + 0, + "group", + ) + ], + [ + ( + dict( + type="grid", + title="大模型", + grid=is_gpt_likes, + internallayoutname="damoxinggridinternal", + parent=self, + ), + 0, + "group", + ) + ], + ] return grids @@ -264,7 +471,7 @@ def setTabTwo_lazy(self, basel): offlinegrid = initsome11(self, lixians) onlinegrid = initsome11(self, mianfei) developgrid += initsome11(self, develop) - online_reg_grid += initsome11(self, shoufei) + online_reg_grid += initsome2(self, shoufei) pretransgrid += initsome11(self, pre) vw, vl = getvboxwidget() basel.addWidget(vw) diff --git a/LunaTranslator/LunaTranslator/gui/usefulwidget.py b/LunaTranslator/LunaTranslator/gui/usefulwidget.py index f2b5c1cb..1c528369 100644 --- a/LunaTranslator/LunaTranslator/gui/usefulwidget.py +++ b/LunaTranslator/LunaTranslator/gui/usefulwidget.py @@ -1440,6 +1440,7 @@ def makegroupingrid(args): parent = args.get("parent", None) groupname = args.get("name", None) enable = args.get("enable", True) + internallayoutname = args.get("internallayoutname", None) group = LGroupBox() if not enable: @@ -1457,10 +1458,14 @@ def makegroupingrid(args): grid = QGridLayout() group.setLayout(grid) automakegrid(grid, lis) + if internallayoutname: + setattr(parent, internallayoutname, grid) elif _type == "form": lay = LFormLayout() group.setLayout(lay) makeforms(lay, lis, args) + if internallayoutname: + setattr(parent, internallayoutname, lay) return group diff --git a/LunaTranslator/LunaTranslator/translator/baiduqianfan.py b/LunaTranslator/LunaTranslator/translator/baiduqianfan.py new file mode 100644 index 00000000..47c3d2a9 --- /dev/null +++ b/LunaTranslator/LunaTranslator/translator/baiduqianfan.py @@ -0,0 +1,132 @@ +from translator.basetranslator import basetrans +import json, requests +from traceback import print_exc + + +class TS(basetrans): + + def langmap(self): + return { + "zh": "Simplified Chinese", + "ja": "Japanese", + "en": "English", + "ru": "Russian", + "es": "Spanish", + "ko": "Korean", + "fr": "French", + "cht": "Traditional Chinese", + "vi": "Vietnamese", + "tr": "Turkish", + "pl": "Polish", + "uk": "Ukrainian", + "it": "Italian", + "ar": "Arabic", + "th": "Thai", + } + + def __init__(self, typename): + self.context = [] + self.access = {} + super().__init__(typename) + + def createdata(self, message): + try: + temperature = float(self.config["Temperature"]) + except: + temperature = 0.3 + + if self.config["use_user_prompt"]: + system = self.config["user_prompt"] + else: + system = "You are a translator. Please help me translate the following {} text into {}, and you should only tell me the translation.".format( + self.srclang, self.tgtlang + ) + data = dict( + system=system, + model=self.config["model"], + messages=message, + # optional + max_tokens=self.config["max_tokens"], + n=1, + # stop=None, + top_p=self.config["top_p"], + temperature=temperature, + frequency_penalty=self.config["frequency_penalty"], + stream=self.config["usingstream"], + ) + return data + + def commonparseresponse(self, query, response: requests.ResponseBase, usingstream): + if usingstream: + message = "" + for chunk in response.iter_lines(): + response_data = chunk.decode("utf-8").strip() + if not response_data: + continue + try: + json_data = json.loads(response_data[6:]) + msg = json_data["result"].replace("\n\n", "\n").strip() + yield msg + message += msg + + except: + print_exc() + raise Exception(response_data) + else: + try: + message = response.json()["result"].replace("\n\n", "\n").strip() + yield message + except: + raise Exception(response.text) + self.context.append({"role": "user", "content": query}) + self.context.append({"role": "assistant", "content": message}) + + def get_access_token(self, API_KEY, SECRET_KEY): + url = "https://aip.baidubce.com/oauth/2.0/token" + params = { + "grant_type": "client_credentials", + "client_id": API_KEY, + "client_secret": SECRET_KEY, + } + js = self.proxysession.post(url, params=params).json() + + try: + return js["access_token"] + except: + raise Exception(js) + + def checkchange(self): + self.checkempty(["model", "SECRET_KEY", "API_KEY"]) + SECRET_KEY, API_KEY = ( + self.multiapikeycurrent["SECRET_KEY"], + self.multiapikeycurrent["API_KEY"], + ) + if not self.access.get((API_KEY, SECRET_KEY)): + acss = self.get_access_token(API_KEY, SECRET_KEY) + self.access[(API_KEY, SECRET_KEY)] = acss + return self.access[(API_KEY, SECRET_KEY)] + + def translate(self, query): + acss = self.checkchange() + self.contextnum = int(self.config["context_num"]) + + message = [] + for _i in range(min(len(self.context) // 2, self.contextnum)): + i = ( + len(self.context) // 2 + - min(len(self.context) // 2, self.contextnum) + + _i + ) + message.append(self.context[i * 2]) + message.append(self.context[i * 2 + 1]) + message.append({"role": "user", "content": query}) + + usingstream = self.config["usingstream"] + url = f"https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/{self.config['model']}?access_token={acss}" + + response = self.proxysession.post( + url, + json=self.createdata(message), + stream=usingstream, + ) + return self.commonparseresponse(query, response, usingstream) diff --git a/LunaTranslator/LunaTranslator/translator/gptcommon.py b/LunaTranslator/LunaTranslator/translator/gptcommon.py index 2b808fea..532fdd28 100644 --- a/LunaTranslator/LunaTranslator/translator/gptcommon.py +++ b/LunaTranslator/LunaTranslator/translator/gptcommon.py @@ -69,52 +69,6 @@ class gptcommon(basetrans): api_url += "/v1" return api_url - def alicreateheaders(self): - h = self.createheaders() - if self.config["流式输出"]: - h.update({"Accept": "text/event-stream"}) - return h - - def alicreatedata(self, message): - - data = dict(model=self.config["model"], input=dict(messages=message)) - if self.config["流式输出"]: - data.update(dict(parameters=dict(incremental_output=True))) - - return data - - def aliparseresponse(self, query, response: requests.ResponseBase, usingstream): - if usingstream: - message = "" - for chunk in response.iter_lines(): - response_data = chunk.decode("utf-8").strip() - if not response_data: - continue - if response_data.startswith("data:") == False: - continue - try: - json_data = json.loads(response_data[5:]) - msg = json_data["output"]["text"] - yield msg - message += msg - except: - print_exc() - raise Exception(response_data) - - if json_data["output"]["finish_reason"] == "stop": - break - - else: - try: - message = ( - response.json()["output"]["text"].replace("\n\n", "\n").strip() - ) - yield message - except: - raise Exception(response.text) - self.context.append({"role": "user", "content": query}) - self.context.append({"role": "assistant", "content": message}) - def commonparseresponse(self, query, response: requests.ResponseBase, usingstream): if usingstream: message = "" @@ -175,24 +129,15 @@ class gptcommon(basetrans): usingstream = self.config["流式输出"] url = self.config["API接口地址"] - parseresponse = self.commonparseresponse - createheaders = self.createheaders - createdata = self.createdata if url.endswith("/chat/completions"): pass - elif url.endswith("/text-generation/generation") or 'dashscope.aliyuncs.com' in url: - # https://dashscope.aliyuncs.com/api/v1/services/aigc/text-generation/generation - # 阿里云百炼 - parseresponse = self.aliparseresponse - createheaders = self.alicreateheaders - createdata = self.alicreatedata else: url = self.checkv1(url) + "/chat/completions" response = self.proxysession.post( url, - headers=createheaders(), + headers=self.createheaders(), params=self.createparam(), - json=createdata(message), + json=self.createdata(message), stream=usingstream, ) - return parseresponse(query, response, usingstream) + return self.commonparseresponse(query, response, usingstream) diff --git a/LunaTranslator/LunaTranslator/translator/txhunyuan.py b/LunaTranslator/LunaTranslator/translator/txhunyuan.py new file mode 100644 index 00000000..b262a330 --- /dev/null +++ b/LunaTranslator/LunaTranslator/translator/txhunyuan.py @@ -0,0 +1,185 @@ +from translator.basetranslator import basetrans +import json + +from datetime import datetime +import hashlib, sys, hmac, time, json + + +def sign_tc3(secret_key, date, service, str2sign): + def _hmac_sha256(key, msg): + return hmac.new(key, msg.encode("utf-8"), hashlib.sha256) + + def _get_signature_key(key, date, service): + k_date = _hmac_sha256(("TC3" + key).encode("utf-8"), date) + k_service = _hmac_sha256(k_date.digest(), service) + k_signing = _hmac_sha256(k_service.digest(), "tc3_request") + return k_signing.digest() + + signing_key = _get_signature_key(secret_key, date, service) + signature = _hmac_sha256(signing_key, str2sign).hexdigest() + return signature + + +def _get_tc3_signature( + header, method, canonical_uri, payload, secret_key, date, service, options=None +): + options = options or {} + canonical_querystring = "" + + if sys.version_info[0] == 3 and isinstance(payload, type("")): + payload = payload.encode("utf8") + + payload_hash = hashlib.sha256(payload).hexdigest() + + canonical_headers = "content-type:%s\nhost:%s\n" % ( + header["Content-Type"], + header["Host"], + ) + signed_headers = "content-type;host" + canonical_request = "%s\n%s\n%s\n%s\n%s\n%s" % ( + method, + canonical_uri, + canonical_querystring, + canonical_headers, + signed_headers, + payload_hash, + ) + + algorithm = "TC3-HMAC-SHA256" + credential_scope = date + "/" + service + "/tc3_request" + if sys.version_info[0] == 3: + canonical_request = canonical_request.encode("utf8") + digest = hashlib.sha256(canonical_request).hexdigest() + string2sign = "%s\n%s\n%s\n%s" % ( + algorithm, + header["X-TC-Timestamp"], + credential_scope, + digest, + ) + + return sign_tc3(secret_key, date, service, string2sign) + + +def _build_req_with_tc3_signature(key, _id, action, params, options=None): + header = {} + header["Content-Type"] = "application/json" + + endpoint = "hunyuan.tencentcloudapi.com" + timestamp = int(time.time()) + header["Host"] = endpoint + header["X-TC-Action"] = action[0].upper() + action[1:] + header["X-TC-RequestClient"] = "SDK_PYTHON_3.0.1193" + header["X-TC-Timestamp"] = str(timestamp) + header["X-TC-Version"] = "2023-09-01" + data = json.dumps(params).encode("utf8") + + service = "hunyuan" + date = datetime.utcfromtimestamp(timestamp).strftime("%Y-%m-%d") + signature = _get_tc3_signature( + header, "POST", "/", data, key, date, service, options + ) + + auth = ( + "TC3-HMAC-SHA256 Credential=%s/%s/%s/tc3_request, SignedHeaders=content-type;host, Signature=%s" + % (_id, date, service, signature) + ) + header["Authorization"] = auth + return header + + +class TS(basetrans): + + def langmap(self): + return { + "zh": "Simplified Chinese", + "ja": "Japanese", + "en": "English", + "ru": "Russian", + "es": "Spanish", + "ko": "Korean", + "fr": "French", + "cht": "Traditional Chinese", + "vi": "Vietnamese", + "tr": "Turkish", + "pl": "Polish", + "uk": "Ukrainian", + "it": "Italian", + "ar": "Arabic", + "th": "Thai", + } + + def __init__(self, typename): + self.context = [] + super().__init__(typename) + + def translate(self, query): + self.checkempty(["secret_id", "secret_key"]) + self.contextnum = int(self.config["context_num"]) + + if self.config["use_user_prompt"]: + message = [{"Role": "user", "Content": self.config["user_prompt"]}] + else: + message = [ + { + "Role": "system", + "Content": "You are a translator. Please help me translate the following {} text into {}, and you should only tell me the translation.".format( + self.srclang, self.tgtlang + ), + }, + ] + + for _i in range(min(len(self.context) // 2, self.contextnum)): + i = ( + len(self.context) // 2 + - min(len(self.context) // 2, self.contextnum) + + _i + ) + message.append(self.context[i * 2]) + message.append(self.context[i * 2 + 1]) + message.append({"Role": "user", "Content": query}) + usingstream = self.config["usingstream"] + json_data = { + "Model": self.config["model"], + "Messages": message, + "Stream": usingstream, + "TopP": self.config["top_p"], + "Temperature": self.config["Temperature"], + } + headers = _build_req_with_tc3_signature( + self.multiapikeycurrent["secret_id"], + self.multiapikeycurrent["secret_key"], + "ChatCompletions", + json_data, + ) + response = self.proxysession.post( + "https://hunyuan.tencentcloudapi.com/", + headers=headers, + data=json.dumps(json_data), + stream=usingstream, + ) + + if usingstream: + message = "" + for i in response.iter_lines(): + + if not i: + continue + i = i.decode("utf8")[6:] + try: + mes = json.loads(i)["Choices"][0]["Delta"]["Content"] + except: + raise Exception(i) + yield mes + message += mes + + else: + try: + message = response.json()["Response"]["Choices"][0]["Message"][ + "Content" + ] + yield message + except: + raise Exception(response.text) + + self.context.append({"Role": "user", "Content": query}) + self.context.append({"Role": "assistant", "Content": message}) diff --git a/LunaTranslator/files/defaultconfig/config.json b/LunaTranslator/files/defaultconfig/config.json index 5dd2cbbe..4fb5ce0c 100644 --- a/LunaTranslator/files/defaultconfig/config.json +++ b/LunaTranslator/files/defaultconfig/config.json @@ -1732,6 +1732,20 @@ "color": "blue", "name": "腾讯api" }, + "txhunyuan": { + "type": "api", + "use": false, + "color": "blue", + "name": "腾讯混元大模型", + "is_gpt_like":true + }, + "baiduqianfan": { + "type": "api", + "use": false, + "color": "blue", + "name": "百度千帆大模型", + "is_gpt_like":true + }, "yandexapi": { "type": "api", "use": false, diff --git a/LunaTranslator/files/defaultconfig/translatorsetting.json b/LunaTranslator/files/defaultconfig/translatorsetting.json index 5990e223..ae18e51e 100644 --- a/LunaTranslator/files/defaultconfig/translatorsetting.json +++ b/LunaTranslator/files/defaultconfig/translatorsetting.json @@ -263,6 +263,51 @@ } } }, + "txhunyuan": { + "args": { + "secret_id": "", + "secret_key": "", + "Temperature": 0.3, + "top_p": 0.3, + "model": "hunyuan-lite", + "context_num": 0, + "use_user_prompt": false, + "user_prompt": "", + "usingstream": false + }, + "argstype": { + "top_p": { + "type": "spin", + "min": 0, + "max": 1, + "step": 0.01 + }, + "usingstream": { + "name": "流式输出", + "type": "switch" + }, + "user_prompt": { + "name": "自定义promt" + }, + "use_user_prompt": { + "name": "使用自定义promt", + "type": "switch" + }, + "context_num": { + "name": "附带上下文个数", + "type": "intspin", + "min": 0, + "max": 10, + "step": 1 + }, + "Temperature": { + "type": "spin", + "min": 0, + "max": 1, + "step": 0.1 + } + } + }, "claude": { "args": { "BASE_URL": "https://api.anthropic.com", @@ -347,9 +392,64 @@ "max": 10, "step": 1 }, - "使用说明": { - "type": "label", - "islink": false + "Temperature": { + "type": "spin", + "min": 0, + "max": 1, + "step": 0.1 + } + } + }, + "baiduqianfan": { + "args": { + "model": "ernie-3.5-8k-0329", + "context_num": 0, + "API_KEY": "", + "SECRET_KEY": "", + "use_user_prompt": false, + "user_prompt": "", + "usingstream": false, + "Temperature": 0.3, + "top_p": 0.3, + "max_tokens": 128, + "frequency_penalty": 0 + }, + "argstype": { + "top_p": { + "type": "spin", + "min": 0, + "max": 1, + "step": 0.01 + }, + "frequency_penalty": { + "type": "spin", + "min": 0, + "max": 2, + "step": 0.05 + }, + "max_tokens": { + "type": "intspin", + "min": 1, + "max": 4096, + "step": 1 + }, + "user_prompt": { + "name": "自定义promt" + }, + "usingstream": { + "name": "流式输出", + "type": "switch" + }, + "use_user_prompt": { + "name": "使用自定义promt", + "type": "switch" + }, + "context_num": { + "name": "附带上下文个数", + "type": "intspin", + "min": 0, + "max": 10, + "step": 1 }, "Temperature": { "type": "spin", @@ -382,10 +482,6 @@ "max": 10, "step": 1 }, - "使用说明": { - "type": "label", - "islink": false - }, "Temperature": { "type": "spin", "min": 0, @@ -661,10 +757,6 @@ "type": "label", "islink": true }, - "使用说明": { - "type": "label", - "islink": false - }, "API超时(秒)": { "type": "intspin", "min": 30, diff --git a/LunaTranslator/files/lang/ar.json b/LunaTranslator/files/lang/ar.json index a63b4e71..f60a3162 100644 --- a/LunaTranslator/files/lang/ar.json +++ b/LunaTranslator/files/lang/ar.json @@ -823,5 +823,9 @@ "总是检测": "دائما الكشف", "动态检测": "دينامية اختبار", "从不检测": "لم تكتشف", - "找不到文本?": "لا يمكن العثور على النص ؟" + "找不到文本?": "لا يمكن العثور على النص ؟", + "腾讯混元大模型": "تينسنت الهجين نموذج كبير", + "传统": "تقليدي", + "大模型": "نموذج كبير", + "百度千帆大模型": "نموذج بايدو" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/cht.json b/LunaTranslator/files/lang/cht.json index 23af05a5..fed4362b 100644 --- a/LunaTranslator/files/lang/cht.json +++ b/LunaTranslator/files/lang/cht.json @@ -823,5 +823,9 @@ "总是检测": "總是檢測", "动态检测": "動態檢測", "从不检测": "從不檢測", - "找不到文本?": "找不到文字?" + "找不到文本?": "找不到文字?", + "腾讯混元大模型": "騰訊混元大模型", + "传统": "傳統", + "大模型": "大模型", + "百度千帆大模型": "百度千帆大模型" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/en.json b/LunaTranslator/files/lang/en.json index 13cb9560..7d7e078b 100644 --- a/LunaTranslator/files/lang/en.json +++ b/LunaTranslator/files/lang/en.json @@ -823,5 +823,9 @@ "总是检测": "Always checking", "动态检测": "Dynamic detection", "从不检测": "Never detect", - "找不到文本?": "Can't find text?" + "找不到文本?": "Can't find text?", + "腾讯混元大模型": "Tencent's hybrid big model", + "传统": "tradition", + "大模型": "Large model", + "百度千帆大模型": "Baidu Qianfan Large Model" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/es.json b/LunaTranslator/files/lang/es.json index d28077cb..b030068a 100644 --- a/LunaTranslator/files/lang/es.json +++ b/LunaTranslator/files/lang/es.json @@ -823,5 +823,9 @@ "总是检测": "Siempre detectado", "动态检测": "Detección dinámica", "从不检测": "Nunca detectar", - "找不到文本?": "¿No se puede encontrar el texto?" + "找不到文本?": "¿No se puede encontrar el texto?", + "腾讯混元大模型": "El gran modelo híbrido de Tencent", + "传统": "Tradición", + "大模型": "Gran modelo", + "百度千帆大模型": "Modelo Baidu qianfan" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/fr.json b/LunaTranslator/files/lang/fr.json index 40c76b4c..5e4d0014 100644 --- a/LunaTranslator/files/lang/fr.json +++ b/LunaTranslator/files/lang/fr.json @@ -823,5 +823,9 @@ "总是检测": "Toujours détecter", "动态检测": "Détection dynamique", "从不检测": "Jamais détecté", - "找不到文本?": "Vous ne trouvez pas le texte?" + "找不到文本?": "Vous ne trouvez pas le texte?", + "腾讯混元大模型": "Tencent hybride grand modèle", + "传统": "La tradition", + "大模型": "Le grand modèle", + "百度千帆大模型": "Baidu mille voiles modèle" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/it.json b/LunaTranslator/files/lang/it.json index 2ce9237c..6d920579 100644 --- a/LunaTranslator/files/lang/it.json +++ b/LunaTranslator/files/lang/it.json @@ -823,5 +823,9 @@ "总是检测": "Controllo sempre", "动态检测": "Rilevamento dinamico", "从不检测": "Non rilevare mai", - "找不到文本?": "Non trovi il messaggio?" + "找不到文本?": "Non trovi il messaggio?", + "腾讯混元大模型": "Il grande modello ibrido di Tencent", + "传统": "tradizione", + "大模型": "Modello grande", + "百度千帆大模型": "Baidu Qianfan Modello grande" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/ja.json b/LunaTranslator/files/lang/ja.json index 04602361..46ba1cfa 100644 --- a/LunaTranslator/files/lang/ja.json +++ b/LunaTranslator/files/lang/ja.json @@ -823,5 +823,9 @@ "总是检测": "常に検出", "动态检测": "どうてきけんしゅつ", "从不检测": "検出しない", - "找不到文本?": "テキストが見つかりませんか?" + "找不到文本?": "テキストが見つかりませんか?", + "腾讯混元大模型": "テンセント混元大モデル", + "传统": "従来の", + "大模型": "ビッグモデル", + "百度千帆大模型": "百度千帆大模型" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/ko.json b/LunaTranslator/files/lang/ko.json index f9e49fb7..ae4a1dbd 100644 --- a/LunaTranslator/files/lang/ko.json +++ b/LunaTranslator/files/lang/ko.json @@ -823,5 +823,9 @@ "总是检测": "항상 테스트", "动态检测": "동적 체크", "从不检测": "테스트하지 않음", - "找不到文本?": "텍스트를 찾을 수 없습니까?" + "找不到文本?": "텍스트를 찾을 수 없습니까?", + "腾讯混元大模型": "텐센트 혼원대모델", + "传统": "전통", + "大模型": "대형 모델", + "百度千帆大模型": "바이두 천범대 모형" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/pl.json b/LunaTranslator/files/lang/pl.json index bd8d69f1..b6e775d5 100644 --- a/LunaTranslator/files/lang/pl.json +++ b/LunaTranslator/files/lang/pl.json @@ -823,5 +823,9 @@ "总是检测": "Zawsze sprawdzam", "动态检测": "Wykrywanie dynamiczne", "从不检测": "Nigdy nie wykrywaj", - "找不到文本?": "Nie możesz znaleźć smsa?" + "找不到文本?": "Nie możesz znaleźć smsa?", + "腾讯混元大模型": "Hybrydowy duży model Tencent", + "传统": "tradycja", + "大模型": "Duży model", + "百度千帆大模型": "Duży model Baidu Qianfan" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/ru.json b/LunaTranslator/files/lang/ru.json index fc2f84a0..e4507210 100644 --- a/LunaTranslator/files/lang/ru.json +++ b/LunaTranslator/files/lang/ru.json @@ -823,5 +823,9 @@ "总是检测": "Всегда проверяйте", "动态检测": "Динамический контроль", "从不检测": "Никогда не проверяю.", - "找不到文本?": "Не удалось найти текст?" + "找不到文本?": "Не удалось найти текст?", + "腾讯混元大模型": "Большая гибридная модель.", + "传统": "Традиции", + "大模型": "Большая модель", + "百度千帆大模型": "Сто тысяч парусов." } \ No newline at end of file diff --git a/LunaTranslator/files/lang/th.json b/LunaTranslator/files/lang/th.json index 887170e6..d61c2f6a 100644 --- a/LunaTranslator/files/lang/th.json +++ b/LunaTranslator/files/lang/th.json @@ -823,5 +823,9 @@ "总是检测": "ตรวจจับเสมอ", "动态检测": "การตรวจจับแบบไดนามิก", "从不检测": "ไม่เคยตรวจจับ", - "找不到文本?": "ไม่พบข้อความ?" + "找不到文本?": "ไม่พบข้อความ?", + "腾讯混元大模型": "Tencent Mixed หยวนรุ่นใหญ่", + "传统": "ประเพณี", + "大模型": "โมเดลขนาดใหญ่", + "百度千帆大模型": "Baidu Qianfan โมเดลขนาดใหญ่" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/tr.json b/LunaTranslator/files/lang/tr.json index 63df8383..b79a327e 100644 --- a/LunaTranslator/files/lang/tr.json +++ b/LunaTranslator/files/lang/tr.json @@ -823,5 +823,9 @@ "总是检测": "Her zaman kontrol ediyor", "动态检测": "Dinamik tanıma", "从不检测": "Asla tanıma", - "找不到文本?": "Mesaj bulamıyor musun?" + "找不到文本?": "Mesaj bulamıyor musun?", + "腾讯混元大模型": "Tencent'in hibrid büyük modeli", + "传统": "gelenek", + "大模型": "Büyük model", + "百度千帆大模型": "Baidu Qianfan Büyük Modeli" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/uk.json b/LunaTranslator/files/lang/uk.json index 07ac784a..c15b521b 100644 --- a/LunaTranslator/files/lang/uk.json +++ b/LunaTranslator/files/lang/uk.json @@ -823,5 +823,9 @@ "总是检测": "Завжди перевіряється", "动态检测": "Динамічне виявлення", "从不检测": "Ніколи не визначити", - "找不到文本?": "Не вдалося знайти текст?" + "找不到文本?": "Не вдалося знайти текст?", + "腾讯混元大模型": "Велика гібридна модель", + "传统": "традиція", + "大模型": "Велика модель", + "百度千帆大模型": "Великий модель Baidu Qianfan" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/vi.json b/LunaTranslator/files/lang/vi.json index ae831e5f..1c84d716 100644 --- a/LunaTranslator/files/lang/vi.json +++ b/LunaTranslator/files/lang/vi.json @@ -823,5 +823,9 @@ "总是检测": "Luôn phát hiện", "动态检测": "Phát hiện động", "从不检测": "Không bao giờ phát hiện", - "找不到文本?": "Không tìm thấy văn bản?" + "找不到文本?": "Không tìm thấy văn bản?", + "腾讯混元大模型": "Mô hình hỗn hợp lớn", + "传统": "Truyền thống", + "大模型": "Mô hình lớn", + "百度千帆大模型": "Mô hình 100.000 cánh buồm" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/zh.json b/LunaTranslator/files/lang/zh.json index 411dd4cc..b580fe1f 100644 --- a/LunaTranslator/files/lang/zh.json +++ b/LunaTranslator/files/lang/zh.json @@ -823,5 +823,9 @@ "无缩放": "", "总是检测": "", "动态检测": "", - "从不检测": "" + "从不检测": "", + "腾讯混元大模型": "", + "传统": "", + "大模型": "", + "百度千帆大模型": "" } \ No newline at end of file diff --git a/docs/style.css b/docs/style.css index cd4299df..208da215 100644 --- a/docs/style.css +++ b/docs/style.css @@ -139,4 +139,17 @@ main { main .markdown-section { display: none; } -*/ \ No newline at end of file +*/ + +.alert { + padding: 10px; + background-color: #ff9; + border-left: 6px solid #ff0; + margin-bottom: 10px; + color: black; +} + +.alert-warning { + background-color: #f0ad4e; + border-color: #ec971f; +} \ No newline at end of file diff --git a/docs/zh/guochandamoxing.md b/docs/zh/guochandamoxing.md index 81d4932a..0ea02868 100644 --- a/docs/zh/guochandamoxing.md +++ b/docs/zh/guochandamoxing.md @@ -1,7 +1,20 @@ -## 国产大模型如何使用ChatGPT兼容接口 +## 如何使用国产大模型API接口 + +## ChatGPT兼容接口 + +### DeepSeek + +**API接口地址** `https://api.deepseek.com` + +### 阿里云百炼大模型 + + +**API接口地址** `https://dashscope.aliyuncs.com/compatible-mode/v1` ### 字节跳动豆包大模型等 + + **API接口地址** `https://ark.cn-beijing.volces.com/api/v3` **SECRET_KEY** 跟[官方文档](https://www.volcengine.com/docs/82379/1263279)获取 @@ -10,8 +23,21 @@ ![img](https://image.lunatranslator.xyz/zh/damoxing/doubao.png) +## 不兼容的专用接口 -### 阿里云百炼大模型 +### 腾讯混元大模型 -**API接口地址** `https://dashscope.aliyuncs.com/api/v1/services/aigc/text-generation/generation` +略 + +### 百度千帆大模型 + +