taranjeet / unofficial-chatgpt-api

This repo is unofficial ChatGPT api. It is based on Daniel Gross's WhatsApp GPT
https://embedchain.ai
MIT License
689 stars 141 forks source link

Improve response time #7

Open fabiangruss opened 1 year ago

fabiangruss commented 1 year ago

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!