mirror of
https://github.com/torappinfo/uweb.git
synced 2024-08-14 23:54:59 +00:00
simplify bingAI
This commit is contained in:
parent
fcc8fe4f5e
commit
e3f545c03f
4 changed files with 26 additions and 210 deletions
|
@ -82,7 +82,6 @@
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
<script type="text/javascript" src="./js/GetSet.js"></script>
|
<script type="text/javascript" src="./js/GetSet.js"></script>
|
||||||
<script type="text/javascript" src="./js/ChatMessages.js"></script>
|
|
||||||
<script type="text/javascript" src="./js/bingChatHub.js"></script>
|
<script type="text/javascript" src="./js/bingChatHub.js"></script>
|
||||||
<script type="text/javascript" src="./js/parserReturn.js"></script>
|
<script type="text/javascript" src="./js/parserReturn.js"></script>
|
||||||
<script type="text/javascript" src="./js/bing.js"></script>
|
<script type="text/javascript" src="./js/bing.js"></script>
|
||||||
|
|
|
@ -1,65 +0,0 @@
|
||||||
let bingProposes = [
|
|
||||||
'教我一个新单词',
|
|
||||||
'我需要有关家庭作业的帮助',
|
|
||||||
'我想学习一项新技能',
|
|
||||||
'最深的海洋是哪个?',
|
|
||||||
'一年有多少小时?',
|
|
||||||
"宇宙是如何开始的?",
|
|
||||||
"寻找非虚构作品",
|
|
||||||
'火烈鸟为何为粉色?',
|
|
||||||
'有什么新闻?',
|
|
||||||
'让我大笑',
|
|
||||||
'给我看鼓舞人心的名言',
|
|
||||||
'世界上最小的哺乳动物是什么?',
|
|
||||||
'向我显示食谱',
|
|
||||||
'最深的海洋是哪个?',
|
|
||||||
'为什么人类需要睡眠?',
|
|
||||||
'教我有关登月的信息',
|
|
||||||
'我想学习一项新技能',
|
|
||||||
'如何创建预算?',
|
|
||||||
'给我说个笑话',
|
|
||||||
'全息影像的工作原理是什么?',
|
|
||||||
'如何设定可实现的目标?',
|
|
||||||
'金字塔是如何建成的?',
|
|
||||||
'激励我!',
|
|
||||||
'宇宙是如何开始的?',
|
|
||||||
'如何制作蛋糕?'
|
|
||||||
];
|
|
||||||
|
|
||||||
let bingmMessages = [
|
|
||||||
'好的,我已清理好板子,可以重新开始了。我可以帮助你探索什么?',
|
|
||||||
'明白了,我已经抹去了过去,专注于现在。我们现在应该探索什么?',
|
|
||||||
'重新开始总是很棒。问我任何问题!',
|
|
||||||
'好了,我已经为新的对话重置了我的大脑。你现在想聊些什么?',
|
|
||||||
'很好,让我们来更改主题。你在想什么?',
|
|
||||||
'谢谢你帮我理清头绪! 我现在能帮你做什么?',
|
|
||||||
'没问题,很高兴你喜欢上一次对话。让我们转到一个新主题。你想要了解有关哪些内容的详细信息?',
|
|
||||||
'谢谢你! 知道你什么时候准备好继续前进总是很有帮助的。我现在能为你回答什么问题?',
|
|
||||||
'当然,我已准备好进行新的挑战。我现在可以为你做什么?'
|
|
||||||
]
|
|
||||||
|
|
||||||
let StartMessage = bingmMessages[0];
|
|
||||||
let Proposes = [bingProposes[0],bingProposes[1],bingProposes[2]];
|
|
||||||
/**
|
|
||||||
获取建议消息
|
|
||||||
*/
|
|
||||||
function nextStartProposes(){
|
|
||||||
Proposes[0] = bingProposes[Math.floor(Math.random() * bingProposes.length)];
|
|
||||||
Proposes[1] = bingProposes[Math.floor(Math.random() * bingProposes.length)];
|
|
||||||
Proposes[2] = bingProposes[Math.floor(Math.random() * bingProposes.length)];
|
|
||||||
return Proposes;
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
获取bing的第一条消息
|
|
||||||
*/
|
|
||||||
function nextStartMessage(){
|
|
||||||
return StartMessage = bingmMessages[Math.floor(Math.random() * bingmMessages.length)];
|
|
||||||
}
|
|
||||||
|
|
||||||
function getStartMessage(){
|
|
||||||
return StartMessage;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getStartProposes(){
|
|
||||||
return Proposes;
|
|
||||||
}
|
|
|
@ -1,6 +1,4 @@
|
||||||
var chat = document.getElementById('chat');
|
var chat = document.getElementById('chat');
|
||||||
var searchSuggestions = document.getElementById('SearchSuggestions');
|
|
||||||
searchSuggestions.style.opacity = 1;
|
|
||||||
var chatTypeDiv = document.getElementById('chatTypeDiv');
|
var chatTypeDiv = document.getElementById('chatTypeDiv');
|
||||||
var docTitle = document.getElementById('docTitle');
|
var docTitle = document.getElementById('docTitle');
|
||||||
var restart_button = document.getElementById('restart');
|
var restart_button = document.getElementById('restart');
|
||||||
|
@ -32,28 +30,6 @@ function addError(message) {
|
||||||
chat.appendChild(go);
|
chat.appendChild(go);
|
||||||
}
|
}
|
||||||
|
|
||||||
//尝试获取聊天权限按钮
|
|
||||||
function addNoPower() {
|
|
||||||
let go = document.createElement('div');
|
|
||||||
go.classList.add('NoPower');
|
|
||||||
go.innerHTML = '点击尝试申请加入候补名单获取NewBing聊天权限';
|
|
||||||
chat.appendChild(go);
|
|
||||||
go.onclick = () => {
|
|
||||||
if (go.geting) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
go.geting = true;
|
|
||||||
go.innerHTML = '正在请求申请加入候补名单..';
|
|
||||||
getPower().then((rett) => {
|
|
||||||
if (rett.ok == true) {
|
|
||||||
go.innerHTML = '请求成功!请刷新页面重试,如果无权限使用请等待几天后重试。'
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
go.innerHTML = '发生错误:' + rett.message;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let onMessageIsOKClose = false;
|
let onMessageIsOKClose = false;
|
||||||
//(json)
|
//(json)
|
||||||
function onMessage(json, returnMessage) {
|
function onMessage(json, returnMessage) {
|
||||||
|
@ -116,7 +92,6 @@ function reSetStartChatMessage(type) {
|
||||||
<div class="bing">
|
<div class="bing">
|
||||||
<div class="adaptiveCardsFatherDIV">
|
<div class="adaptiveCardsFatherDIV">
|
||||||
<div class="textBlock markdown-body">
|
<div class="textBlock markdown-body">
|
||||||
${nextStartMessage(type)}
|
|
||||||
</div>
|
</div>
|
||||||
<div class="throttling">
|
<div class="throttling">
|
||||||
${t} / 0
|
${t} / 0
|
||||||
|
@ -130,18 +105,6 @@ function reSetStartChatMessage(type) {
|
||||||
restartNewChat.classList.add('onShow');
|
restartNewChat.classList.add('onShow');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
searchSuggestions.innerHTML = '';
|
|
||||||
let prs = nextStartProposes();
|
|
||||||
prs.forEach((s) => {
|
|
||||||
let a = document.createElement('a');
|
|
||||||
a.innerHTML = s;
|
|
||||||
a.onclick = (even) => {
|
|
||||||
if (searchSuggestions.style.opacity >= 1) {
|
|
||||||
send(even.target.innerHTML);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
searchSuggestions.appendChild(a);
|
|
||||||
});
|
|
||||||
docTitle.innerText = 'NewBingGoGo:聊天啦啦啦啦';
|
docTitle.innerText = 'NewBingGoGo:聊天啦啦啦啦';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -149,7 +112,6 @@ function reSetStartChatMessage(type) {
|
||||||
function isAskingToMagic() {
|
function isAskingToMagic() {
|
||||||
isSpeaking = true;
|
isSpeaking = true;
|
||||||
send_button.value = '施法中.';
|
send_button.value = '施法中.';
|
||||||
searchSuggestions.innerHTML = '';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**bing正在回复 */
|
/**bing正在回复 */
|
||||||
|
@ -160,7 +122,6 @@ function isSpeakingStart(chatWithMagic, sendText) {
|
||||||
docTitle.innerText = sendText;
|
docTitle.innerText = sendText;
|
||||||
}
|
}
|
||||||
send_button.value = '响应中.';
|
send_button.value = '响应中.';
|
||||||
searchSuggestions.innerHTML = '';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**bing回复结束 */
|
/**bing回复结束 */
|
||||||
|
@ -180,9 +141,6 @@ function send(text) {
|
||||||
createChat(thisChatType).then((r) => {
|
createChat(thisChatType).then((r) => {
|
||||||
if (!r.ok) {
|
if (!r.ok) {
|
||||||
addError(r.message);
|
addError(r.message);
|
||||||
if (r.type == 'NoPower') {
|
|
||||||
addNoPower();
|
|
||||||
}
|
|
||||||
isSpeakingFinish();
|
isSpeakingFinish();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -247,11 +205,6 @@ function handleScroll() {
|
||||||
var docHeight = document.body.scrollHeight;
|
var docHeight = document.body.scrollHeight;
|
||||||
var scrollPos = window.pageYOffset;
|
var scrollPos = window.pageYOffset;
|
||||||
// 如果滚动到底部,显示元素,否则隐藏元素
|
// 如果滚动到底部,显示元素,否则隐藏元素
|
||||||
if (scrollPos + window.innerHeight >= docHeight - 50) {
|
|
||||||
searchSuggestions.style.opacity = 1;
|
|
||||||
} else {
|
|
||||||
searchSuggestions.style.opacity = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// 添加滚动事件监听器
|
// 添加滚动事件监听器
|
||||||
window.addEventListener("scroll", handleScroll);
|
window.addEventListener("scroll", handleScroll);
|
||||||
|
|
|
@ -348,51 +348,12 @@ class Chat {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/***
|
|
||||||
* 补齐url
|
|
||||||
*/
|
|
||||||
function URLTrue(magicUrl, thiePath) {
|
function URLTrue(magicUrl, thiePath) {
|
||||||
let url = magicUrl;
|
return url + thiePath;
|
||||||
if (!url.endsWith('/')) {
|
|
||||||
url = url + '/';
|
|
||||||
}
|
|
||||||
url = url + thiePath;
|
|
||||||
return url;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//获取newbing权限
|
//获取newbing权限
|
||||||
async function getPower() {
|
async function getPower() {}
|
||||||
//设置cookies到魔法链接
|
|
||||||
let magicUrl = await getMagicUrl();
|
|
||||||
if (!magicUrl) {
|
|
||||||
return {
|
|
||||||
ok: false,
|
|
||||||
message: "需要设置魔法链接才能获取权限哦!"
|
|
||||||
};
|
|
||||||
}
|
|
||||||
if (!expUrl.test(magicUrl)) {
|
|
||||||
return {
|
|
||||||
ok: false,
|
|
||||||
message: "魔法链接不正确!请修改魔法链接。"
|
|
||||||
};
|
|
||||||
}
|
|
||||||
await copyCookies(magicUrl);
|
|
||||||
|
|
||||||
try {
|
|
||||||
await fetch(URLTrue(magicUrl, 'bingcopilotwaitlist'));
|
|
||||||
return {
|
|
||||||
ok: true,
|
|
||||||
message: "ok"
|
|
||||||
};
|
|
||||||
} catch (e) {
|
|
||||||
console.warn(e);
|
|
||||||
return {
|
|
||||||
ok: false,
|
|
||||||
message: "发生错误,可能是魔法链接无法链接:" + e.message
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
async function copyCookies(magicUrl) {}
|
async function copyCookies(magicUrl) {}
|
||||||
|
|
||||||
|
@ -406,21 +367,8 @@ async function copyCookies(magicUrl) {}
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
async function createChat(theChatType) {
|
async function createChat(theChatType) {
|
||||||
//设置cookies到魔法链接
|
|
||||||
let chatWithMagic = await getChatHubWithMagic();
|
let chatWithMagic = await getChatHubWithMagic();
|
||||||
let magicUrl = await getMagicUrl();
|
let magicUrl = await getMagicUrl();
|
||||||
if (!magicUrl) {
|
|
||||||
return {
|
|
||||||
ok: false,
|
|
||||||
message: "需要设置魔法链接才能聊天哦!"
|
|
||||||
};
|
|
||||||
}
|
|
||||||
if (!expUrl.test(magicUrl)) {
|
|
||||||
return {
|
|
||||||
ok: false,
|
|
||||||
message: "魔法链接不正确!请修改魔法链接。"
|
|
||||||
};
|
|
||||||
}
|
|
||||||
let restartNewChat = document.getElementById('restartNewChat');
|
let restartNewChat = document.getElementById('restartNewChat');
|
||||||
if(chatWithMagic=='repeat'){//如果是聊天复用
|
if(chatWithMagic=='repeat'){//如果是聊天复用
|
||||||
restartNewChat.classList.remove('onShow');
|
restartNewChat.classList.remove('onShow');
|
||||||
|
@ -437,47 +385,28 @@ async function createChat(theChatType) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
try {
|
let mes;
|
||||||
await copyCookies(magicUrl);
|
do {
|
||||||
let res = await fetch(URLTrue(magicUrl, 'turing/conversation/create'),{credentials: 'include'});
|
try {
|
||||||
let resjson = await res.json();
|
let res = await fetch(URLTrue(magicUrl,'turing/conversation/create'),
|
||||||
if (!resjson.result) {
|
{credentials: 'include'});
|
||||||
console.warn(resjson);
|
let resjson = await res.json();
|
||||||
return {
|
if (!resjson.result || resjson.result.value != 'Success') {
|
||||||
ok: false,
|
mes = resjson;
|
||||||
message: "未知错误!"
|
break;
|
||||||
};
|
}
|
||||||
}
|
//保存成功的聊天
|
||||||
if (resjson.result.value != 'Success') {
|
setLastChatJson(resjson);
|
||||||
let type = resjson.result.value;
|
return {
|
||||||
let mess = resjson.result.message;
|
ok: true,
|
||||||
if (resjson.result.value == 'UnauthorizedRequest') {
|
message: 'ok',
|
||||||
type = 'NoLogin'
|
obj: new Chat(magicUrl, chatWithMagic, resjson.conversationId, resjson.clientId, resjson.conversationSignature, theChatType)
|
||||||
mess = '首先你需要在bing登录微软账号!请前往 https://cn.bing.com/ 登录微软账号。';
|
};
|
||||||
} else if (resjson.result.value == 'Forbidden') {
|
} catch (e) {mes = e.message;}
|
||||||
type = 'NoPower'
|
}while(false);
|
||||||
mess = '你还没有获得NewBing的使用权限';
|
|
||||||
}
|
|
||||||
console.warn(resjson);
|
|
||||||
return {
|
|
||||||
ok: false,
|
|
||||||
type: type,
|
|
||||||
message: mess
|
|
||||||
};
|
|
||||||
}
|
|
||||||
//保存成功的聊天
|
|
||||||
setLastChatJson(resjson);
|
|
||||||
return {
|
|
||||||
ok: true,
|
|
||||||
message: 'ok',
|
|
||||||
obj: new Chat(magicUrl, chatWithMagic, resjson.conversationId, resjson.clientId, resjson.conversationSignature, theChatType)
|
|
||||||
};
|
|
||||||
} catch (e) {
|
|
||||||
console.warn(e);
|
|
||||||
return {
|
|
||||||
ok: false,
|
|
||||||
message: "发生错误,可能是魔法链接无法链接:" + e.message
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
|
return {
|
||||||
|
ok: false,
|
||||||
|
message: mes
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue