77 lines
2.7 KiB
HTML
77 lines
2.7 KiB
HTML
![]() |
<!DOCTYPE html>
|
||
|
<html lang="zh-CN">
|
||
|
<head>
|
||
|
<meta name="renderer" content="webkit"/>
|
||
|
<meta name="force-rendering" content="webkit"/>
|
||
|
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
|
||
|
<meta charset="UTF-8"/>
|
||
|
<meta name="viewport"
|
||
|
content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0, viewport-fit=cover"/>
|
||
|
<title>智能助理</title>
|
||
|
<link rel="stylesheet" href="https://g.alicdn.com/chatui/sdk-v2/0.3.8/sdk.css">
|
||
|
</head>
|
||
|
<body>
|
||
|
<div id="root"></div>
|
||
|
<script src="https://g.alicdn.com/chatui/sdk-v2/0.3.8/sdk.js"></script>
|
||
|
<script src="https://g.alicdn.com/chatui/extensions/5.18.0/isv-parser.js"></script>
|
||
|
<script>
|
||
|
const messages = [];
|
||
|
|
||
|
var bot = new ChatSDK({
|
||
|
config: {
|
||
|
navbar: {
|
||
|
title: '智能助理'
|
||
|
},
|
||
|
robot: {
|
||
|
avatar: 'https://gw.alicdn.com/tfs/TB1U7FBiAT2gK0jSZPcXXcKkpXa-108-108.jpg'
|
||
|
},
|
||
|
// 用户头像
|
||
|
user: {
|
||
|
avatar: 'https://gw.alicdn.com/tfs/TB1DYHLwMHqK1RjSZFEXXcGMXXa-56-62.svg',
|
||
|
},
|
||
|
messages: [
|
||
|
{
|
||
|
type: 'text',
|
||
|
content: {
|
||
|
text: '智能助理为您服务,请问有什么可以帮您?'
|
||
|
}
|
||
|
}
|
||
|
]
|
||
|
},
|
||
|
requests: {
|
||
|
send: function (msg) {
|
||
|
// alert(msg.content.text)
|
||
|
messages.push({role: "user", content: msg.content.text});
|
||
|
const body = JSON.stringify({model: "google/gemma-7b-it:free", messages: messages});
|
||
|
// alert(body)
|
||
|
if (msg.type === 'text') {
|
||
|
return {
|
||
|
method: 'POST',
|
||
|
url: 'https://openrouter.ai/api/v1/chat/completions',
|
||
|
headers: {
|
||
|
'Content-Type': 'application/json',
|
||
|
'Authorization': 'Bearer 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'
|
||
|
},
|
||
|
body: body
|
||
|
};
|
||
|
}
|
||
|
}
|
||
|
},
|
||
|
handlers: {
|
||
|
parseResponse: function (res, requestType) {
|
||
|
// alert(requestType);
|
||
|
console.log(res);
|
||
|
if (requestType === 'send' && res?.choices?.length > 0) {
|
||
|
let res1=res?.choices[0]?.message?.content;
|
||
|
return {type: 'text', content: {text: res1}};
|
||
|
}
|
||
|
return res;
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
|
||
|
bot.run();
|
||
|
</script>
|
||
|
<script src="https://g.alicdn.com/chatui/icons/2.0.2/index.js" async></script>
|
||
|
</body>
|
||
|
</html>
|