はじめに
Bing AIチャットの順番待ち登録が済んでいる事が大前提となっています。
やっておくと楽な行為
Cookie に関する操作があるので、Edgeアドオン『Cookie Editor』を使って Cookie を閲覧すると作業が楽になります。
導入部分
npm install bing-chat dotenv
package.json
{
+ "type": "module",
"name": "bing-chat-qiita-demo",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "MIT",
"dependencies": {
"bing-chat": "^0.2.1",
"dotenv": "^16.0.3"
}
}
.env
BING_COOKIE="Cookie「_U」 の Value をここに設置してください。"
コード
main.js
import dotenv from 'dotenv'
import { BingChat } from 'bing-chat'
dotenv.config();
(async () => {
const api = new BingChat({
cookie: process.env.BING_COOKIE
});
const res = await api.sendMessage('こんにちは');
console.log(res.text);
})();
output
こんにちは、Bingです。どうぞよろしくお願いします。😊
注意
非公式ライブラリを用いての実装の為、Bing Chat 自体の仕様変更により動作不能になる恐れがある事をご了承ください。