summaryrefslogtreecommitdiffstats
path: root/g4f/Provider/openai
diff options
context:
space:
mode:
authorH Lohaus <hlohaus@users.noreply.github.com>2024-04-28 22:47:28 +0200
committerGitHub <noreply@github.com>2024-04-28 22:47:28 +0200
commitc3e8113eb455266c02836da5dc5150be35e54ff0 (patch)
tree0bfc8aeccc7e6ab722bc433469ecbc14da321210 /g4f/Provider/openai
parentMerge pull request #1901 from hlohaus/arka (diff)
parentAdd proofofwork to OpenaiChat (diff)
downloadgpt4free-c3e8113eb455266c02836da5dc5150be35e54ff0.tar
gpt4free-c3e8113eb455266c02836da5dc5150be35e54ff0.tar.gz
gpt4free-c3e8113eb455266c02836da5dc5150be35e54ff0.tar.bz2
gpt4free-c3e8113eb455266c02836da5dc5150be35e54ff0.tar.lz
gpt4free-c3e8113eb455266c02836da5dc5150be35e54ff0.tar.xz
gpt4free-c3e8113eb455266c02836da5dc5150be35e54ff0.tar.zst
gpt4free-c3e8113eb455266c02836da5dc5150be35e54ff0.zip
Diffstat (limited to 'g4f/Provider/openai')
-rw-r--r--g4f/Provider/openai/proofofwork.py39
1 files changed, 39 insertions, 0 deletions
diff --git a/g4f/Provider/openai/proofofwork.py b/g4f/Provider/openai/proofofwork.py
new file mode 100644
index 00000000..e44ef6f7
--- /dev/null
+++ b/g4f/Provider/openai/proofofwork.py
@@ -0,0 +1,39 @@
+import random
+import hashlib
+import json
+import base64
+from datetime import datetime, timedelta, timezone
+
+def generate_proof_token(required: bool, seed: str, difficulty: str, user_agent: str):
+ if not required:
+ return
+
+ cores = [8, 12, 16, 24]
+ screens = [3000, 4000, 6000]
+
+ core = random.choice(cores)
+ screen = random.choice(screens)
+
+ # Get current UTC time
+ now_utc = datetime.now(timezone.utc)
+ # Convert UTC time to Eastern Time
+ now_et = now_utc.astimezone(timezone(timedelta(hours=-5)))
+
+ parse_time = now_et.strftime('%a, %d %b %Y %H:%M:%S GMT')
+
+ config = [core + screen, parse_time, 4294705152, 0, user_agent]
+
+ diff_len = len(difficulty) // 2
+
+ 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 + base).encode()).digest()
+
+ if hash_value.hex()[:diff_len] <= difficulty:
+ result = "gAAAAAB" + base
+ return result
+
+ fallback_base = base64.b64encode(f'"{seed}"'.encode()).decode()
+ return "gAAAAABwQ8Lk5FbGpA2NcR9dShT6gYjU7VxZ4D" + fallback_base