From 2609758ad9190a63226a660a1eac9121676804bb Mon Sep 17 00:00:00 2001 From: Grey_D Date: Mon, 17 Apr 2023 15:04:16 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20fix=20login=20issue?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- requirements.txt | 3 ++- tests/testLogin.py | 17 +++++++++++++++++ utils/chatgpt.py | 6 ++---- 3 files changed, 21 insertions(+), 5 deletions(-) create mode 100644 tests/testLogin.py diff --git a/requirements.txt b/requirements.txt index 0007f8d..937b561 100644 --- a/requirements.txt +++ b/requirements.txt @@ -9,4 +9,5 @@ beautifulsoup4~=4.11.2 colorama rich prompt-toolkit -google \ No newline at end of file +google +pytest \ No newline at end of file diff --git a/tests/testLogin.py b/tests/testLogin.py new file mode 100644 index 0000000..df63dcc --- /dev/null +++ b/tests/testLogin.py @@ -0,0 +1,17 @@ +import unittest +from http.cookies import SimpleCookie +from config.chatgpt_config import ChatGPTConfig +from utils.chatgpt import ChatGPT + + +class TestLogin(unittest.TestCase): + chatgpt_config = ChatGPTConfig() + chatgpt = ChatGPT(chatgpt_config) + text, conversation_id = chatgpt.send_new_message( + "I am a new tester for RESTful APIs." + ) + assert text is not None + + +if __name__ == "__main__": + unittest.main() diff --git a/utils/chatgpt.py b/utils/chatgpt.py index df02dec..496ca33 100644 --- a/utils/chatgpt.py +++ b/utils/chatgpt.py @@ -68,8 +68,7 @@ class ChatGPT: self.conversation_dict: Dict[str, Conversation] = {} self.headers = dict( { - # "cookie": f"cf_clearance={self.cf_clearance}; _puid={self._puid}; __cf_bm=Nl7zy2rM7a8Ix1MB64EyiG5vePkLZ0HX2RtJuj1SYT4-1681638176-0-AUS+5CeavTt8Xs/aw07CxlVVfvtjjfcLCxru0byb1OdTmb5UpP6kbVhesib0j8vJblhaO19VTr7wVEtr46iiA7D+4zVNYD0b4Lh6gZ5wBXlSmf0lrOl/vDhtCn4WOiY92Uu2+6JqWAk6gtHYfSx+waQqzaKIPQnQMNti2IrpyZZd; __Secure-next-auth.callback-url=https%3A%2F%2Fchat.openai.com%2F; __Host-next-auth.csrf-token=0b7e3bb24cc2f1d21030a03269484f928527e4aab16c9b4d344529ee46ca9fe8%7C2a6e7e38eaac7ca8cbcae40912bade72150d8aa18317e3db74f49b125957613a;_cfuvid=FpwoyzyYPrG0a0NqtkhvayIWPZmzOQc4B9g3pEunvo8-1681470057686-0-604800000" - # f"__Secure-next-auth.session-token={self.session_token}", + "cookie": f"cf_clearance={self.cf_clearance}; _puid={self._puid}; __Secure-next-auth.session-token={self.session_token}", "cookie": self.config.cookie, "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36", "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7" @@ -88,9 +87,7 @@ class ChatGPT: def get_latest_message_id(self, conversation_id): # Get continuous conversation message id url = f"https://chat.openai.com/backend-api/conversation/{conversation_id}" - print(self.headers) r = requests.get(url, headers=self.headers, proxies=self.proxies) - return r.json()["current_node"] def _parse_message_raw_output(self, response: requests.Response): @@ -266,6 +263,7 @@ if __name__ == "__main__": text, conversation_id = chatgpt.send_new_message( "I am a new tester for RESTful APIs." ) + print(text, conversation_id) result = chatgpt.send_message( "generate: {'post': {'tags': ['pet'], 'summary': 'uploads an image', 'description': '', 'operationId': 'uploadFile', 'consumes': ['multipart/form-data'], 'produces': ['application/json'], 'parameters': [{'name': 'petId', 'in': 'path', 'description': 'ID of pet to update', 'required': True, 'type': 'integer', 'format': 'int64'}, {'name': 'additionalMetadata', 'in': 'formData', 'description': 'Additional data to pass to server', 'required': False, 'type': 'string'}, {'name': 'file', 'in': 'formData', 'description': 'file to upload', 'required': False, 'type': 'file'}], 'responses': {'200': {'description': 'successful operation', 'schema': {'type': 'object', 'properties': {'code': {'type': 'integer', 'format': 'int32'}, 'type': {'type': 'string'}, 'message': {'type': 'string'}}}}}, 'security': [{'petstore_auth': ['write:pets', 'read:pets']}]}}", conversation_id,