Skip to content
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

Enhance Program Performance and Conciseness #6

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 11 additions & 1 deletion chatgpt_automation/chatgpt_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import time
import undetected_chromedriver as uc
from selenium.webdriver.support import expected_conditions as EC

# from selenium import webdriver
from selenium.webdriver.common.by import By
Expand Down Expand Up @@ -132,7 +133,16 @@ def interact(self, question : str):
def reset_thread(self):
"""the conversation is refreshed"""
self.browser.find_element(By.XPATH, self.reset_xq).click()


def check_if_request_limit_exceeded(self):
elements = self.browser.find_elements(By.XPATH,'//div[@class="py-2 px-3 border text-gray-600 rounded-md text-sm dark:text-gray-100 border-red-500 bg-red-500/10"]')
Copy link
Owner

@ugorsahin ugorsahin May 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line can fail easily since the class definition is way too specific, there should be something else to identify the rate limiting

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry I can't find another solution. You're totally free to modify it or even remove it from the code if you want.

if len(elements) != 0:
raise RequestLimitExceeded('Too many requests in 1 hour. Try again later.')
def delete_current_conversation(self):
self.wait.until(EC.presence_of_element_located((By.XPATH, '(//button[@class="p-1 hover:text-white"])[2]'))).click()
self.wait.until(EC.presence_of_element_located((By.XPATH, '(//button[@class="p-1 hover:text-white"])[1]'))).click()
class RequestLimitExceeded(Exception):
pass

if __name__ == "__main__":
import argparse
Expand Down
6 changes: 6 additions & 0 deletions chatgpt_automation/talking_heads.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,9 @@ def continue_conversation(self, text_1: str= None, text_2: str= None):
self.head_responses[0].append(f_response)
self.head_responses[1].append(s_response)
return f_response, s_response

def delete_all_conversations(self):
for i in range(2):
self.switch_to_tab(i)
self.driver.delete_current_conversation()