Skip to content
This repository has been archived by the owner on Aug 10, 2023. It is now read-only.

Commit

Permalink
try fix #1431
Browse files Browse the repository at this point in the history
  • Loading branch information
Antonio committed Jun 20, 2023
1 parent 860e540 commit 190914d
Showing 1 changed file with 31 additions and 21 deletions.
52 changes: 31 additions & 21 deletions src/revChatGPT/V1.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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(
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 190914d

Please sign in to comment.