summaryrefslogtreecommitdiffstats
path: root/g4f/Provider/openai/proofofwork.py
diff options
context:
space:
mode:
authorH Lohaus <hlohaus@users.noreply.github.com>2024-05-18 16:54:00 +0200
committerGitHub <noreply@github.com>2024-05-18 16:54:00 +0200
commitfcd36475e5767b1451a02bd164b07f7c54726745 (patch)
treea8c2b770c72d1ef64b401a63af492e4322ee4c47 /g4f/Provider/openai/proofofwork.py
parentMerge pull request #1970 from hlohaus/leech (diff)
parentFix OpenaiChat provider, improve proofofwork (diff)
downloadgpt4free-fcd36475e5767b1451a02bd164b07f7c54726745.tar
gpt4free-fcd36475e5767b1451a02bd164b07f7c54726745.tar.gz
gpt4free-fcd36475e5767b1451a02bd164b07f7c54726745.tar.bz2
gpt4free-fcd36475e5767b1451a02bd164b07f7c54726745.tar.lz
gpt4free-fcd36475e5767b1451a02bd164b07f7c54726745.tar.xz
gpt4free-fcd36475e5767b1451a02bd164b07f7c54726745.tar.zst
gpt4free-fcd36475e5767b1451a02bd164b07f7c54726745.zip
Diffstat (limited to '')
-rw-r--r--g4f/Provider/openai/proofofwork.py29
1 files changed, 9 insertions, 20 deletions
diff --git a/g4f/Provider/openai/proofofwork.py b/g4f/Provider/openai/proofofwork.py
index cbce153f..baf8a0ea 100644
--- a/g4f/Provider/openai/proofofwork.py
+++ b/g4f/Provider/openai/proofofwork.py
@@ -4,22 +4,18 @@ import json
import base64
from datetime import datetime, timezone
-proof_token_cache: dict = {}
-def generate_proof_token(required: bool, seed: str = None, difficulty: str = None, user_agent: str = None, proofTokens: list = None):
+def generate_proof_token(required: bool, seed: str = "", difficulty: str = "", user_agent: str = None, proofTokens: list = None):
if not required:
return
- if seed is not None and seed in proof_token_cache:
- return proof_token_cache[seed]
-
- # Get current UTC time
- now_utc = datetime.now(timezone.utc)
- parse_time = now_utc.strftime('%a, %d %b %Y %H:%M:%S GMT')
if proofTokens:
- config = random.choice(proofTokens)
+ config = proofTokens[-1]
else:
screen = random.choice([3008, 4010, 6000]) * random.choice([1, 2, 4])
+ # Get current UTC time
+ now_utc = datetime.now(timezone.utc)
+ parse_time = now_utc.strftime('%a, %d %b %Y %H:%M:%S GMT')
config = [
screen, parse_time,
None, 0, user_agent,
@@ -31,22 +27,15 @@ def generate_proof_token(required: bool, seed: str = None, difficulty: str = Non
random.choice(["alert", "ontransitionend", "onprogress"])
]
- config[1] = parse_time
- config[4] = user_agent
- config[7] = random.randint(101, 2100)
-
- diff_len = None if difficulty is None else len(difficulty)
+ diff_len = len(difficulty)
for i in range(100000):
config[3] = i
json_data = json.dumps(config)
base = base64.b64encode(json_data.encode()).decode()
- hash_value = hashlib.sha3_512((seed or "" + base).encode()).digest()
+ hash_value = hashlib.sha3_512((seed + base).encode()).digest()
- if difficulty is None or hash_value.hex()[:diff_len] <= difficulty:
- if seed is None:
- return "gAAAAAC" + base
- proof_token_cache[seed] = "gAAAAAB" + base
- return proof_token_cache[seed]
+ if hash_value.hex()[:diff_len] <= difficulty:
+ return "gAAAAAB" + base
fallback_base = base64.b64encode(f'"{seed}"'.encode()).decode()
return "gAAAAABwQ8Lk5FbGpA2NcR9dShT6gYjU7VxZ4D" + fallback_base