minimaxir / simpleaichat

Python package for easily interfacing with chat apps, with robust features and minimal code complexity.
MIT License
3.47k stars 229 forks source link

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

Open pcustic opened 1 year ago

pcustic commented 1 year ago

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.

minimaxir commented 1 year ago

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.

AsafMah commented 1 year ago

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)
deydist commented 1 year ago

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...")
matthieudesprez commented 1 year ago

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

deydist commented 1 year ago

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.

faziyasultana commented 8 months ago

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 commented 8 months ago

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 commented 8 months ago

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)