Giter Site home page Giter Site logo

transitive-bullshit / bing-chat Goto Github PK

View Code? Open in Web Editor NEW
1.2K 16.0 129.0 336 KB

Node.js client for Bing's new AI-powered search. It's like ChatGPT on steroids 🔥

License: MIT License

Shell 2.71% JavaScript 2.87% TypeScript 94.42%
ai bing chatbot chatgpt search

bing-chat's Introduction

bing-chat's People

Contributors

dickymuliafiqri avatar ericlewis avatar lukasdotcom avatar transitive-bullshit avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bing-chat's Issues

Cookie not needed

I just set the cookie to '' and it still worked for the example in the README.

We should update the documentation if the project becomes active again

use bing chat to get images

Bing has a new feature additon to allow for us to use the chat for image generation with DALL-E 3 image generation engine. Was wondering if we can get this api to interact with that image generation also

unexpected HTTP error createConversation 403

npx tsx d:\code\python\binggpt\bing-chat-main\demos\demo.ts
windows 11

✖ What are today’s top stories in the United States?
Error: unexpected HTTP error createConversation 403: Forbidden
at (d:\code\python\binggpt\bing-chat-main\src\bing-chat.ts:317:15)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at BingChat.sendMessage (d:\code\python\binggpt\bing-chat-main\src\bing-chat.ts:65:28)
at async oraPromise (file:///d:/code/python/binggpt/bing-chat-main/node_modules/ora/index.js:397:18)
at main (d:\code\python\binggpt\bing-chat-main\demos\demo.ts:20:15)

I can log in https://www.bing.com,Can chat normally
image

cookie
RDBBN1J1 @~%N2($M}0 E9J

1F)~% XG$XM5GZ7F`_%L HP

Why would you report 403?

_U Cookie Generation

Unsure if this is even something that is possible, but has anyone looked into reverse engineering the _U cookie generation such that it would not have to be manually refreshed every few days? This would be super useful if a new cookie can be generated through an endpoint or node.js so that a service might be totally self sufficient.

Use diffirent chat modes?

Bing chat has Normal, Balanced and Precise modes, it would be nice to be able to set this via a parameter.

Is there a way to send also images in the request?

The idea would be to be able to send inside sendMessage a base64 encoded image as to get also an analysis on it. There is an endpoint https://www.bing.com/images/kblob from which through a POST I believe you can generate a blobId, processedBlobId.

Screenshot 2023-09-24 at 12 40 54

Screenshot 2023-09-24 at 12 41 07

Once the kblob is generated, a GET request is performed to assess that the upload is successful (?).
Screenshot 2023-09-24 at 12 41 27

Anyone knows how to do it?

Thank you :)

Empty text response from bing-chat

My code is set up correctly, have tried with and without cookies, tried resetting my _U cookie, but the empty "text" object in response keep coming empty =(

image

Node.js v18.12.1

Connect Timeout error

I am just trying to run the demo example with npx tsx demo.ts but I keep getting this timeout error. I included my _U cookie

TypeError: fetch failed
    at Object.fetch (node:internal/deps/undici/undici:11576:11)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at BingChat.sendMessage (c:\Users\j50032330\Documents\bing-chat-main\bing-chat-main\src\bing-chat.ts:65:28)
    at async oraPromise (file:///C:/Users/j50032330/Documents/bing-chat-main/bing-chat-main/node_modules/ora/index.js:397:18)
    at main (c:\Users\j50032330\Documents\bing-chat-main\bing-chat-main\demos\demo.ts:20:15) {
  cause: ConnectTimeoutError: Connect Timeout Error
      at onConnectTimeout (node:internal/deps/undici/undici:8522:28)
      at node:internal/deps/undici/undici:8480:50
      at Immediate._onImmediate (node:internal/deps/undici/undici:8509:37)
      at process.processImmediate (node:internal/timers:478:21) {
    code: 'UND_ERR_CONNECT_TIMEOUT'
  }
}

Support return AI-generated image

The newest version of Bing chat is able to respond to prompts with a DALL-E generated image, so I'm wondering if the api can get return the generated image. Currently the response to a prompt like draw me a cat with a large top hat is

I'm sorry but I'm not able to draw pictures as I am a text-based conversational agent. However, I can suggest some websites where you can find images of cats with top hats. Would you like me to do that?

Bing Chat advanced features?

Hi, is it possible to utilize the Bing specific features like reading pdfs or URLs through this wrapper? I'm guessing for URLs you can simply have it open a text link but what about reading a file?

Error: unexpected HTTP error createConversation 503: Service Unavailable

When trying to run any of the demos I get this error:

(base) raschidjfr@MacBook-Pro-de-Raschid bing-chat % npx tsx demos/demo
✖ What are today’s top stories in the United States?
Error: unexpected HTTP error createConversation 503: Service Unavailable
    at <anonymous> (/Users/raschidjfr/Documents/git/bing-chat/src/bing-chat.ts:317:15)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at BingChat.sendMessage (/Users/raschidjfr/Documents/git/bing-chat/src/bing-chat.ts:65:28)
    at async oraPromise (file:///Users/raschidjfr/Documents/git/bing-chat/node_modules/ora/index.js:397:18)
    at main (/Users/raschidjfr/Documents/git/bing-chat/demos/demo.ts:20:15)

The error is traced back to this block. Removing the cookie from the headers seems to fix the problem:

return fetch('https://www.bing.com/turing/conversation/create', {
      headers: {
        accept: 'application/json',
        'accept-language': 'en-US,en;q=0.9',
        'content-type': 'application/json',
        'sec-ch-ua':
          '"Not_A Brand";v="99", "Microsoft Edge";v="109", "Chromium";v="109"',
        'sec-ch-ua-arch': '"x86"',
        'sec-ch-ua-bitness': '"64"',
        'sec-ch-ua-full-version': '"109.0.1518.78"',
        'sec-ch-ua-full-version-list':
          '"Not_A Brand";v="99.0.0.0", "Microsoft Edge";v="109.0.1518.78", "Chromium";v="109.0.5414.120"',
        'sec-ch-ua-mobile': '?0',
        'sec-ch-ua-model': '',
        'sec-ch-ua-platform': '"macOS"',
        'sec-ch-ua-platform-version': '"12.6.0"',
        'sec-fetch-dest': 'empty',
        'sec-fetch-mode': 'cors',
        'sec-fetch-site': 'same-origin',
        'x-edge-shopping-flag': '1',
        'x-ms-client-request-id': requestId,
        'x-ms-useragent':
          'azsdk-js-api-client-factory/1.0.0-beta.1 core-rest-pipeline/1.10.0 OS/MacIntel',
        // cookie    <- Removing this line fixes the problem
      },
      referrer: 'https://www.bing.com/search',
      referrerPolicy: 'origin-when-cross-origin',
      body: null,
      method: 'GET',
      mode: 'cors',
      credentials: 'include'
    })

Instruction on using Bing API on LiteLLM to function as OpenAI compatible API

Hi there- is anyone willing to share whether you can get the bing AI API set up to use it as an OpenAI compatible API?

May be able to use LiteLLM but I'm having trouble figuring it out. They just released a server to host the liteLLM API so could be used (I think) either locally or online via proxy server?

Would be grateful if someone could explain or provide a brief tutorial since I'm struggling to figure it out... Thank you!

Socket closes mid-generation

For me, the websocket closes mid-generation and I never get a response. When I enable partial responses, I can see that the script just exits mid-response. I did some digging and saw the socket just closes for whatever reason.

Anyone else have that issue?

Module '"node:crypto"' has no default export

I got the below error while trying to test it at WSL 2 (Ubuntu under Windows), thanks

$ ls
demos  docs  license  main.js  media  node_modules  package-lock.json  package.json  pnpm-lock.yaml  readme.md  src  tsconfig.json  tsup.config.ts  typedoc.json
$ cd demos
$ ls
demo-conversation.ts  demo-on-progress.ts  demo.ts
$ npx tsc demo-conversation.ts
../src/bing-chat.ts:1:8 - error TS1192: Module '"node:crypto"' has no default export.

1 import crypto from 'node:crypto'
         ~~~~~~

../src/bing-chat.ts:3:8 - error TS1259: Module '"/home/hajsf/bing-chat/node_modules/@types/ws/index"' can only be default-imported using the 'esModuleInterop' flag

3 import WebSocket from 'ws'
         ~~~~~~~~~

  ../node_modules/@types/ws/index.d.ts:398:1
    398 export = WebSocket;
        ~~~~~~~~~~~~~~~~~~~
    This module is declared with 'export =', and can only be used with a default import when using the 'esModuleInterop' flag.


Found 2 errors in the same file, starting at: ../src/bing-chat.ts:1

MUID cookie is now required for convsersation/create?

Starting this morning, I've ran into an issue where you can't create a chat without the MUID. It throws a 404. I have my own update to fix that, but I wanted to see if other people have been having that issue.

The MUID comes from Microsoft for ad tracking: https://learn.microsoft.com/en-us/clarity/setup-and-installation/cookie-list
The format looks like a 32 digit hex uppercase / GUID, but you aren't able to spoof it - I tried. I wonder if you can use a blank MR or MR=true and it hits the same middleware and generates a new MUID. I don't know enough about the Microsoft cookies.

Once the MUID and _U are added to the cookie, it works like always.

const fetchOptions = { ...otherStuff, cookie: `MUID=<32-digit-hex>; _U=<user-token>; `} 

BING_COOKIE

Hi.

How can I get the bing coojie, I've the below list of cookies with the chat tab, which one shall I use?:

image

SyntaxError: Unexpected end of JSON input

SyntaxError: Unexpected end of JSON input
    at JSON.parse (<anonymous>)
    at parseJSONFromBytes (node:internal/deps/undici/undici:6571:19)
    at successSteps (node:internal/deps/undici/undici:6545:27)
    at node:internal/deps/undici/undici:1211:60
    at node:internal/process/task_queues:140:7
    at AsyncResource.runInAsyncScope (node:async_hooks:203:9)
    at AsyncResource.runMicrotask (node:internal/process/task_queues:137:8)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

This error is coming when i send message to api, and thing is it works in windows, but when i try in host it sends above error

ERROR in node:crypto

i am getting this error while importing the bing-chat into the component

ERROR in node:crypto
Module build failed: UnhandledSchemeError: Reading from "node:crypto" is not handled by plugins (Unhandled scheme).
Webpack supports "data:" and "file:" URIs by default.
You may need an additional plugin to handle "node:" URIs.
at /home/ankush/bingchat/node_modules/webpack/lib/NormalModule.js:838:25
at Hook.eval [as callAsync] (eval at create (/home/ankush/bingchat/node_modules/tapable/lib/HookCodeFactory.js:33:10), :6:1)
at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (/home/ankush/bingchat/node_modules/tapable/lib/Hook.js:18:14)
at Object.processResource (/home/ankush/bingchat/node_modules/webpack/lib/NormalModule.js:835:8)
at processResource (/home/ankush/bingchat/node_modules/loader-runner/lib/LoaderRunner.js:220:11)
at iteratePitchingLoaders (/home/ankush/bingchat/node_modules/loader-runner/lib/LoaderRunner.js:171:10)
at runLoaders (/home/ankush/bingchat/node_modules/loader-runner/lib/LoaderRunner.js:398:2)
at NormalModule._doBuild (/home/ankush/bingchat/node_modules/webpack/lib/NormalModule.js:825:3)
at NormalModule.build (/home/ankush/bingchat/node_modules/webpack/lib/NormalModule.js:969:15)
at /home/ankush/bingchat/node_modules/webpack/lib/Compilation.js:1377:12

webpack compiled with 1 error and 1 warning

Chat quality is significantly worse than using the official Bing Chat interface

For example, using the prompt Can you explain how Silicon Valley Bank collapsed?

Here's what the official Bing Chat interface generated:

  • Silicon Valley Bank (SVB) was a bank that specialized in providing loans and services to startups and tech companies. On March 10, 2023, it failed after a bank run, which means that many depositors tried to withdraw their money at the same time¹⁵. This happened because SVB had invested heavily in risky assets that lost value due to market volatility and regulatory changes². SVB also faced lawsuits for misleading its stockholders about its financial health². The collapse of SVB was the largest bank failure since the 2008 financial crisis and the second-largest in U.S. history¹⁵. It affected many startups from the US and abroad, who could not access their funds or get new loans¹⁵. Some of SVB's international branches were rescued by other banks, such as HSBC in the UK³.

And here's what the reverse engineered API (this repo) generates:

  • Hello, this is Bing. I can explain what happened to Silicon Valley Bank (SVB) based on some news articles. SVB was a bank that specialized in lending to tech companies and startups. It collapsed on Friday after a run on deposits and a capital crisis. It was the largest bank failure since 2008. The FDIC backed 100% of its deposits, giving account holders access to all their money. However, many customers are still facing challenges with their finances. What aspect of SVB's collapse are you most interested in?

Does anyone have any ideas on why this quality discrepancy is happening? My hypothesis is that the Bing Chat UI is using a newer model. I looked through the network tab whilst interacting with the Bing Chat UI and there doesn't seem to be any difference in the requests.

Any ideas?

[MAJOR ISSUE] ECONNRESET & Failed to fetch, for a majority of the requests

Directly using one of the examples, line for line. These are the errors I get. Sometimes I will get a proper request but that is very rare. The errors I get will either be The websocket error one or a Failed fetch: Type Error.

Below is two attempts at running the demo, I was not having this issue the other day.
image

cannot work for current new bing

Hi! I find it cannot handle responses from new bing now. It could work several hours ago, but now it cannot. I think something is changed in the responses of current new bing.

Error log:

file:///app/node_modules/bing-chat/build/index.js:148
              const msg = update.arguments[0].messages[0];
                                                      ^

TypeError: Cannot read properties of undefined (reading '0')
    at WebSocket.<anonymous> (file:///app/node_modules/bing-chat/build/index.js:148:55)
    at WebSocket.emit (node:events:512:28)
    at Receiver.receiverOnMessage (/app/node_modules/ws/lib/websocket.js:1184:20)
    at Receiver.emit (node:events:512:28)
    at Receiver.dataMessage (/app/node_modules/ws/lib/receiver.js:541:14)
    at Receiver.getData (/app/node_modules/ws/lib/receiver.js:459:17)
    at Receiver.startLoop (/app/node_modules/ws/lib/receiver.js:158:22)
    at Receiver._write (/app/node_modules/ws/lib/receiver.js:84:10)
    at writeOrBuffer (node:internal/streams/writable:392:12)
    at _write (node:internal/streams/writable:333:10)

Error: WebSocket error: Error: Unexpected server response: 200

Error: WebSocket error: Error: Unexpected server response: 200
at WebSocket. (file:///home/container/node_modules/bing-chat/build/index.js:83:20)
at WebSocket.emit (node:events:513:28)
at emitErrorAndClose (/home/container/node_modules/ws/lib/websocket.js:1008:13)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21)

text req null

I use your library when I call to get the answer and only get null text results

Stops working sometimes

I've created a wrapper API for this package to use as an endpoint hosted on AWS Lambda, however sometimes it starts returning empty text responses. Redeploying the wrapper to another locale Lambda function works, but that too can start returning empty responses after a point. Not sure what is causing this activity.

Are continued conversations supported?

To keep conversation context, I tried both:

  1. creating a conversation and then using the conversationId in api.sendMessage;
  2. sending a message with api.sendMessage, saving the conversationId from that response and reusing it later.

Neither method worked. The answer always comes with an empty string.
Normal messages without specifying conversationId work as expected.

I am wondering if this is supported at all, since it's not included in the README.md? Thanks.

Express error

i want to add this library on my express but it is not working on server. It works very well on local machine but not working on server side when i host it on any platform

app.post('/chat-wsb-client', async (req, res) => {
  try {
    const chatClient = new BingChat({
      cookie: process.env.UNITRIX,
    })
    const prompt = req?.body?.chat || 'Hi, How are you?'
    const result = await chatClient.sendMessage(prompt, {
      variant: 'Precise',
    })
    res.send({ response: result?.text, cid: result?.conversationId })
  } catch (error) {
    res.send({ error, msg: 'runtime error' })
  }
})

It no longer works

It seems to no longer work, I've tried adding the _U cookie and also tried adding all cookies but it doesn't return any results.

HTTP error createConversation 404

Hi! I find it cannot handle responses from new bing now. It could work several hours ago, but now it cannot. I think something is changed in the responses of current new bing.

Error log:
Error: unexpected HTTP error createConversation 404: Not Found

Unable to receive a response when asking questions in creative mode

Hello, first of all, thank you for your reverse engineering work on newbing. I have packaged it as a simple backend API that can post questions and related configurations directly for asking and continuous conversation. If I want to open source it on gitee, what kind of identification should I use? I used bing-chat in the dependencies.

The second question is, if I ask questions in creative mode and it is slightly complex, I may not be able to get a response most of the time. Could you please tell me if your project sets the limit for return time or if it is a limitation from Microsoft's side? I hope this can be resolved.

I am a developer from China. Please let me know if there are any errors in my translation.

Request from Server at United States Datacenter

Hi All,
Has anyone faced the following error while running bing-chat (bing-chat-rnz) code from a server located in the United States? I am getting the following error.

WebSocket error: Error: Unexpected server response: 200

Is is working ?

Hi, I just found out this repo and I can't make it work, I got the cookie from edge by visiting https://www.bing.com
and in dev tools - applications - cookies for https://www.bing.com get the _U cookie, but when I run the example :

const res = await api.sendMessage('Write a 500 word essay on frogs.', {
        // change the variant to 'Precise'
        variant: 'Creative'
      })

    // print the full text at the end
    console.log(res)

it just finished up quickly with

{
  author: 'bot',
  id: '04119b41-7338-48b4-84dd-9b0e2d543964',
  conversationId: undefined,
  clientId: undefined,
  conversationSignature: undefined,
  invocationId: '2',
  text: ''
}

Is there anything I missing ?

TIA

CAPTCHA requirements

It seems that Microsoft have done any API update and now they require CAPTCHA, any solution? thanks!

"result": {
"value": "CaptchaChallenge",
"message": "User needs to solve CAPTCHA to continue.",
"error": "User needs to solve CAPTCHA to continue.",
"serviceVersion": "20230803.43"
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.