Simatwa / WebChatGPT

Python SDK/API for ChatGPT Web-Version
GNU General Public License v3.0
96 stars 24 forks source link

[error] decoding json code as response #13

Closed XenocodeRCE closed 7 months ago

XenocodeRCE commented 9 months ago

Code

from WebChatGPT import ChatGPT
bot = ChatGPT(
    "C:/Users/.../openai.json"
)
response = bot.chat('bonjour')

print(response)

Error

Traceback (most recent call last):
  File "C:\Users\...\AppData\Roaming\Python\Python310\site-packages\requests\models.py", line 971, in json
    return complexjson.loads(self.text, **kwargs)
  File "C:\Program Files\Python310\lib\json\__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File "C:\Program Files\Python310\lib\json\decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Program Files\Python310\lib\json\decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\...\Desktop\wcb.py", line 5, in <module>
    response = bot.chat('bonjour')
  File "C:\Users\...\AppData\Roaming\Python\Python310\site-packages\WebChatGPT\main.py", line 320, in chat
    resp = self.ask(prompt, stream)
  File "C:\Users\...\AppData\Roaming\Python\Python310\site-packages\WebChatGPT\main.py", line 238, in ask
    ws_payload = dict(response.json())
  File "C:\Users\...\AppData\Roaming\Python\Python310\site-packages\requests\models.py", line 975, in json
    raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
11100010 commented 8 months ago

the same error:

wbc interactive 13:34.11 Fri Feb 23 2024 >>> ╭─────────────────────────────────── WebChatGPT v0.2.9 ────────────────────────────────────╮ │ │ │ Repo : https://github.com/Simatwa/WebChatGPT │ │ By : Smartwa │ │ │ ╰──────────────────────────────────────────────────────────────────────────────────────────╯ Welcome to Reverse Engineering of ChatGPT Web-version. Type help or h for general help info. ┌─~~~@WebChatGPT └──╼ ❯❯❯hello 13:34:28 - ERROR : Expecting value: line 1 column 1 (char 0) ┌─~~~@WebChatGPT └──╼ ❯❯❯

Simatwa commented 8 months ago

As it stands the SDK is very unreliable. This happens due to the fact that I've limited info on how the responses are generated using the http and websocket protocols interchangeably. That's why you would find at times you get the response just as expected and then next time an exception is raised. So overcoming that is a kinda a problem at the moment, but I'm full of hopes that it gonna get a fix just in if not on time.

XenocodeRCE commented 8 months ago

maybe allow us to Verbose ? So we can see whats wrong. I suspect here that the returned data is simply not JSON. Also OpenAI added a little chall on the ChatGpt website to prevent bots, maybe it has to do with it ?

Simatwa commented 8 months ago

As for verbose, I implemented that for websocket using the trace parameter:

bot = ChatGPT("<path-to-cookies>", trace=True)

Regarding bot mitigation on the site, it is likely that they made some changes, which is why the old implementation is no longer effective.

thangckt commented 8 months ago

i have the same problem

Simatwa commented 7 months ago

Greeting folks. The old implementation that doesn't rely on websocket is back. So the recent release is very reliable. Thanks for your great concerns and patience.