unofficial-chatgpt-api icon indicating copy to clipboard operation
unofficial-chatgpt-api copied to clipboard

Improve response time

Open fabiangruss opened this issue 2 years ago • 0 comments

Hi, thanks for the great repo! Currently, the python scripts waits 10 seconds before returning the response. This can lead to errors for example if the result takes longer.

You can take this code (or something similar) that looks for the loading indicator and immediately returns the result when the indicator disappears.

...    
send_message(message)

  # Check if an answer was received
    while True:
        # Check loading indicator
        loading = PAGE.query_selector_all(
            "div[class*='result-streaming']")
        if len(loading) == 0:
            response = get_last_message()
            break

print("Response: ", response)
...

Thanks for the great work!

fabiangruss avatar Dec 03 '22 22:12 fabiangruss