t.me/xtekky
commited on
Commit
·
de1a201
1
Parent(s):
c70a257
phind cloudflare fix
Browse files- README.md +3 -0
- phind/__init__.py +52 -17
- testing/phind_test.py +3 -0
README.md
CHANGED
@@ -106,6 +106,9 @@ print(response.completion.choices[0].text)
|
|
106 |
```python
|
107 |
import phind
|
108 |
|
|
|
|
|
|
|
109 |
prompt = 'who won the quatar world cup'
|
110 |
|
111 |
# help needed: not getting newlines from the stream, please submit a PR if you know how to fix this
|
|
|
106 |
```python
|
107 |
import phind
|
108 |
|
109 |
+
# set cf_clearance cookie
|
110 |
+
phind.cf_clearance = 'xx.xx-1682166681-0-160'
|
111 |
+
|
112 |
prompt = 'who won the quatar world cup'
|
113 |
|
114 |
# help needed: not getting newlines from the stream, please submit a PR if you know how to fix this
|
phind/__init__.py
CHANGED
@@ -7,6 +7,8 @@ from re import findall
|
|
7 |
|
8 |
from curl_cffi.requests import post
|
9 |
|
|
|
|
|
10 |
class PhindResponse:
|
11 |
|
12 |
class Completion:
|
@@ -69,10 +71,19 @@ class Search:
|
|
69 |
}
|
70 |
|
71 |
headers = {
|
72 |
-
'authority'
|
73 |
-
'
|
74 |
-
'
|
75 |
-
'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
76 |
}
|
77 |
|
78 |
return post('https://www.phind.com/api/bing/search', headers = headers, json = {
|
@@ -117,14 +128,24 @@ class Completion:
|
|
117 |
}
|
118 |
|
119 |
headers = {
|
120 |
-
'authority'
|
121 |
-
'
|
122 |
-
'
|
123 |
-
'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
124 |
}
|
125 |
|
126 |
completion = ''
|
127 |
-
response = post('https://www.phind.com/api/infer/answer', headers = headers, json = json_data, timeout=99999)
|
128 |
for line in response.text.split('\r\n\r\n'):
|
129 |
completion += (line.replace('data: ', ''))
|
130 |
|
@@ -172,14 +193,28 @@ class StreamingCompletion:
|
|
172 |
}
|
173 |
}
|
174 |
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
183 |
|
184 |
StreamingCompletion.stream_completed = True
|
185 |
|
|
|
7 |
|
8 |
from curl_cffi.requests import post
|
9 |
|
10 |
+
cf_clearance = ''
|
11 |
+
|
12 |
class PhindResponse:
|
13 |
|
14 |
class Completion:
|
|
|
71 |
}
|
72 |
|
73 |
headers = {
|
74 |
+
'authority': 'www.phind.com',
|
75 |
+
'accept': '*/*',
|
76 |
+
'accept-language': 'en,fr-FR;q=0.9,fr;q=0.8,es-ES;q=0.7,es;q=0.6,en-US;q=0.5,am;q=0.4,de;q=0.3',
|
77 |
+
'cookie': f'cf_clearance={cf_clearance}',
|
78 |
+
'origin': 'https://www.phind.com',
|
79 |
+
'referer': 'https://www.phind.com/search?q=hi&c=&source=searchbox&init=true',
|
80 |
+
'sec-ch-ua': '"Chromium";v="112", "Google Chrome";v="112", "Not:A-Brand";v="99"',
|
81 |
+
'sec-ch-ua-mobile': '?0',
|
82 |
+
'sec-ch-ua-platform': '"macOS"',
|
83 |
+
'sec-fetch-dest': 'empty',
|
84 |
+
'sec-fetch-mode': 'cors',
|
85 |
+
'sec-fetch-site': 'same-origin',
|
86 |
+
'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',
|
87 |
}
|
88 |
|
89 |
return post('https://www.phind.com/api/bing/search', headers = headers, json = {
|
|
|
128 |
}
|
129 |
|
130 |
headers = {
|
131 |
+
'authority': 'www.phind.com',
|
132 |
+
'accept': '*/*',
|
133 |
+
'accept-language': 'en,fr-FR;q=0.9,fr;q=0.8,es-ES;q=0.7,es;q=0.6,en-US;q=0.5,am;q=0.4,de;q=0.3',
|
134 |
+
'content-type': 'application/json',
|
135 |
+
'cookie': f'cf_clearance={cf_clearance}',
|
136 |
+
'origin': 'https://www.phind.com',
|
137 |
+
'referer': 'https://www.phind.com/search?q=hi&c=&source=searchbox&init=true',
|
138 |
+
'sec-ch-ua': '"Chromium";v="112", "Google Chrome";v="112", "Not:A-Brand";v="99"',
|
139 |
+
'sec-ch-ua-mobile': '?0',
|
140 |
+
'sec-ch-ua-platform': '"macOS"',
|
141 |
+
'sec-fetch-dest': 'empty',
|
142 |
+
'sec-fetch-mode': 'cors',
|
143 |
+
'sec-fetch-site': 'same-origin',
|
144 |
+
'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',
|
145 |
}
|
146 |
|
147 |
completion = ''
|
148 |
+
response = post('https://www.phind.com/api/infer/answer', headers = headers, json = json_data, timeout=99999, impersonate='chrome110')
|
149 |
for line in response.text.split('\r\n\r\n'):
|
150 |
completion += (line.replace('data: ', ''))
|
151 |
|
|
|
193 |
}
|
194 |
}
|
195 |
|
196 |
+
print(cf_clearance)
|
197 |
+
|
198 |
+
headers = {
|
199 |
+
'authority': 'www.phind.com',
|
200 |
+
'accept': '*/*',
|
201 |
+
'accept-language': 'en,fr-FR;q=0.9,fr;q=0.8,es-ES;q=0.7,es;q=0.6,en-US;q=0.5,am;q=0.4,de;q=0.3',
|
202 |
+
'content-type': 'application/json',
|
203 |
+
'cookie': f'cf_clearance={cf_clearance}',
|
204 |
+
'origin': 'https://www.phind.com',
|
205 |
+
'referer': 'https://www.phind.com/search?q=hi&c=&source=searchbox&init=true',
|
206 |
+
'sec-ch-ua': '"Chromium";v="112", "Google Chrome";v="112", "Not:A-Brand";v="99"',
|
207 |
+
'sec-ch-ua-mobile': '?0',
|
208 |
+
'sec-ch-ua-platform': '"macOS"',
|
209 |
+
'sec-fetch-dest': 'empty',
|
210 |
+
'sec-fetch-mode': 'cors',
|
211 |
+
'sec-fetch-site': 'same-origin',
|
212 |
+
'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',
|
213 |
+
}
|
214 |
+
|
215 |
+
response = post('https://www.phind.com/api/infer/answer',
|
216 |
+
headers = headers, json = json_data, timeout=99999, impersonate='chrome110', content_callback=StreamingCompletion.handle_stream_response)
|
217 |
+
|
218 |
|
219 |
StreamingCompletion.stream_completed = True
|
220 |
|
testing/phind_test.py
CHANGED
@@ -1,5 +1,8 @@
|
|
1 |
import phind
|
2 |
|
|
|
|
|
|
|
3 |
prompt = 'hello world'
|
4 |
|
5 |
# normal completion
|
|
|
1 |
import phind
|
2 |
|
3 |
+
# set cf_clearance cookie
|
4 |
+
phind.cf_clearance = 'hWfIdYKgcnxnU5ayolWe9t7eEmAbULywS.qfHkm1T_A-1682166681-0-160'
|
5 |
+
|
6 |
prompt = 'hello world'
|
7 |
|
8 |
# normal completion
|