mirror of
https://github.com/HIllya51/LunaTranslator.git
synced 2024-12-29 16:44:13 +08:00
dev
This commit is contained in:
parent
cd136a2ef0
commit
a83c9ff745
@ -4,7 +4,7 @@ var hasdone = true
|
|||||||
var thistext = ''
|
var thistext = ''
|
||||||
window.fetch = function (input, init) {
|
window.fetch = function (input, init) {
|
||||||
const fetchPromise = originalFetch.apply(this, arguments);
|
const fetchPromise = originalFetch.apply(this, arguments);
|
||||||
if (!input.includes("conversation")) return fetchPromise;
|
if (!%s) return fetchPromise;
|
||||||
hasdone = false;
|
hasdone = false;
|
||||||
thistext = ''
|
thistext = ''
|
||||||
fetchPromise.then(response => {
|
fetchPromise.then(response => {
|
||||||
@ -26,9 +26,7 @@ window.fetch = function (input, init) {
|
|||||||
line = line.trim()
|
line = line.trim()
|
||||||
if (line.length == 0) continue;
|
if (line.length == 0) continue;
|
||||||
try {
|
try {
|
||||||
const chunk = JSON.parse(line.substring(6));
|
%s
|
||||||
console.log("Chunk received:", chunk.message.content.parts[0]);
|
|
||||||
thistext = chunk.message.content.parts[0]
|
|
||||||
} catch {
|
} catch {
|
||||||
|
|
||||||
}
|
}
|
@ -28,11 +28,15 @@ class TS(basetransdev):
|
|||||||
if self.Runtime_evaluate("window.injectedjs")["result"]["type"] != "undefined":
|
if self.Runtime_evaluate("window.injectedjs")["result"]["type"] != "undefined":
|
||||||
return
|
return
|
||||||
with open(
|
with open(
|
||||||
os.path.join(os.path.dirname(__file__), "dev_chatgpt.js"),
|
os.path.join(os.path.dirname(__file__), "commonhookfetchstream.js"),
|
||||||
"r",
|
"r",
|
||||||
encoding="utf8",
|
encoding="utf8",
|
||||||
) as ff:
|
) as ff:
|
||||||
js = ff.read()
|
js = ff.read() % (
|
||||||
|
'input.includes("conversation")',
|
||||||
|
r"""const chunk = JSON.parse(line.substring(6));
|
||||||
|
thistext = chunk.message.content.parts[0]""",
|
||||||
|
)
|
||||||
self.Runtime_evaluate(js)
|
self.Runtime_evaluate(js)
|
||||||
self.Runtime_evaluate("window.injectedjs=true")
|
self.Runtime_evaluate("window.injectedjs=true")
|
||||||
|
|
||||||
@ -49,7 +53,7 @@ class TS(basetransdev):
|
|||||||
)
|
)
|
||||||
content = prompt + content
|
content = prompt + content
|
||||||
self.Runtime_evaluate(
|
self.Runtime_evaluate(
|
||||||
'textarea=document.querySelector("#prompt-textarea");textarea.value="";event = new Event("input", {{bubbles: true, cancelable: true }});textarea.dispatchEvent(event);textarea=document.querySelector("textarea");textarea.value=`{}`;event = new Event("input", {{bubbles: true, cancelable: true }});textarea.dispatchEvent(event);'.format(
|
'textarea=document.querySelector("#prompt-textarea");textarea.value="";event = new Event("input", {{bubbles: true, cancelable: true }});textarea.dispatchEvent(event);textarea.value=`{}`;event = new Event("input", {{bubbles: true, cancelable: true }});textarea.dispatchEvent(event);'.format(
|
||||||
content
|
content
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -28,11 +28,17 @@ class TS(basetransdev):
|
|||||||
if self.Runtime_evaluate("window.injectedjs")["result"]["type"] != "undefined":
|
if self.Runtime_evaluate("window.injectedjs")["result"]["type"] != "undefined":
|
||||||
return
|
return
|
||||||
with open(
|
with open(
|
||||||
os.path.join(os.path.dirname(__file__), "dev_moonshot.js"),
|
os.path.join(os.path.dirname(__file__), "commonhookfetchstream.js"),
|
||||||
"r",
|
"r",
|
||||||
encoding="utf8",
|
encoding="utf8",
|
||||||
) as ff:
|
) as ff:
|
||||||
js = ff.read()
|
js = ff.read() % (
|
||||||
|
'input.endsWith("completion/stream")',
|
||||||
|
"""const chunk = JSON.parse(line.substring(6));
|
||||||
|
if(chunk.event!='cmpl')continue;
|
||||||
|
if(chunk.text)
|
||||||
|
thistext += chunk.text""",
|
||||||
|
)
|
||||||
self.Runtime_evaluate(js)
|
self.Runtime_evaluate(js)
|
||||||
self.Runtime_evaluate("window.injectedjs=true")
|
self.Runtime_evaluate("window.injectedjs=true")
|
||||||
|
|
||||||
|
74
LunaTranslator/LunaTranslator/translator/dev_qwen.py
Normal file
74
LunaTranslator/LunaTranslator/translator/dev_qwen.py
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
from translator.basetranslator_dev import basetransdev
|
||||||
|
import time, os
|
||||||
|
|
||||||
|
|
||||||
|
class TS(basetransdev):
|
||||||
|
target_url = "https://tongyi.aliyun.com/qianwen"
|
||||||
|
|
||||||
|
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__), "commonhookfetchstream.js"),
|
||||||
|
"r",
|
||||||
|
encoding="utf8",
|
||||||
|
) as ff:
|
||||||
|
js = ff.read() % (
|
||||||
|
'input.endsWith("dialog/conversation")',
|
||||||
|
r"""const chunk = JSON.parse(line.substring(6));
|
||||||
|
thistext = chunk.contents[0].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.getElementsByTagName("textarea")[0].click()')
|
||||||
|
self.send_keys(content)
|
||||||
|
self.Runtime_evaluate(
|
||||||
|
r"""document.querySelector("#tongyiPageLayout > div.sc-fQpRED.jsoEZg > div > div.sc-hNGPaV.erDcgy.pageContentWrap--AovzQ5wq > div > div.inputField--PE5FhWzd > div > div.chatInput--eJzBH8LP > div.operateBtn--zFx6rSR0").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"]
|
@ -1582,6 +1582,13 @@
|
|||||||
"name": "moonshot",
|
"name": "moonshot",
|
||||||
"is_gpt_like": true
|
"is_gpt_like": true
|
||||||
},
|
},
|
||||||
|
"dev_qwen": {
|
||||||
|
"use": false,
|
||||||
|
"color": "blue",
|
||||||
|
"type": "dev",
|
||||||
|
"name": "qianwen",
|
||||||
|
"is_gpt_like": true
|
||||||
|
},
|
||||||
"deepl_dev": {
|
"deepl_dev": {
|
||||||
"use": false,
|
"use": false,
|
||||||
"color": "blue",
|
"color": "blue",
|
||||||
|
@ -776,6 +776,28 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"dev_qwen": {
|
||||||
|
"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