mirror of
https://github.com/torappinfo/uweb.git
synced 2024-08-14 23:54:59 +00:00
Compare commits
No commits in common. "74511d89e0530b53f86b9ce828af58eaa534b7f2" and "89edcd3d46245d36ec1a8832211d9fe6992623a1" have entirely different histories.
74511d89e0
...
89edcd3d46
4 changed files with 212 additions and 30 deletions
|
@ -82,6 +82,7 @@
|
||||||
}
|
}
|
||||||
</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>
|
||||||
|
|
65
en/searchurl/bingAI/js/ChatMessages.js
Normal file
65
en/searchurl/bingAI/js/ChatMessages.js
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
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,11 +1,13 @@
|
||||||
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');
|
||||||
var input_text = document.getElementById('input');
|
var input_text = document.getElementById('input');
|
||||||
var send_button = document.getElementById('send');
|
var send_button = document.getElementById('send');
|
||||||
let restartNewChat = document.getElementById('restartNewChat');
|
let restartNewChat = document.getElementById('restartNewChat');
|
||||||
var thisChatType = chatTypes.balance;
|
var thisChatType;
|
||||||
|
|
||||||
reSetStartChatMessage();
|
reSetStartChatMessage();
|
||||||
|
|
||||||
|
@ -30,6 +32,28 @@ 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) {
|
||||||
|
@ -83,9 +107,6 @@ var isSpeaking = false;
|
||||||
|
|
||||||
/**重置聊天框和聊天建议到初始状态 */
|
/**重置聊天框和聊天建议到初始状态 */
|
||||||
function reSetStartChatMessage(type) {
|
function reSetStartChatMessage(type) {
|
||||||
createChat(thisChatType).then((r) => {
|
|
||||||
if(r.ok) talk = r.obj;
|
|
||||||
});
|
|
||||||
getChatHubWithMagic().then(async a => {
|
getChatHubWithMagic().then(async a => {
|
||||||
let t = 0;
|
let t = 0;
|
||||||
if (a == 'repeat') {
|
if (a == 'repeat') {
|
||||||
|
@ -95,6 +116,7 @@ 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
|
||||||
|
@ -108,12 +130,26 @@ 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:聊天啦啦啦啦';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**正在创建聊天 */
|
/**正在创建聊天 */
|
||||||
function isAskingToMagic() {
|
function isAskingToMagic() {
|
||||||
isSpeaking = true;
|
isSpeaking = true;
|
||||||
send_button.value = '施法中.';
|
send_button.value = '施法中.';
|
||||||
|
searchSuggestions.innerHTML = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**bing正在回复 */
|
/**bing正在回复 */
|
||||||
|
@ -124,6 +160,7 @@ function isSpeakingStart(chatWithMagic, sendText) {
|
||||||
docTitle.innerText = sendText;
|
docTitle.innerText = sendText;
|
||||||
}
|
}
|
||||||
send_button.value = '响应中.';
|
send_button.value = '响应中.';
|
||||||
|
searchSuggestions.innerHTML = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**bing回复结束 */
|
/**bing回复结束 */
|
||||||
|
@ -143,6 +180,9 @@ 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;
|
||||||
}
|
}
|
||||||
|
@ -207,6 +247,11 @@ 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,12 +348,51 @@ class Chat {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/***
|
||||||
|
* 补齐url
|
||||||
|
*/
|
||||||
function URLTrue(magicUrl, thiePath) {
|
function URLTrue(magicUrl, thiePath) {
|
||||||
return url + thiePath;
|
let url = magicUrl;
|
||||||
|
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) {}
|
||||||
|
|
||||||
|
@ -367,8 +406,21 @@ 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');
|
||||||
|
@ -385,15 +437,33 @@ async function createChat(theChatType) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let mes;
|
|
||||||
do {
|
|
||||||
try {
|
try {
|
||||||
let res = await fetch(URLTrue(magicUrl,'turing/conversation/create'),
|
await copyCookies(magicUrl);
|
||||||
{credentials: 'include'});
|
let res = await fetch(URLTrue(magicUrl, 'Create'),{credentials: 'include'});
|
||||||
let resjson = await res.json();
|
let resjson = await res.json();
|
||||||
if (!resjson.result || resjson.result.value != 'Success') {
|
if (!resjson.result) {
|
||||||
mes = resjson;
|
console.warn(resjson);
|
||||||
break;
|
return {
|
||||||
|
ok: false,
|
||||||
|
message: "未知错误!"
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (resjson.result.value != 'Success') {
|
||||||
|
let type = resjson.result.value;
|
||||||
|
let mess = resjson.result.message;
|
||||||
|
if (resjson.result.value == 'UnauthorizedRequest') {
|
||||||
|
type = 'NoLogin'
|
||||||
|
mess = '首先你需要在bing登录微软账号!请前往 https://cn.bing.com/ 登录微软账号。';
|
||||||
|
} else if (resjson.result.value == 'Forbidden') {
|
||||||
|
type = 'NoPower'
|
||||||
|
mess = '你还没有获得NewBing的使用权限';
|
||||||
|
}
|
||||||
|
console.warn(resjson);
|
||||||
|
return {
|
||||||
|
ok: false,
|
||||||
|
type: type,
|
||||||
|
message: mess
|
||||||
|
};
|
||||||
}
|
}
|
||||||
//保存成功的聊天
|
//保存成功的聊天
|
||||||
setLastChatJson(resjson);
|
setLastChatJson(resjson);
|
||||||
|
@ -402,11 +472,12 @@ async function createChat(theChatType) {
|
||||||
message: 'ok',
|
message: 'ok',
|
||||||
obj: new Chat(magicUrl, chatWithMagic, resjson.conversationId, resjson.clientId, resjson.conversationSignature, theChatType)
|
obj: new Chat(magicUrl, chatWithMagic, resjson.conversationId, resjson.clientId, resjson.conversationSignature, theChatType)
|
||||||
};
|
};
|
||||||
} catch (e) {mes = e.message;}
|
} catch (e) {
|
||||||
}while(false);
|
console.warn(e);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
ok: false,
|
ok: false,
|
||||||
message: mes
|
message: "发生错误,可能是魔法链接无法链接:" + e.message
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue