mirror of
https://github.com/HIllya51/LunaTranslator.git
synced 2025-01-01 10:04:12 +08:00
dev
This commit is contained in:
parent
ad03159759
commit
270299a475
@ -0,0 +1,36 @@
|
|||||||
|
const originXHR = XMLHttpRequest
|
||||||
|
|
||||||
|
window.XMLHttpRequest = function () {
|
||||||
|
var newxhr = new originXHR()
|
||||||
|
newxhr.open_ori = newxhr.open
|
||||||
|
|
||||||
|
newxhr.open = function () {
|
||||||
|
var input=arguments[1]
|
||||||
|
if (%s) {
|
||||||
|
|
||||||
|
newxhr.onprogress_ori = newxhr.onprogress
|
||||||
|
newxhr.offset=0
|
||||||
|
newxhr.onprogress = function (event) {
|
||||||
|
var current=newxhr.responseText
|
||||||
|
var lines=current.substring(newxhr.offset)
|
||||||
|
lines = lines.split('\n')
|
||||||
|
for (let i = 0; i < lines.length; i++) {
|
||||||
|
let line = lines[i]
|
||||||
|
line = line.trim()
|
||||||
|
if (line.length == 0) continue;
|
||||||
|
try {
|
||||||
|
%s
|
||||||
|
} catch {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
newxhr.offset=current.length;
|
||||||
|
if(newxhr.onprogress_ori)
|
||||||
|
return newxhr.onprogress_ori.apply(this, arguments);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return newxhr.open_ori.apply(this, arguments);
|
||||||
|
};
|
||||||
|
|
||||||
|
return newxhr
|
||||||
|
}
|
73
LunaTranslator/LunaTranslator/translator/dev_deepseek.py
Normal file
73
LunaTranslator/LunaTranslator/translator/dev_deepseek.py
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
from translator.basetranslator_dev import basetransdev
|
||||||
|
import time, os
|
||||||
|
|
||||||
|
|
||||||
|
class TS(basetransdev):
|
||||||
|
target_url = "https://chat.deepseek.com/"
|
||||||
|
|
||||||
|
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 injectjs(self):
|
||||||
|
if self.Runtime_evaluate("window.injectedjs")["result"]["type"] != "undefined":
|
||||||
|
return
|
||||||
|
with open(
|
||||||
|
os.path.join(os.path.dirname(__file__), "commonhookxhrstream.js"),
|
||||||
|
"r",
|
||||||
|
encoding="utf8",
|
||||||
|
) as ff:
|
||||||
|
js = ff.read() % (
|
||||||
|
"input.endsWith('v0/chat/completions')",
|
||||||
|
r"""const chunk = JSON.parse(line.substring(6));
|
||||||
|
if(!!(chunk.choices[0].delta.content))
|
||||||
|
thistext += chunk.choices[0].delta.content""",
|
||||||
|
)
|
||||||
|
self.Runtime_evaluate(js)
|
||||||
|
self.Runtime_evaluate("window.injectedjs=true")
|
||||||
|
|
||||||
|
def translate(self, content):
|
||||||
|
self.injectjs()
|
||||||
|
|
||||||
|
self.Runtime_evaluate("hasdone=false")
|
||||||
|
self.Runtime_evaluate('thistext=""')
|
||||||
|
if self.config["use_custom_prompt"]:
|
||||||
|
prompt = self.config["custom_prompt"]
|
||||||
|
else:
|
||||||
|
prompt = "You are a translator. Please help me translate the following {} text into {}, and you should only tell me the translation.\n".format(
|
||||||
|
self.srclang, self.tgtlang
|
||||||
|
)
|
||||||
|
content = prompt + content
|
||||||
|
self.Runtime_evaluate('document.querySelector("#chat-input").click()')
|
||||||
|
self.send_keys(content)
|
||||||
|
self.Runtime_evaluate("document.getElementsByClassName('_89d4d19')[1].click()")
|
||||||
|
if self.config["usingstream"]:
|
||||||
|
curr = ""
|
||||||
|
while not self.Runtime_evaluate("hasdone")["result"]["value"]:
|
||||||
|
time.sleep(0.1)
|
||||||
|
thistext = self.Runtime_evaluate("thistext")["result"]["value"]
|
||||||
|
if thistext.startswith(curr):
|
||||||
|
yield thistext[len(curr) :]
|
||||||
|
else:
|
||||||
|
yield thistext
|
||||||
|
curr = thistext
|
||||||
|
else:
|
||||||
|
while not self.Runtime_evaluate("hasdone")["result"]["value"]:
|
||||||
|
time.sleep(0.1)
|
||||||
|
continue
|
||||||
|
yield self.Runtime_evaluate("thistext")["result"]["value"]
|
@ -1596,6 +1596,13 @@
|
|||||||
"name": "chatglm",
|
"name": "chatglm",
|
||||||
"is_gpt_like": true
|
"is_gpt_like": true
|
||||||
},
|
},
|
||||||
|
"dev_deepseek": {
|
||||||
|
"use": false,
|
||||||
|
"color": "blue",
|
||||||
|
"type": "dev",
|
||||||
|
"name": "deepseek",
|
||||||
|
"is_gpt_like": true
|
||||||
|
},
|
||||||
"deepl_dev": {
|
"deepl_dev": {
|
||||||
"use": false,
|
"use": false,
|
||||||
"color": "blue",
|
"color": "blue",
|
||||||
|
@ -820,6 +820,28 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"dev_deepseek": {
|
||||||
|
"args": {
|
||||||
|
"usingstream": true,
|
||||||
|
"use_custom_prompt": false,
|
||||||
|
"custom_prompt": ""
|
||||||
|
},
|
||||||
|
"argstype": {
|
||||||
|
"usingstream": {
|
||||||
|
"name": "流式输出",
|
||||||
|
"type": "switch"
|
||||||
|
},
|
||||||
|
"custom_prompt": {
|
||||||
|
"name": "自定义promt",
|
||||||
|
"type": "multiline",
|
||||||
|
"refswitch": "use_custom_prompt"
|
||||||
|
},
|
||||||
|
"use_custom_prompt": {
|
||||||
|
"type": "switch_ref",
|
||||||
|
"name": "使用自定义promt"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"gemini": {
|
"gemini": {
|
||||||
"args": {
|
"args": {
|
||||||
"注册网址": "https://ai.google.dev/tutorials/python_quickstart",
|
"注册网址": "https://ai.google.dev/tutorials/python_quickstart",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user