Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,75 +1,37 @@
|
|
1 |
-
import os
|
2 |
-
import logging
|
3 |
import requests
|
4 |
-
|
5 |
-
from urllib3.poolmanager import PoolManager
|
6 |
-
from urllib3.util.retry import Retry
|
7 |
-
import ssl
|
8 |
|
9 |
-
|
10 |
-
|
11 |
-
format="%(asctime)s [%(levelname)s] %(message)s",
|
12 |
-
)
|
13 |
-
|
14 |
-
class SSLAdapter(HTTPAdapter):
|
15 |
-
def init_poolmanager(self, *args, **kwargs):
|
16 |
-
context = ssl.create_default_context()
|
17 |
-
context.minimum_version = ssl.TLSVersion.TLSv1_3
|
18 |
-
context.set_ciphers("DEFAULT:@SECLEVEL=1")
|
19 |
-
kwargs["ssl_context"] = context
|
20 |
-
return super().init_poolmanager(*args, **kwargs)
|
21 |
-
|
22 |
-
def create_session():
|
23 |
-
session = requests.Session()
|
24 |
-
session.mount("https://", SSLAdapter())
|
25 |
-
retries = Retry(
|
26 |
-
total=3,
|
27 |
-
backoff_factor=1,
|
28 |
-
status_forcelist=[429, 500, 502, 503, 504],
|
29 |
-
)
|
30 |
-
session.mount("https://", HTTPAdapter(max_retries=retries))
|
31 |
-
return session
|
32 |
-
|
33 |
-
def signup_user():
|
34 |
-
url = "https://api.puter.com/signup"
|
35 |
headers = {
|
36 |
-
"
|
|
|
37 |
"Accept": "*/*",
|
38 |
-
"
|
39 |
-
"Origin": "https://puter.com",
|
40 |
-
"Referer": "https://puter.com/",
|
41 |
"Sec-Ch-Ua": '"Not:A-Brand";v="24", "Chromium";v="134"',
|
|
|
42 |
"Sec-Ch-Ua-Mobile": "?0",
|
43 |
-
"
|
|
|
|
|
44 |
"Accept-Language": "en-US,en;q=0.9",
|
45 |
-
"X-Requested-With": "XMLHttpRequest",
|
46 |
-
"Sec-Fetch-User": "?1", # إضافة رأس جديد
|
47 |
-
"Upgrade-Insecure-Requests": "1",
|
48 |
}
|
49 |
-
|
50 |
-
|
51 |
-
"
|
52 |
-
"
|
53 |
-
"
|
54 |
-
"
|
|
|
|
|
|
|
|
|
55 |
}
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
headers=headers,
|
61 |
-
json=data,
|
62 |
-
timeout=10,
|
63 |
-
verify=True,
|
64 |
-
# proxies={"https": "http://your_proxy:port"}, # إزالة التعليق إذا كنت تستخدم بروكسي
|
65 |
-
)
|
66 |
-
logging.info(f"Response: {response.status_code}")
|
67 |
-
logging.info(f"Response Body: {response.text}") # إظهار الرد الكامل
|
68 |
-
response.raise_for_status()
|
69 |
-
return response.json()
|
70 |
-
except Exception as e:
|
71 |
-
logging.error(f"Error: {e}")
|
72 |
-
return None
|
73 |
|
|
|
74 |
if __name__ == "__main__":
|
75 |
-
|
|
|
|
|
|
|
1 |
import requests
|
2 |
+
import json
|
|
|
|
|
|
|
3 |
|
4 |
+
def call_puter_api():
|
5 |
+
url = "https://api.puter.com/drivers/call"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
headers = {
|
7 |
+
"Authorization": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0IjoicyIsInYiOiIwLjAuMCIsInUiOiJtR3F6M3JWNlIyS3o1Y2M1WVV6SWp3PT0iLCJ1dSI6ImpvS2wycFFSVHpDV3FOTmRkQng5V3c9PSIsImlhdCI6MTc0MjkyOTE4OX0.djVas5YRJX1o99LdLMPF7XkNXgdefsYR3wyya2_2R00",
|
8 |
+
"Content-Type": "application/json;charset=UTF-8",
|
9 |
"Accept": "*/*",
|
10 |
+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36",
|
|
|
|
|
11 |
"Sec-Ch-Ua": '"Not:A-Brand";v="24", "Chromium";v="134"',
|
12 |
+
"Sec-Ch-Ua-Platform": "Windows",
|
13 |
"Sec-Ch-Ua-Mobile": "?0",
|
14 |
+
"Origin": "https://docs.puter.com",
|
15 |
+
"Referer": "https://docs.puter.com/",
|
16 |
+
"Accept-Encoding": "gzip, deflate, br",
|
17 |
"Accept-Language": "en-US,en;q=0.9",
|
|
|
|
|
|
|
18 |
}
|
19 |
+
|
20 |
+
payload = {
|
21 |
+
"interface": "puter-chat-completion",
|
22 |
+
"driver": "claude",
|
23 |
+
"method": "complete",
|
24 |
+
"args": {
|
25 |
+
"messages": [{"role": "user", "content": "Explain quantum computing in simple terms."}], # Hardcoded message
|
26 |
+
"model": "claude-3-7-sonnet-latest",
|
27 |
+
"stream": True,
|
28 |
+
},
|
29 |
}
|
30 |
+
|
31 |
+
with requests.post(url, headers=headers, json=payload, stream=True) as response:
|
32 |
+
print(response.text)
|
33 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
|
35 |
+
# Run the API call
|
36 |
if __name__ == "__main__":
|
37 |
+
call_puter_api()
|