mirror of
https://github.com/searxng/searxng
synced 2024-01-01 19:24:07 +01:00
c
This commit is contained in:
parent
2123f49bcf
commit
25fcb6bc0f
2 changed files with 214 additions and 206 deletions
210
searx/webapp.py
210
searx/webapp.py
|
@ -1291,7 +1291,7 @@ let sentences=[]
|
||||||
function modal_open(url, num)
|
function modal_open(url, num)
|
||||||
{
|
{
|
||||||
if(lock_chat==1) return;
|
if(lock_chat==1) return;
|
||||||
let article;
|
|
||||||
prev_chat = document.getElementById('chat_talk').innerHTML;
|
prev_chat = document.getElementById('chat_talk').innerHTML;
|
||||||
if(num == 'pdf') { document.getElementById('chat_talk').innerHTML = prev_chat+'<div class="chat_question">'+'打开链接'+'<a class="footnote">'+ 'PDF' +'</a>'+"</div>";}
|
if(num == 'pdf') { document.getElementById('chat_talk').innerHTML = prev_chat+'<div class="chat_question">'+'打开链接'+'<a class="footnote">'+ 'PDF' +'</a>'+"</div>";}
|
||||||
else{ document.getElementById('chat_talk').innerHTML = prev_chat+'<div class="chat_question">'+'打开链接'+'<a class="footnote">'+ String(num) +'</a>'+"</div>";}
|
else{ document.getElementById('chat_talk').innerHTML = prev_chat+'<div class="chat_question">'+'打开链接'+'<a class="footnote">'+ String(num) +'</a>'+"</div>";}
|
||||||
|
@ -1507,113 +1507,117 @@ function modal_open(url, num)
|
||||||
resolve("success");
|
resolve("success");
|
||||||
}
|
}
|
||||||
|
|
||||||
})
|
}).then(
|
||||||
}).then(
|
() => {
|
||||||
() => {
|
fulltext = article.textContent;
|
||||||
fulltext = article.textContent;
|
fulltext = fulltext.replaceAll("\n\n","\n").replaceAll("\n\n","\n");
|
||||||
fulltext = fulltext.replaceAll("\n\n","\n").replaceAll("\n\n","\n");
|
const delimiter = /[?!;\?\n。;!………]/g
|
||||||
const delimiter = /[?!;\?\n。;!………]/g
|
fulltext = fulltext.split(delimiter);
|
||||||
fulltext = fulltext.split(delimiter);
|
fulltext = fulltext.filter((item) => {
|
||||||
fulltext = fulltext.filter((item) => {
|
// 使用正则表达式匹配仅由数字、逗号和空格组成的字符串
|
||||||
// 使用正则表达式匹配仅由数字、逗号和空格组成的字符串
|
const regex = /^[0-9,\s]+$/;
|
||||||
const regex = /^[0-9,\s]+$/;
|
return !regex.test(item);
|
||||||
return !regex.test(item);
|
});
|
||||||
});
|
fulltext = fulltext.filter(function(item) {
|
||||||
fulltext = fulltext.filter(function(item) {
|
return item && item.trim(); // 去掉空值和空格
|
||||||
return item && item.trim(); // 去掉空值和空格
|
});
|
||||||
});
|
optkeytext = {
|
||||||
optkeytext = {
|
method: "POST",
|
||||||
method: "POST",
|
headers: headers,
|
||||||
headers: headers,
|
body: JSON.stringify({'text':fulltext.join("\n")})
|
||||||
body: JSON.stringify({'text':fulltext.join("\n")})
|
};
|
||||||
};
|
fetchRetry('https://search.kg/keytext',3,optkeytext)
|
||||||
fetchRetry('https://search.kg/keytext',3,optkeytext)
|
.then(response => response.json())
|
||||||
.then(response => response.json())
|
.then(data =>
|
||||||
.then(data =>
|
|
||||||
{
|
|
||||||
keytextres = unique(data);
|
|
||||||
|
|
||||||
promptWebpage = '网页标题:'+ article.title +'\n'+'网页布局:\n'
|
|
||||||
for (el in modalele)
|
|
||||||
{
|
{
|
||||||
if((promptWebpage + modalele[el] + '\n').length <400)
|
keytextres = unique(data);
|
||||||
promptWebpage = promptWebpage + modalele[el] + '\n';
|
|
||||||
}
|
promptWebpage = '网页标题:'+ article.title +'\n'+'网页布局:\n'
|
||||||
promptWebpage = promptWebpage +'网页内容:\n'
|
for (el in modalele)
|
||||||
keySentencesCount = 0;
|
{
|
||||||
for (st in keytextres)
|
if((promptWebpage + modalele[el] + '\n').length <400)
|
||||||
{
|
promptWebpage = promptWebpage + modalele[el] + '\n';
|
||||||
if((promptWebpage + keytextres[st] + '\n').length <1200)
|
}
|
||||||
promptWebpage = promptWebpage + keytextres[st] + '\n';
|
promptWebpage = promptWebpage +'网页内容:\n'
|
||||||
keySentencesCount = keySentencesCount+1;
|
keySentencesCount = 0;
|
||||||
}
|
for (st in keytextres)
|
||||||
promptWeb = [{'role':'assistant','content':promptWebpage},{'role':'user','content':'总结网页内容,发表带emoji的评论'}]
|
{
|
||||||
const options = {
|
if((promptWebpage + keytextres[st] + '\n').length <1200)
|
||||||
method: "POST",
|
promptWebpage = promptWebpage + keytextres[st] + '\n';
|
||||||
headers: headers,
|
keySentencesCount = keySentencesCount+1;
|
||||||
body: b64EncodeUnicode( JSON.stringify({
|
}
|
||||||
"messages": promptWeb.concat(add_system),
|
promptWeb = [{'role':'assistant','content':promptWebpage},{'role':'user','content':'总结网页内容,发表带emoji的评论'}]
|
||||||
"max_tokens": 1000,
|
const options = {
|
||||||
"temperature": 0.9,
|
method: "POST",
|
||||||
"top_p": 1,
|
headers: headers,
|
||||||
"frequency_penalty": 0,
|
body: b64EncodeUnicode( JSON.stringify({
|
||||||
"presence_penalty": 0,
|
"messages": promptWeb.concat(add_system),
|
||||||
"stream": true
|
"max_tokens": 1000,
|
||||||
}) )
|
"temperature": 0.9,
|
||||||
};
|
"top_p": 1,
|
||||||
|
"frequency_penalty": 0,
|
||||||
chatTemp = ""
|
"presence_penalty": 0,
|
||||||
text_offset = -1;
|
"stream": true
|
||||||
prev_chat = document.getElementById('chat_talk').innerHTML;
|
}) )
|
||||||
|
};
|
||||||
fetch("https://search.kg/completions", options)
|
|
||||||
.then((response) => {
|
chatTemp = ""
|
||||||
const reader = response.body.getReader();
|
text_offset = -1;
|
||||||
let result = '';
|
prev_chat = document.getElementById('chat_talk').innerHTML;
|
||||||
let half = '';
|
|
||||||
reader.read().then(function processText({ done, value }) {
|
fetch("https://search.kg/completions", options)
|
||||||
if (done) return;
|
.then((response) => {
|
||||||
const text = new TextDecoder('utf-8').decode(value);
|
const reader = response.body.getReader();
|
||||||
text.trim().split('\n').forEach(function(v) {
|
let result = '';
|
||||||
try{document.querySelector("#chat_talk").scrollTop = document.querySelector("#chat_talk").scrollHeight}catch(e){}
|
let half = '';
|
||||||
result = ''
|
reader.read().then(function processText({ done, value }) {
|
||||||
if(v.length>6) result = v.slice(6);
|
if (done) return;
|
||||||
if(result == "[DONE]")
|
const text = new TextDecoder('utf-8').decode(value);
|
||||||
{
|
text.trim().split('\n').forEach(function(v) {
|
||||||
lock_chat=0
|
try{document.querySelector("#chat_talk").scrollTop = document.querySelector("#chat_talk").scrollHeight}catch(e){}
|
||||||
return;
|
result = ''
|
||||||
}
|
if(v.length>6) result = v.slice(6);
|
||||||
let choices;
|
if(result == "[DONE]")
|
||||||
try
|
{
|
||||||
{
|
lock_chat=0
|
||||||
try{choices=JSON.parse(half+result)['choices'];half = '';}
|
return;
|
||||||
catch(e){choices=JSON.parse(result)['choices'];half = '';}
|
}
|
||||||
}catch(e){half+=result}
|
let choices;
|
||||||
if(choices && choices.length>0 && choices[0].delta.content)
|
try
|
||||||
{
|
{
|
||||||
chatTemp+=choices[0].delta.content
|
try{choices=JSON.parse(half+result)['choices'];half = '';}
|
||||||
}
|
catch(e){choices=JSON.parse(result)['choices'];half = '';}
|
||||||
chatTemp=chatTemp.replaceAll("\n\n","\n").replaceAll("\n\n","\n")
|
}catch(e){half+=result}
|
||||||
document.querySelector("#prompt").innerHTML="";
|
if(choices && choices.length>0 && choices[0].delta.content)
|
||||||
markdownToHtml(beautify(chatTemp), document.querySelector("#prompt"))
|
{
|
||||||
document.getElementById('chat_talk').innerHTML = prev_chat+'<div class="chat_answer">'+document.querySelector("#prompt").innerHTML+"</div>";
|
chatTemp+=choices[0].delta.content
|
||||||
|
}
|
||||||
|
chatTemp=chatTemp.replaceAll("\n\n","\n").replaceAll("\n\n","\n")
|
||||||
|
document.querySelector("#prompt").innerHTML="";
|
||||||
|
markdownToHtml(beautify(chatTemp), document.querySelector("#prompt"))
|
||||||
|
document.getElementById('chat_talk').innerHTML = prev_chat+'<div class="chat_answer">'+document.querySelector("#prompt").innerHTML+"</div>";
|
||||||
|
|
||||||
|
})
|
||||||
|
return reader.read().then(processText);
|
||||||
|
});
|
||||||
})
|
})
|
||||||
return reader.read().then(processText);
|
.catch((error) => {
|
||||||
|
console.error('Error:', error);
|
||||||
});
|
});
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
console.error('Error:', error);
|
|
||||||
});
|
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
},
|
||||||
|
error => {
|
||||||
|
console.log(error);
|
||||||
|
}
|
||||||
|
);
|
||||||
},
|
},
|
||||||
error => {
|
error => {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
|
|
210
searx/webapp1.py
210
searx/webapp1.py
|
@ -1291,7 +1291,7 @@ let sentences=[]
|
||||||
function modal_open(url, num)
|
function modal_open(url, num)
|
||||||
{
|
{
|
||||||
if(lock_chat==1) return;
|
if(lock_chat==1) return;
|
||||||
let article;
|
|
||||||
prev_chat = document.getElementById('chat_talk').innerHTML;
|
prev_chat = document.getElementById('chat_talk').innerHTML;
|
||||||
if(num == 'pdf') { document.getElementById('chat_talk').innerHTML = prev_chat+'<div class="chat_question">'+'打开链接'+'<a class="footnote">'+ 'PDF' +'</a>'+"</div>";}
|
if(num == 'pdf') { document.getElementById('chat_talk').innerHTML = prev_chat+'<div class="chat_question">'+'打开链接'+'<a class="footnote">'+ 'PDF' +'</a>'+"</div>";}
|
||||||
else{ document.getElementById('chat_talk').innerHTML = prev_chat+'<div class="chat_question">'+'打开链接'+'<a class="footnote">'+ String(num) +'</a>'+"</div>";}
|
else{ document.getElementById('chat_talk').innerHTML = prev_chat+'<div class="chat_question">'+'打开链接'+'<a class="footnote">'+ String(num) +'</a>'+"</div>";}
|
||||||
|
@ -1507,113 +1507,117 @@ function modal_open(url, num)
|
||||||
resolve("success");
|
resolve("success");
|
||||||
}
|
}
|
||||||
|
|
||||||
})
|
}).then(
|
||||||
}).then(
|
() => {
|
||||||
() => {
|
fulltext = article.textContent;
|
||||||
fulltext = article.textContent;
|
fulltext = fulltext.replaceAll("\n\n","\n").replaceAll("\n\n","\n");
|
||||||
fulltext = fulltext.replaceAll("\n\n","\n").replaceAll("\n\n","\n");
|
const delimiter = /[?!;\?\n。;!………]/g
|
||||||
const delimiter = /[?!;\?\n。;!………]/g
|
fulltext = fulltext.split(delimiter);
|
||||||
fulltext = fulltext.split(delimiter);
|
fulltext = fulltext.filter((item) => {
|
||||||
fulltext = fulltext.filter((item) => {
|
// 使用正则表达式匹配仅由数字、逗号和空格组成的字符串
|
||||||
// 使用正则表达式匹配仅由数字、逗号和空格组成的字符串
|
const regex = /^[0-9,\s]+$/;
|
||||||
const regex = /^[0-9,\s]+$/;
|
return !regex.test(item);
|
||||||
return !regex.test(item);
|
});
|
||||||
});
|
fulltext = fulltext.filter(function(item) {
|
||||||
fulltext = fulltext.filter(function(item) {
|
return item && item.trim(); // 去掉空值和空格
|
||||||
return item && item.trim(); // 去掉空值和空格
|
});
|
||||||
});
|
optkeytext = {
|
||||||
optkeytext = {
|
method: "POST",
|
||||||
method: "POST",
|
headers: headers,
|
||||||
headers: headers,
|
body: JSON.stringify({'text':fulltext.join("\n")})
|
||||||
body: JSON.stringify({'text':fulltext.join("\n")})
|
};
|
||||||
};
|
fetchRetry('https://search.kg/keytext',3,optkeytext)
|
||||||
fetchRetry('https://search.kg/keytext',3,optkeytext)
|
.then(response => response.json())
|
||||||
.then(response => response.json())
|
.then(data =>
|
||||||
.then(data =>
|
|
||||||
{
|
|
||||||
keytextres = unique(data);
|
|
||||||
|
|
||||||
promptWebpage = '网页标题:'+ article.title +'\n'+'网页布局:\n'
|
|
||||||
for (el in modalele)
|
|
||||||
{
|
{
|
||||||
if((promptWebpage + modalele[el] + '\n').length <400)
|
keytextres = unique(data);
|
||||||
promptWebpage = promptWebpage + modalele[el] + '\n';
|
|
||||||
}
|
promptWebpage = '网页标题:'+ article.title +'\n'+'网页布局:\n'
|
||||||
promptWebpage = promptWebpage +'网页内容:\n'
|
for (el in modalele)
|
||||||
keySentencesCount = 0;
|
{
|
||||||
for (st in keytextres)
|
if((promptWebpage + modalele[el] + '\n').length <400)
|
||||||
{
|
promptWebpage = promptWebpage + modalele[el] + '\n';
|
||||||
if((promptWebpage + keytextres[st] + '\n').length <1200)
|
}
|
||||||
promptWebpage = promptWebpage + keytextres[st] + '\n';
|
promptWebpage = promptWebpage +'网页内容:\n'
|
||||||
keySentencesCount = keySentencesCount+1;
|
keySentencesCount = 0;
|
||||||
}
|
for (st in keytextres)
|
||||||
promptWeb = [{'role':'assistant','content':promptWebpage},{'role':'user','content':'总结网页内容,发表带emoji的评论'}]
|
{
|
||||||
const options = {
|
if((promptWebpage + keytextres[st] + '\n').length <1200)
|
||||||
method: "POST",
|
promptWebpage = promptWebpage + keytextres[st] + '\n';
|
||||||
headers: headers,
|
keySentencesCount = keySentencesCount+1;
|
||||||
body: b64EncodeUnicode( JSON.stringify({
|
}
|
||||||
"messages": promptWeb.concat(add_system),
|
promptWeb = [{'role':'assistant','content':promptWebpage},{'role':'user','content':'总结网页内容,发表带emoji的评论'}]
|
||||||
"max_tokens": 1000,
|
const options = {
|
||||||
"temperature": 0.9,
|
method: "POST",
|
||||||
"top_p": 1,
|
headers: headers,
|
||||||
"frequency_penalty": 0,
|
body: b64EncodeUnicode( JSON.stringify({
|
||||||
"presence_penalty": 0,
|
"messages": promptWeb.concat(add_system),
|
||||||
"stream": true
|
"max_tokens": 1000,
|
||||||
}) )
|
"temperature": 0.9,
|
||||||
};
|
"top_p": 1,
|
||||||
|
"frequency_penalty": 0,
|
||||||
chatTemp = ""
|
"presence_penalty": 0,
|
||||||
text_offset = -1;
|
"stream": true
|
||||||
prev_chat = document.getElementById('chat_talk').innerHTML;
|
}) )
|
||||||
|
};
|
||||||
fetch("https://search.kg/completions", options)
|
|
||||||
.then((response) => {
|
chatTemp = ""
|
||||||
const reader = response.body.getReader();
|
text_offset = -1;
|
||||||
let result = '';
|
prev_chat = document.getElementById('chat_talk').innerHTML;
|
||||||
let half = '';
|
|
||||||
reader.read().then(function processText({ done, value }) {
|
fetch("https://search.kg/completions", options)
|
||||||
if (done) return;
|
.then((response) => {
|
||||||
const text = new TextDecoder('utf-8').decode(value);
|
const reader = response.body.getReader();
|
||||||
text.trim().split('\n').forEach(function(v) {
|
let result = '';
|
||||||
try{document.querySelector("#chat_talk").scrollTop = document.querySelector("#chat_talk").scrollHeight}catch(e){}
|
let half = '';
|
||||||
result = ''
|
reader.read().then(function processText({ done, value }) {
|
||||||
if(v.length>6) result = v.slice(6);
|
if (done) return;
|
||||||
if(result == "[DONE]")
|
const text = new TextDecoder('utf-8').decode(value);
|
||||||
{
|
text.trim().split('\n').forEach(function(v) {
|
||||||
lock_chat=0
|
try{document.querySelector("#chat_talk").scrollTop = document.querySelector("#chat_talk").scrollHeight}catch(e){}
|
||||||
return;
|
result = ''
|
||||||
}
|
if(v.length>6) result = v.slice(6);
|
||||||
let choices;
|
if(result == "[DONE]")
|
||||||
try
|
{
|
||||||
{
|
lock_chat=0
|
||||||
try{choices=JSON.parse(half+result)['choices'];half = '';}
|
return;
|
||||||
catch(e){choices=JSON.parse(result)['choices'];half = '';}
|
}
|
||||||
}catch(e){half+=result}
|
let choices;
|
||||||
if(choices && choices.length>0 && choices[0].delta.content)
|
try
|
||||||
{
|
{
|
||||||
chatTemp+=choices[0].delta.content
|
try{choices=JSON.parse(half+result)['choices'];half = '';}
|
||||||
}
|
catch(e){choices=JSON.parse(result)['choices'];half = '';}
|
||||||
chatTemp=chatTemp.replaceAll("\n\n","\n").replaceAll("\n\n","\n")
|
}catch(e){half+=result}
|
||||||
document.querySelector("#prompt").innerHTML="";
|
if(choices && choices.length>0 && choices[0].delta.content)
|
||||||
markdownToHtml(beautify(chatTemp), document.querySelector("#prompt"))
|
{
|
||||||
document.getElementById('chat_talk').innerHTML = prev_chat+'<div class="chat_answer">'+document.querySelector("#prompt").innerHTML+"</div>";
|
chatTemp+=choices[0].delta.content
|
||||||
|
}
|
||||||
|
chatTemp=chatTemp.replaceAll("\n\n","\n").replaceAll("\n\n","\n")
|
||||||
|
document.querySelector("#prompt").innerHTML="";
|
||||||
|
markdownToHtml(beautify(chatTemp), document.querySelector("#prompt"))
|
||||||
|
document.getElementById('chat_talk').innerHTML = prev_chat+'<div class="chat_answer">'+document.querySelector("#prompt").innerHTML+"</div>";
|
||||||
|
|
||||||
|
})
|
||||||
|
return reader.read().then(processText);
|
||||||
|
});
|
||||||
})
|
})
|
||||||
return reader.read().then(processText);
|
.catch((error) => {
|
||||||
|
console.error('Error:', error);
|
||||||
});
|
});
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
console.error('Error:', error);
|
|
||||||
});
|
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
},
|
||||||
|
error => {
|
||||||
|
console.log(error);
|
||||||
|
}
|
||||||
|
);
|
||||||
},
|
},
|
||||||
error => {
|
error => {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
|
|
Loading…
Add table
Reference in a new issue