ChatGPT icon indicating copy to clipboard operation
ChatGPT copied to clipboard

Not a JSON response

Open Zero6992 opened this issue 2 years ago • 11 comments

When my conversation becomes more and more, I often receive Not a JSON response

I need to reset the entire conversation reset_chat to receive the next response

Do you have any idea what could be causing this problem?

Zero6992 avatar Dec 08 '22 20:12 Zero6992

Please post your code when opening an issue, Including detailed steps to reproduce the problem

rawandahmad698 avatar Dec 08 '22 21:12 rawandahmad698

I'm having this error, and reset_chat doesn't help either. And for me, this error happens EVERY time I request something from ChatGPT. :/

ChrisNonyminus avatar Dec 08 '22 22:12 ChrisNonyminus

Nevermind, I figured out the problem: the authorization token was expired. Using a new token fixed it!

ChrisNonyminus avatar Dec 08 '22 22:12 ChrisNonyminus

I think I know where the problem is, I put refresh_session in the wrong place

Zero6992 avatar Dec 08 '22 23:12 Zero6992

I think I know where the problem is, I put refresh_session in the wrong place

So where should I put refresh_session?

here is my code.

import sys
from config import config
from revChatGPT.revChatGPT import Chatbot

chatbot = Chatbot(config, conversation_id=None)

def resetChat():
    chatbot.reset_chat() # Forgets conversation

def getresult(prompt):
    chatbot.refresh_session() # Uses the session_token to get a new bearer token
    resp = chatbot.get_chat_response(prompt, output="text") # Sends a request to the API and returns the response by OpenAI
    print("getresult", resp['message'])
    return resp['message']

if __name__ == '__main__':
    getresult(sys.argv[1])

Is refresh_session misplaced?

yym68686 avatar Dec 09 '22 08:12 yym68686

It is in the right place

acheong08 avatar Dec 09 '22 08:12 acheong08

That's correct

Zero6992 avatar Dec 09 '22 09:12 Zero6992

I am experiencing the same issue again, and this is the code that I use for handling the returned message

from asyncChatGPT.asyncChatGPT import Chatbot
.
.
async def handle_response(prompt) -> str:
    chatbot.refresh_session()
    response = await chatbot.get_chat_response(prompt, output="text")
    responseMessage = response['message']

    return responseMessage

As the number of messages in the conversation increases, around 10 to 20, it will keep throwing errors Not a JSON response until I reset the chatbot

Zero6992 avatar Dec 09 '22 10:12 Zero6992

It seems the API limits the max length of the conversation. That is an OpenAI issue

acheong08 avatar Dec 09 '22 11:12 acheong08

Need more investigation

acheong08 avatar Dec 09 '22 11:12 acheong08

Gonna add better error handlers to show the actual response if not JSON

acheong08 avatar Dec 09 '22 11:12 acheong08

I think better error handlers have been added

acheong08 avatar Dec 11 '22 03:12 acheong08