mirror of
https://github.com/HIllya51/LunaTranslator.git
synced 2024-12-29 16:44:13 +08:00
div
This commit is contained in:
parent
33e715a1d0
commit
6baf3bad5e
@ -7,24 +7,11 @@ window.fetch = function (input, init) {
|
|||||||
if (!input.includes("conversation")) return fetchPromise;
|
if (!input.includes("conversation")) return fetchPromise;
|
||||||
hasdone = false;
|
hasdone = false;
|
||||||
thistext = ''
|
thistext = ''
|
||||||
// 构造一个自定义的可读流
|
|
||||||
//controller.close()会导致真正的fetch被终止
|
|
||||||
// 不太会js,只能让他假等待了,ui里面会显示在等待,但luna里面能读到,而且按钮也能正确按下
|
|
||||||
const customReadableStream = new ReadableStream({
|
|
||||||
start(controller) {
|
|
||||||
setTimeout(() => {
|
|
||||||
|
|
||||||
controller.close();
|
|
||||||
}, 99999999999);
|
|
||||||
|
|
||||||
},
|
|
||||||
});
|
|
||||||
fetchPromise.then(response => {
|
fetchPromise.then(response => {
|
||||||
const contentType = response.headers.get('content-type');
|
const clone = response.clone()
|
||||||
|
const contentType = clone.headers.get('content-type');
|
||||||
if (contentType && contentType.includes('text/event-stream')) {
|
if (contentType && contentType.includes('text/event-stream')) {
|
||||||
console.log(response.body)
|
const reader = clone.body.getReader();
|
||||||
const reader = response.body.getReader();
|
|
||||||
|
|
||||||
reader.read().then(function processStream({ done, value }) {
|
reader.read().then(function processStream({ done, value }) {
|
||||||
|
|
||||||
@ -55,13 +42,5 @@ window.fetch = function (input, init) {
|
|||||||
console.error('Fetch error:', error);
|
console.error('Fetch error:', error);
|
||||||
});
|
});
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return fetchPromise;
|
||||||
resolve(new Response(customReadableStream, {
|
|
||||||
status: 200,
|
|
||||||
headers: {
|
|
||||||
'Content-type': 'text/event-stream'
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
|
|
||||||
});
|
|
||||||
};
|
};
|
@ -28,7 +28,7 @@ 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__), "hookchatgptfetch.js"),
|
os.path.join(os.path.dirname(__file__), "dev_chatgpt.js"),
|
||||||
"r",
|
"r",
|
||||||
encoding="utf8",
|
encoding="utf8",
|
||||||
) as ff:
|
) as ff:
|
||||||
@ -41,12 +41,13 @@ class TS(basetransdev):
|
|||||||
|
|
||||||
self.Runtime_evaluate("hasdone=false")
|
self.Runtime_evaluate("hasdone=false")
|
||||||
self.Runtime_evaluate('thistext=""')
|
self.Runtime_evaluate('thistext=""')
|
||||||
content = (
|
if self.config["use_custom_prompt"]:
|
||||||
"You are a translator. Please help me translate the following {} text into {}, and you should only tell me the translation.\n".format(
|
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
|
self.srclang, self.tgtlang
|
||||||
)
|
)
|
||||||
+ 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=document.querySelector("textarea");textarea.value=`{}`;event = new Event("input", {{bubbles: true, cancelable: true }});textarea.dispatchEvent(event);'.format(
|
||||||
content
|
content
|
||||||
|
@ -734,12 +734,23 @@
|
|||||||
},
|
},
|
||||||
"dev_chatgpt": {
|
"dev_chatgpt": {
|
||||||
"args": {
|
"args": {
|
||||||
"usingstream": true
|
"usingstream": true,
|
||||||
|
"use_custom_prompt": false,
|
||||||
|
"custom_prompt": ""
|
||||||
},
|
},
|
||||||
"argstype": {
|
"argstype": {
|
||||||
"usingstream": {
|
"usingstream": {
|
||||||
"name": "流式输出",
|
"name": "流式输出",
|
||||||
"type": "switch"
|
"type": "switch"
|
||||||
|
},
|
||||||
|
"custom_prompt": {
|
||||||
|
"name": "自定义promt",
|
||||||
|
"type": "multiline",
|
||||||
|
"refswitch": "use_custom_prompt"
|
||||||
|
},
|
||||||
|
"use_custom_prompt": {
|
||||||
|
"type": "switch_ref",
|
||||||
|
"name": "使用自定义promt"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user