From 190914d4bd9f3221687582adf753438bf094ba03 Mon Sep 17 00:00:00 2001 From: Antonio Date: Tue, 20 Jun 2023 13:06:54 +0800 Subject: [PATCH] try fix #1431 --- src/revChatGPT/V1.py | 52 ++++++++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 21 deletions(-) diff --git a/src/revChatGPT/V1.py b/src/revChatGPT/V1.py index 0d9a9bf925..37cc7945db 100644 --- a/src/revChatGPT/V1.py +++ b/src/revChatGPT/V1.py @@ -368,6 +368,18 @@ def login(self) -> None: self.set_access_token(auth.auth()) + def __arkose_token(self) -> str: + headers = { + "Accept": "application/json", + "Content-Type": "application/x-www-form-urlencoded", + "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36", + } + form_data = "public_key=35536E1E-65B4-4D96-9D97-6ADB7EFF8147&site=https%3A%2F%2Fchat.openai.com&userbrowser=Mozilla%2F5.0%20(X11%3B%20Linux%20x86_64)%20AppleWebKit%2F537.36%20(KHTML%2C%20like%20Gecko)%20Chrome%2F114.0.0.0%20Safari%2F537.36&capi_version=1.5.2&capi_mode=lightbox&style_theme=default&rnd=0.3649022041957759" + url = "https://tcr9i.chat.openai.com/fc/gt2/public_key/35536E1E-65B4-4D96-9D97-6ADB7EFF8147" + response = self.session.post(url, data=form_data, headers=headers) + self.__check_response(response) + return response.json()["token"] + @logger(is_timed=True) def __send_request( self, @@ -379,7 +391,10 @@ def __send_request( log.debug("Sending the payload") cid, pid = data["conversation_id"], data["parent_message_id"] - model, message = None, "" + message = "" + + if data.get("model", "").startswith("gpt-4"): + data["arkose_token"] = self.__arkose_token() self.conversation_id_prev_queue.append(cid) self.parent_id_prev_queue.append(pid) @@ -550,10 +565,6 @@ def post_messages( "model": model, "history_and_training_disabled": self.disable_history, } - if model.startswith("gpt-4"): - data[ - "arkose_token" - ] = f"{generate_random_hex()}|r=ap-southeast-1|meta=3|meta_width=300|metabgclr=transparent|metaiconclr=%23555555|guitextcolor=%23000000|pk=35536E1E-65B4-4D96-9D97-6ADB7EFF8147|at=40|sup=1|rid={random_int(1,99)}|ag=101|cdn_url=https%3A%2F%2Ftcr9i.chat.openai.com%2Fcdn%2Ffc|lurl=https%3A%2F%2Faudio-ap-southeast-1.arkoselabs.com|surl=https%3A%2F%2Ftcr9i.chat.openai.com|smurl=https%3A%2F%2Ftcr9i.chat.openai.com%2Fcdn%2Ffc%2Fassets%2Fstyle-manager" plugin_ids = self.config.get("plugin_ids", []) or plugin_ids if len(plugin_ids) > 0 and not conversation_id: data["plugin_ids"] = plugin_ids @@ -693,11 +704,6 @@ def continue_write( ), "history_and_training_disabled": self.disable_history, } - if model.startswith("gpt-4"): - data[ - "arkose_token" - ] = f"{generate_random_hex()}|r=ap-southeast-1|meta=3|meta_width=300|metabgclr=transparent|metaiconclr=%23555555|guitextcolor=%23000000|pk=35536E1E-65B4-4D96-9D97-6ADB7EFF8147|at=40|sup=1|rid={random_int(1,99)}|ag=101|cdn_url=https%3A%2F%2Ftcr9i.chat.openai.com%2Fcdn%2Ffc|lurl=https%3A%2F%2Faudio-ap-southeast-1.arkoselabs.com|surl=https%3A%2F%2Ftcr9i.chat.openai.com|smurl=https%3A%2F%2Ftcr9i.chat.openai.com%2Fcdn%2Ffc%2Fassets%2Fstyle-manager" - yield from self.__send_request( data, timeout=timeout, @@ -954,6 +960,18 @@ def __init__( # overwrite inherited normal session with async self.session = AsyncClient(headers=self.session.headers) + async def __arkose_token(self) -> str: + headers = { + "Accept": "application/json", + "Content-Type": "application/x-www-form-urlencoded", + "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36", + } + form_data = "public_key=35536E1E-65B4-4D96-9D97-6ADB7EFF8147&site=https%3A%2F%2Fchat.openai.com&userbrowser=Mozilla%2F5.0%20(X11%3B%20Linux%20x86_64)%20AppleWebKit%2F537.36%20(KHTML%2C%20like%20Gecko)%20Chrome%2F114.0.0.0%20Safari%2F537.36&capi_version=1.5.2&capi_mode=lightbox&style_theme=default&rnd=0.3649022041957759" + url = "https://tcr9i.chat.openai.com/fc/gt2/public_key/35536E1E-65B4-4D96-9D97-6ADB7EFF8147" + response = await self.session.post(url, data=form_data, headers=headers) + self.__check_response(response) + return response.json()["token"] + async def __send_request( self, data: dict, @@ -964,8 +982,9 @@ async def __send_request( log.debug("Sending the payload") cid, pid = data["conversation_id"], data["parent_message_id"] - model, message = None, "" - + message = "" + if data.get("model", "").startswith("gpt-4"): + data["arkose_token"] = await self.__arkose_token() self.conversation_id_prev_queue.append(cid) self.parent_id_prev_queue.append(pid) async with self.session.stream( @@ -1135,10 +1154,6 @@ async def post_messages( plugin_ids = self.config.get("plugin_ids", []) or plugin_ids if len(plugin_ids) > 0 and not conversation_id: data["plugin_ids"] = plugin_ids - if model.startswith("gpt-4"): - data[ - "arkose_token" - ] = f"{generate_random_hex()}|r=ap-southeast-1|meta=3|meta_width=300|metabgclr=transparent|metaiconclr=%23555555|guitextcolor=%23000000|pk=35536E1E-65B4-4D96-9D97-6ADB7EFF8147|at=40|sup=1|rid={random_int(1,99)}|ag=101|cdn_url=https%3A%2F%2Ftcr9i.chat.openai.com%2Fcdn%2Ffc|lurl=https%3A%2F%2Faudio-ap-southeast-1.arkoselabs.com|surl=https%3A%2F%2Ftcr9i.chat.openai.com|smurl=https%3A%2F%2Ftcr9i.chat.openai.com%2Fcdn%2Ffc%2Fassets%2Fstyle-manager" async for msg in self.__send_request( data, timeout=timeout, @@ -1264,11 +1279,6 @@ async def continue_write( ), "history_and_training_disabled": self.disable_history, } - if model.startswith("gpt-4"): - data[ - "arkose_token" - ] = f"{generate_random_hex()}|r=ap-southeast-1|meta=3|meta_width=300|metabgclr=transparent|metaiconclr=%23555555|guitextcolor=%23000000|pk=35536E1E-65B4-4D96-9D97-6ADB7EFF8147|at=40|sup=1|rid={random_int(1,99)}|ag=101|cdn_url=https%3A%2F%2Ftcr9i.chat.openai.com%2Fcdn%2Ffc|lurl=https%3A%2F%2Faudio-ap-southeast-1.arkoselabs.com|surl=https%3A%2F%2Ftcr9i.chat.openai.com|smurl=https%3A%2F%2Ftcr9i.chat.openai.com%2Fcdn%2Ffc%2Fassets%2Fstyle-manager" - async for msg in self.__send_request( data=data, auto_continue=auto_continue,