Deploy natively
git clone https://github.com/tuhinpal/bingchat-api.git
cd bingchat-api
npm run build
npm start
Deploy with Docker
git clone https://github.com/tuhinpal/bingchat-api.git
cd bingchat-api
docker build -t bingchat-api .
docker run -it -d -p 8080:8080 bingchat-api
Or, You can fork this repository and connect it to any provider which supports Docker/NodeJS.
This api need your cookie to generate conversation. So, you should have beta access. After deployment login to that bing account and open developer console. Then paste the code (replace your serverUrl
).
const cookie = document.cookie;
const serverUrl = "http://localhost:8080";
fetch(`${serverUrl}/set-cookie`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ cookie }),
})
.then((res) => res.json())
.then((res) => console.log(res))
.catch((err) => console.log(err));
POST /create-conversation
GET /generate
Query Parameter | Type | Description |
---|---|---|
conversationId |
string |
Required. Get it after /create-conversation |
clientId |
string |
Required. Get it after /create-conversation |
conversationSignature |
string |
Required. Get it after /create-conversation |
text |
string |
Required. Text prompt |
Note: It uses EventSource stream to send content upon generation.
Use the client library to implement these with ease.
npm install bing-chatai-client
import { createConversation, Generate } from "bing-chatai-client";
const conversation = await createConversation("http://localhost:8080");
console.log(conversation);
const gen = new Generate(conversation.conversationUrl);
gen.generate("Hello bing what is an ai?");
gen.onMessage((data) => {
console.log(data);
});
gen.onFinished((message) => {
console.info(message);
});
gen.onError((message) => {
console.error(message);
});
If you have any feedback, please reach me out at me[at]thetuhin.com.
Contributions are always welcome!
This project is licensed under MIT. This project is made as a proof of concept and doesnot meant to harm microsoft.