t.me/xtekky
commited on
Commit
·
20af89c
1
Parent(s):
99d36a7
phind, user_agent and cf_clearance param for cloudflare bypass
Browse files- phind/README.md +1 -0
- phind/__init__.py +14 -6
- {testing → phind}/phind_test.py +2 -1
phind/README.md
CHANGED
@@ -5,6 +5,7 @@ import phind
|
|
5 |
|
6 |
# set cf_clearance cookie
|
7 |
phind.cf_clearance = 'xx.xx-1682166681-0-160'
|
|
|
8 |
|
9 |
prompt = 'who won the quatar world cup'
|
10 |
|
|
|
5 |
|
6 |
# set cf_clearance cookie
|
7 |
phind.cf_clearance = 'xx.xx-1682166681-0-160'
|
8 |
+
phind.user_agent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36' # same as the one from browser you got cf_clearance from
|
9 |
|
10 |
prompt = 'who won the quatar world cup'
|
11 |
|
phind/__init__.py
CHANGED
@@ -8,6 +8,7 @@ from re import findall
|
|
8 |
from curl_cffi.requests import post
|
9 |
|
10 |
cf_clearance = ''
|
|
|
11 |
|
12 |
class PhindResponse:
|
13 |
|
@@ -52,6 +53,9 @@ class PhindResponse:
|
|
52 |
|
53 |
class Search:
|
54 |
def create(prompt: str, actualSearch: bool = True, language: str = 'en') -> dict: # None = no search
|
|
|
|
|
|
|
55 |
if not actualSearch:
|
56 |
return {
|
57 |
'_type': 'SearchResponse',
|
@@ -83,7 +87,7 @@ class Search:
|
|
83 |
'sec-fetch-dest': 'empty',
|
84 |
'sec-fetch-mode': 'cors',
|
85 |
'sec-fetch-site': 'same-origin',
|
86 |
-
'user-agent':
|
87 |
}
|
88 |
|
89 |
return post('https://www.phind.com/api/bing/search', headers = headers, json = {
|
@@ -102,6 +106,9 @@ class Completion:
|
|
102 |
codeContext: str = '',
|
103 |
language: str = 'en') -> PhindResponse:
|
104 |
|
|
|
|
|
|
|
105 |
if results is None:
|
106 |
results = Search.create(prompt, actualSearch = True)
|
107 |
|
@@ -141,7 +148,7 @@ class Completion:
|
|
141 |
'sec-fetch-dest': 'empty',
|
142 |
'sec-fetch-mode': 'cors',
|
143 |
'sec-fetch-site': 'same-origin',
|
144 |
-
'user-agent':
|
145 |
}
|
146 |
|
147 |
completion = ''
|
@@ -192,9 +199,7 @@ class StreamingCompletion:
|
|
192 |
'creative': creative
|
193 |
}
|
194 |
}
|
195 |
-
|
196 |
-
print(cf_clearance)
|
197 |
-
|
198 |
headers = {
|
199 |
'authority': 'www.phind.com',
|
200 |
'accept': '*/*',
|
@@ -209,7 +214,7 @@ class StreamingCompletion:
|
|
209 |
'sec-fetch-dest': 'empty',
|
210 |
'sec-fetch-mode': 'cors',
|
211 |
'sec-fetch-site': 'same-origin',
|
212 |
-
'user-agent':
|
213 |
}
|
214 |
|
215 |
response = post('https://www.phind.com/api/infer/answer',
|
@@ -228,6 +233,9 @@ class StreamingCompletion:
|
|
228 |
codeContext : str = '',
|
229 |
language : str = 'en'):
|
230 |
|
|
|
|
|
|
|
231 |
if results is None:
|
232 |
results = Search.create(prompt, actualSearch = True)
|
233 |
|
|
|
8 |
from curl_cffi.requests import post
|
9 |
|
10 |
cf_clearance = ''
|
11 |
+
user_agent = ''
|
12 |
|
13 |
class PhindResponse:
|
14 |
|
|
|
53 |
|
54 |
class Search:
|
55 |
def create(prompt: str, actualSearch: bool = True, language: str = 'en') -> dict: # None = no search
|
56 |
+
if user_agent == '':
|
57 |
+
raise ValueError('user_agent must be set, refer to documentation')
|
58 |
+
|
59 |
if not actualSearch:
|
60 |
return {
|
61 |
'_type': 'SearchResponse',
|
|
|
87 |
'sec-fetch-dest': 'empty',
|
88 |
'sec-fetch-mode': 'cors',
|
89 |
'sec-fetch-site': 'same-origin',
|
90 |
+
'user-agent': user_agent
|
91 |
}
|
92 |
|
93 |
return post('https://www.phind.com/api/bing/search', headers = headers, json = {
|
|
|
106 |
codeContext: str = '',
|
107 |
language: str = 'en') -> PhindResponse:
|
108 |
|
109 |
+
if user_agent == '':
|
110 |
+
raise ValueError('user_agent must be set, refer to documentation')
|
111 |
+
|
112 |
if results is None:
|
113 |
results = Search.create(prompt, actualSearch = True)
|
114 |
|
|
|
148 |
'sec-fetch-dest': 'empty',
|
149 |
'sec-fetch-mode': 'cors',
|
150 |
'sec-fetch-site': 'same-origin',
|
151 |
+
'user-agent': user_agent
|
152 |
}
|
153 |
|
154 |
completion = ''
|
|
|
199 |
'creative': creative
|
200 |
}
|
201 |
}
|
202 |
+
|
|
|
|
|
203 |
headers = {
|
204 |
'authority': 'www.phind.com',
|
205 |
'accept': '*/*',
|
|
|
214 |
'sec-fetch-dest': 'empty',
|
215 |
'sec-fetch-mode': 'cors',
|
216 |
'sec-fetch-site': 'same-origin',
|
217 |
+
'user-agent': user_agent
|
218 |
}
|
219 |
|
220 |
response = post('https://www.phind.com/api/infer/answer',
|
|
|
233 |
codeContext : str = '',
|
234 |
language : str = 'en'):
|
235 |
|
236 |
+
if user_agent == '':
|
237 |
+
raise ValueError('user_agent must be set, refer to documentation')
|
238 |
+
|
239 |
if results is None:
|
240 |
results = Search.create(prompt, actualSearch = True)
|
241 |
|
{testing → phind}/phind_test.py
RENAMED
@@ -1,7 +1,8 @@
|
|
1 |
import phind
|
2 |
|
3 |
# set cf_clearance cookie
|
4 |
-
phind.cf_clearance = '
|
|
|
5 |
|
6 |
prompt = 'hello world'
|
7 |
|
|
|
1 |
import phind
|
2 |
|
3 |
# set cf_clearance cookie
|
4 |
+
phind.cf_clearance = 'heguhSRBB9d0sjLvGbQECS8b80m2BQ31xEmk9ChshKI-1682268995-0-160'
|
5 |
+
phind.user_agent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36'
|
6 |
|
7 |
prompt = 'hello world'
|
8 |
|