-
Notifications
You must be signed in to change notification settings - Fork 142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update server.py // Better waiting algo to wait for a reply for ChatGPT, installation script and improved documentation #11
base: main
Are you sure you want to change the base?
Conversation
👉 I have improved the waiting algo to wait for a reply for ChatGPT
Update server.py
Thanks for this project. |
Interesting, but it still fails waiting for it to end conversation. I'd suggest to check submit button svg child, since it is removed while chat is sending messages, and when it finishes, svg is restored. def get_submit_button():
"""Get the submit button"""
print ("Getting submit button")
QUERY = PAGE.query_selector("div[class*='PromptTextarea__TextareaWrapper']")
if QUERY is None:
return None
return QUERY.query_selector("button"
@APP.route("/chat", methods=["GET"])
def chat():
message = flask.request.args.get("q")
BUTTON = get_submit_button()
if BUTTON is not None:
if BUTTON.query_selector("svg") is None:
return "Please wait for previous question to finish its answer!"
print("Sending message: ", message)
send_message(message)
print("⏳ Waiting for response...")
# Submit button has SVG when iddle, and it is removed while waiting for answer completion
while True:
time.sleep(1)
if BUTTON.query_selector("svg") is None:
break;
# Wait until svg is restored, which means that chat has completed answering.
while True:
time.sleep(1)
print(" ... waiting svg ...")
if BUTTON.query_selector("svg"):
break
print("⏳ ✅ End waiting for response...")
response = get_last_message()
print("🤖 Response: ", response)
else:
response = "Update this script, since something changed in ChatGPT web UI."
return response |
This can be solved with:
def is_loading_response() -> bool:
"""See if the send button is diabled, if it does, we're not loading"""
return not PAGE.query_selector("button[class*='PromptTextarea__PositionSubmit']").is_enabled() See PR #14 for more details |
This no longer works as they made changes to their frontend lol def is_loading_response() -> bool:
# see if the send button svg exists
return not bool(PAGE.query_selector("svg[class*='w-4 h-4 rotate-90']")) |
No description provided.