LibreChat icon indicating copy to clipboard operation
LibreChat copied to clipboard

[error]: /turing/conversation/create: failed to parse response body

Open leoleaf opened this issue 1 year ago • 3 comments

hello, guys. this project is really fantastic, i have been using it for a while time. but,yesterday,when i asked bingAI,it returned a error. Have you ever see this error?

An error occurred. Please try again in a few moments. Error message: /turing/conversation/create: failed to parse response body. ...

leoleaf avatar May 24 '23 02:05 leoleaf

Hi, yes it seems Bing has updated something on their end but I have a solution for you. Update the project to latest on main branch, I also posted this here: https://github.com/waylaidwanderer/node-chatgpt-api/issues/378#issuecomment-1559868368 and updated the project accordingly here #369

You will need to set BINGAI_TOKEN in your ./api/.env file (or in your browser if using "user_provided") to your full cookies string from bing.com, instead of just the U= value.

This is confirmed working for me

image

Using firefox and dev tools, i get my cookies string from here:

image


You can use any browser, just fish around in the network tab to see which request has a Cookie value in the Request headers

image

Thanks for checking out the project, I'm glad you're enjoying it!

danny-avila avatar May 24 '23 02:05 danny-avila

@feng2505664393 let me know if the above worked for you

There were also some other suggestions at the bottom of this issues page https://github.com/waylaidwanderer/node-chatgpt-api/issues/378

danny-avila avatar May 24 '23 13:05 danny-avila

@feng2505664393 let me know if the above worked for you

There were also some other suggestions at the bottom of this issues page waylaidwanderer/node-chatgpt-api#378

Sorry, sir. I used an old version of chat-clone. In order to try the solution you provided, I had to update my Docker image. It took me some time, but the exciting thing is that I just finished all the work on the solution and it works! Hahaha, thank you.

leoleaf avatar May 24 '23 15:05 leoleaf

Awesome, glad to help!

danny-avila avatar May 24 '23 18:05 danny-avila

if like me you do not like manual steps to derive BING_API_TOKEN configuration, this can be automated

if __name__ == "__main__":
    token = get_bing_api_token("username", "password")
    print(token)

python selenium function to get BING_API_TOKEN
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException as STimeout
from http.cookies import SimpleCookie
import json
import time

def get_bing_api_token(
    username,
    password,
    headless=True,
    remote_selenium="http://localhost:4444",
    wait=10,
    json_outfile="bing_cookie.json",
):
    options = webdriver.ChromeOptions()
    options.set_capability("goog:loggingPrefs", {"performance": "ALL"})

    if headless:
        options.add_argument("headless")  # Run browser in headless mode

    # Create a new WebDriver instance with Docker
    driver = webdriver.Remote(remote_selenium, options=options)

    # Open Bing
    driver.get("https://www.bing.com")

    # <button id="bnp_btn_accept" class="bnp_btn_accept">
    # respond to cookies
    try:
        cookie = WebDriverWait(driver, wait).until(
            EC.element_to_be_clickable((By.ID, "bnp_btn_accept"))
        )
        cookie.click()
    except STimeout:
        pass

    try:
        login_button = WebDriverWait(driver, wait).until(
            EC.element_to_be_clickable((By.ID, "id_l"))
        )
        login_button.click()

        username_field = WebDriverWait(driver, wait).until(
            EC.element_to_be_clickable((By.ID, "i0116"))
        )
        username_field.send_keys(username)
        username_field.send_keys(Keys.ENTER)

        password_field = WebDriverWait(driver, wait).until(
            EC.element_to_be_clickable((By.ID, "i0118"))
        )
        password_field.send_keys(password)
        password_field.send_keys(Keys.ENTER)

        signed_in_no = WebDriverWait(driver, wait).until(
            EC.element_to_be_clickable((By.ID, "idBtn_Back"))
        )
        signed_in_no.click()

        cookie = SimpleCookie()
        interesting = []
        # loop until some appropriate cookies are found
        while len(interesting) == 0:
            time.sleep(1)

            logs_raw = driver.get_log("performance")
            for r in logs_raw:
                try:
                    hdr = json.loads(r["message"])["message"]["params"][
                        "headers"
                    ]
                    if "cookie" in hdr.keys():
                        cookie.load(hdr["cookie"])
                        hdr["cookie"] = {
                            k: v.value for k, v in cookie.items()
                        }
                        if "_U" in hdr["cookie"].keys():
                            interesting.append(hdr)
                except KeyError:
                    pass

        if json_outfile is not None:
            with open("bing_cookie.json", "w") as f:
                json.dump(interesting, f, indent=2)

        return interesting[0]["cookie"]["_U"]
    except STimeout:
        return "selenium timeout"
    finally:
        # Close the WebDriver session
        driver.quit()

rraymondgh avatar Dec 09 '23 17:12 rraymondgh