simpleaichat icon indicating copy to clipboard operation
simpleaichat copied to clipboard

orjson.JSONDecodeError: Input is a zero-length, empty document: line 1 column 1 (char 0)

Open pcustic opened this issue 1 year ago • 8 comments

I tried to use simpleaichat but received error from the title. I installed simpleaichat in new virtual env and ran it in Python prompt.

Full traceback:

>>> AIChat(api_key="sk-***")
ChatGPT: Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "***/venv/lib/python3.9/site-packages/simpleaichat/simpleaichat.py", line 64, in __init__
    self.interactive_console(character=character, prime=prime)
  File "***/venv/lib/python3.9/site-packages/simpleaichat/simpleaichat.py", line 207, in interactive_console
    for chunk in sess.stream("Hello!", self.client):
  File "***/venv/lib/python3.9/site-packages/simpleaichat/chatgpt.py", line 147, in stream
    chunk_dict = orjson.loads(chunk)
orjson.JSONDecodeError: Input is a zero-length, empty document: line 1 column 1 (char 0

It happens also if I give it any argument like "Ronald McDonald" or similar.


Environment: macOS Ventura 13.0.1 Python 3.9 Api key for ChatGPT Plus.

pcustic avatar Jun 19 '23 20:06 pcustic

This appears to be the result of a model error on OpenAI's end, and not anything simpleaichat is doing. (which may be more annoying to fix with the stream interface)

Running the line of code again should work (eventually) but I may need to add a more helpful error message.

For that interface, it might be OK to implement retry logic and see how that goes.

minimaxir avatar Jun 19 '23 21:06 minimaxir

Instead of crashing - maybe display the error with the problomatic chunk?

I.E

                        try:
                            chunk_dict = orjson.loads(chunk)
                            delta = chunk_dict["choices"][0]["delta"].get("content")
                            if delta:
                                content.append(delta)
                                yield {"delta": delta, "response": "".join(content)}
                        except Exception as e:
                            print(e, chunk)

AsafMah avatar Jun 20 '23 10:06 AsafMah

I'm experiencing the same thing but upon retrying it has yet to succeed, EVER.

import orjson
from simpleaichat import AIChat

while True:
    try:
        AIChat(api_key="sk-...")
    except orjson.JSONDecodeError:
        print("trying again...")

deydist avatar Jun 20 '23 20:06 deydist

Had the same issue and now it works after I've setup a payment method for the API usage and regenerated an API key on openai

matthieudesprez avatar Jun 20 '23 21:06 matthieudesprez

Had the same issue and now it works after I've setup a payment method for the API usage and regenerated an API key on openai

Makes sense your key needs to be paid for I guess!! Thanks for the reply.

deydist avatar Jun 21 '23 13:06 deydist

Hi, I'm actually getting the same error. Can anyone please tell me how to solve this one? ChatGPT: Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/Users/faziya/simpleaichat/simpleaichat/simpleaichat.py", line 58, in __init__ self.interactive_console(character=character, prime=prime) File "/Users/faziya/simpleaichat/simpleaichat/simpleaichat.py", line 203, in interactive_console for chunk in sess.stream("Hello!", self.client): File "/Users/faziya/simpleaichat/simpleaichat/chatgpt.py", line 161, in stream chunk_dict = orjson.loads(chunk) orjson.JSONDecodeError: Input is a zero-length, empty document: line 1 column 1 (char 0)

faziyasultana avatar Jan 18 '24 15:01 faziyasultana

Had the same issue and now it works after I've setup a payment method for the API usage and regenerated an API key on openai

Hi, I'm actually getting the same error. Can anyone please tell me how to solve this one? ChatGPT: Traceback (most recent call last): File "", line 1, in File "/Users/faziya/simpleaichat/simpleaichat/simpleaichat.py", line 58, in init self.interactive_console(character=character, prime=prime) File "/Users/faziya/simpleaichat/simpleaichat/simpleaichat.py", line 203, in interactive_console for chunk in sess.stream("Hello!", self.client): File "/Users/faziya/simpleaichat/simpleaichat/chatgpt.py", line 161, in stream chunk_dict = orjson.loads(chunk) orjson.JSONDecodeError: Input is a zero-length, empty document: line 1 column 1 (char 0)

faziyasultana avatar Jan 20 '24 10:01 faziyasultana

I tried to use simpleaichat but received error from the title. I installed simpleaichat in new virtual env and ran it in Python prompt.

Full traceback:

>>> AIChat(api_key="sk-***")
ChatGPT: Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "***/venv/lib/python3.9/site-packages/simpleaichat/simpleaichat.py", line 64, in __init__
    self.interactive_console(character=character, prime=prime)
  File "***/venv/lib/python3.9/site-packages/simpleaichat/simpleaichat.py", line 207, in interactive_console
    for chunk in sess.stream("Hello!", self.client):
  File "***/venv/lib/python3.9/site-packages/simpleaichat/chatgpt.py", line 147, in stream
    chunk_dict = orjson.loads(chunk)
orjson.JSONDecodeError: Input is a zero-length, empty document: line 1 column 1 (char 0

It happens also if I give it any argument like "Ronald McDonald" or similar.

Environment: macOS Ventura 13.0.1 Python 3.9 Api key for ChatGPT Plus.

Hi, I'm actually getting the same error. Can anyone please tell me how to solve this one? ChatGPT: Traceback (most recent call last): File "", line 1, in File "/Users/faziya/simpleaichat/simpleaichat/simpleaichat.py", line 58, in init self.interactive_console(character=character, prime=prime) File "/Users/faziya/simpleaichat/simpleaichat/simpleaichat.py", line 203, in interactive_console for chunk in sess.stream("Hello!", self.client): File "/Users/faziya/simpleaichat/simpleaichat/chatgpt.py", line 161, in stream chunk_dict = orjson.loads(chunk) orjson.JSONDecodeError: Input is a zero-length, empty document: line 1 column 1 (char 0)

faziyasultana avatar Jan 20 '24 10:01 faziyasultana