返回提交历史
Added
.dockerignore
+1
-0
Added
.vscode/launch.json
+16
-0
Added
audio.m4a
+0
-0
Added
audio.wav
+0
-0
Added
deepseek4free
+1
-0
Added
demo.docx
+0
-0
Added
downloads.json
+1
-0
Added
g4f.dev
+1
-0
Added
g4f/Provider/needs_auth/Sora.py
+0
-0
Modified
g4f/image/__init__.py
+3
-2
Modified
g4f/tools/media.py
+3
-0
Added
markitdown
+1
-0
Added
new.py
+158
-0
XFEstudio/gpt4free
Fix image orintation
0b86b09a
代码差异
13 个文件
+185
-2
@@ -0,0 +1 @@
1
projects/
@@ -0,0 +1,16 @@
1
{
2
// Use IntelliSense to learn about possible attributes.
3
// Hover to view descriptions of existing attributes.
4
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5
"version": "0.2.0",
6
"configurations": [
7
8
9
{
10
"name": "Python Debugger: Module",
11
"type": "debugpy",
12
"request": "launch",
13
"module": "etc.unittest"
14
}
15
]
16
}
二进制文件已变更,无法进行逐行预览。
二进制文件已变更,无法进行逐行预览。
@@ -0,0 +1 @@
1
Subproject commit c205cdfd240b87679111f62299cd4391566ca0db
二进制文件已变更,无法进行逐行预览。
@@ -0,0 +1 @@
1
[{"urls": ["https://github.com/xtekky/gpt4free/compare/0.4.5.5...main"], "max_depth": -1}]
@@ -0,0 +1 @@
1
Subproject commit 54add9f17c866cbf672b73ef30dbab2a5feeb6e5
此文件没有可显示的逐行差异。
@@ -246,8 +246,9 @@ def process_image(image: Image, new_width: int = 800, new_height: int = 800, sav
246
246
if orientation:
247
247
debug.log(f"Image orientation: {orientation}")
248
248
if orientation == 6:
249
image = image.transpose(ROTATE_90)
250
# Resize image
249
image = image.transpose(ROTATE_270)
250
elif orientation == 3:
251
image = image.transpose(ROTATE_180)
251
252
image.thumbnail((new_width, new_height))
252
253
# Remove transparency
253
254
if image.mode == "RGBA":
@@ -88,6 +88,9 @@ def render_messages(messages: Messages, media: list = None) -> Iterator:
88
88
"content": [part for part in parts if part]
89
89
}
90
90
else:
91
print(f"Rendering message: {media}")
92
for media_data, filename in media:
93
print(is_valid_media(media_data, filename))
91
94
if media is not None and idx == len(messages) - 1:
92
95
yield {
93
96
**message,
@@ -0,0 +1 @@
1
Subproject commit c856a6c2c1bb2d7b2b514280d1c3c39cf6105350
@@ -0,0 +1,158 @@
1
from g4f.client import Client
2
from g4f.Provider import PuterJS
3
4
client = Client(
5
provider=PuterJS,
6
api_key="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0IjoiYXUiLCJ2IjoiMC4wLjAiLCJ1dSI6InR2ZGJwZWZSVCtTOWJKeTZLbCszVGc9PSIsImF1Ijoib0dWODVGQjJXaENUUTNqVkwwL3FoUT09IiwicyI6IkNJSVpnT1NHajN4QW50L1lYVFg1aGc9PSIsImlhdCI6MTc0OTgyMTUyNn0.mQu8q21JwYRrzCshh9ytgx24VzDQVTNHabzDJJyB2Ws",
7
)
8
9
response = client.chat.completions.create(
10
model="gpt-4o",
11
messages=[
12
{"role": "system", "content": "You are a helpful assistant."},
13
{"role": "user", "content": "What is the capital of France?"},
14
],
15
max_tokens=50,
16
)
17
print(response.choices[0].message.content)
18
exit()
19
20
21
22
import base64
23
import os
24
from ecdsa import SigningKey, SECP256k1
25
import hashlib
26
import requests
27
import uuid
28
29
30
# -------- Create Anonymous User --------
31
def create_anon_user():
32
while True:
33
private_key_bytes = os.urandom(32)
34
try:
35
sk = SigningKey.from_string(private_key_bytes, curve=SECP256k1)
36
break
37
except Exception:
38
continue # Try again until valid
39
40
private_key_b64 = base64.b64encode(private_key_bytes).decode('utf-8')
41
public_key_bytes = sk.verifying_key.to_string()
42
43
# Fake server call to get user ID
44
return {
45
"privateKey": private_key_b64,
46
"anonUserId": str(uuid.uuid4())
47
}
48
49
50
# -------- Create Challenge Signature --------
51
def create_challenge(user_data):
52
challenge = os.urandom(32) # Simulated challenge
53
challenge_hash = hashlib.sha256(challenge).digest()
54
55
private_key_bytes = base64.b64decode(user_data["privateKey"])
56
sk = SigningKey.from_string(private_key_bytes, curve=SECP256k1)
57
signature = sk.sign(challenge_hash)
58
59
return {
60
"challenge": base64.b64encode(challenge).decode('utf-8'),
61
"signature": base64.b64encode(signature).decode('utf-8'),
62
"anonUserId": user_data["anonUserId"]
63
}
64
65
66
# -------- Middleware Simulation --------
67
def middleware_hook(request):
68
request_id = base64.b64encode(os.urandom(8)).decode()
69
url_path = request["url"].split("?")[0]
70
71
try:
72
# Simulate the ef(e, t) call (fallback ID)
73
statsig_id = some_external_handler(url_path, request.get("method", "GET"))
74
except Exception as e:
75
statsig_id = base64.b64encode(f"e:{str(e)}".encode()).decode()
76
77
# Add headers
78
headers = request.setdefault("headers", {})
79
headers["x-xai-request-id"] = request_id
80
headers["x-statsig-id"] = statsig_id
81
82
return request
83
84
85
# -------- Simulated external call --------
86
def some_external_handler(path, method):
87
# Simulate dynamic loading of a function
88
if "fail" in path:
89
raise ValueError("Simulated failure")
90
return f"handler-id-for-{path}"
91
92
import base64
93
import urllib.parse
94
95
def rc4_decrypt(base64_str, key):
96
# Step 1: Base64 decode
97
decoded_bytes = base64.b64decode(base64_str)
98
99
# Step 2: Percent-decode (as in JS's decodeURIComponent(escape()))
100
decoded_str = urllib.parse.unquote(''.join('%%%02x' % b for b in decoded_bytes))
101
102
# Step 3: RC4 Decryption
103
S = list(range(256))
104
j = 0
105
out = []
106
107
# KSA (Key Scheduling Algorithm)
108
for i in range(256):
109
j = (j + S[i] + ord(key[i % len(key)])) % 256
110
S[i], S[j] = S[j], S[i]
111
112
# PRGA (Pseudo-Random Generation Algorithm)
113
i = j = 0
114
for char in decoded_str:
115
i = (i + 1) % 256
116
j = (j + S[i]) % 256
117
S[i], S[j] = S[j], S[i]
118
out.append(chr(ord(char) ^ S[(S[i] + S[j]) % 256]))
119
120
return ''.join(out)
121
122
from Crypto.Cipher import ARC4
123
import base64
124
125
def rc4_decrypt(cipher_text_b64: str, key: str) -> str:
126
cipher_bytes = base64.b64decode(cipher_text_b64)
127
cipher = ARC4.new(key.encode())
128
decrypted = cipher.decrypt(cipher_bytes)
129
return decrypted.decode(errors="ignore")
130
131
def rc4_encrypt(plain_text: str, key: str) -> str:
132
cipher = ARC4.new(key.encode())
133
encrypted = cipher.encrypt(plain_text.encode())
134
return base64.b64encode(encrypted).decode()
135
136
137
138
print(rc4_decrypt("R0QM/BrwHl93JoU09oYYeJ63W3Lzgm2wzxLaXq3F61juBwCJ36jTeZpXYbMQ87tZOra9nETi7rVfJrF/BqeiBp4y/egBRA==", "https://grok.com/rest/app-chat/conversations/new/GET"))
139
140
141
# -------- Usage --------
142
if __name__ == "__main__":
143
# 1. Create user
144
user = create_anon_user()
145
print("Anon user created:", user)
146
147
# 2. Create challenge signature
148
challenge_data = create_challenge(user)
149
print("Challenge signed:", challenge_data)
150
151
# 3. Simulate middleware request
152
request = {
153
"url": "https://api.example.com/resource",
154
"method": "POST",
155
"headers": {}
156
}
157
modified_request = middleware_hook(request)
158
print("Modified request headers:", modified_request["headers"])