XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet
公开
关注 0 Fork 0 Star 1
返回提交历史

XFEstudio/gpt4free

phind cloudflare fix

de1a201c
t.me/xtekky <98614666+xtekky@users.noreply.github.com>
提交于

代码差异

3 个文件 +58 -17
Modified README.md +3 -0
@@ -106,6 +106,9 @@ print(response.completion.choices[0].text)
106 106 ```python
107 107 import phind
108 108
109 # set cf_clearance cookie
110 phind.cf_clearance = 'xx.xx-1682166681-0-160'
111
109 112 prompt = 'who won the quatar world cup'
110 113
111 114 # help needed: not getting newlines from the stream, please submit a PR if you know how to fix this
Modified phind/__init__.py +52 -17
@@ -7,6 +7,8 @@ from re import findall
7 7
8 8 from curl_cffi.requests import post
9 9
10 cf_clearance = ''
11
10 12 class PhindResponse:
11 13
12 14 class Completion:
@@ -69,10 +71,19 @@ class Search:
69 71 }
70 72
71 73 headers = {
72 'authority' : 'www.phind.com',
73 'origin' : 'https://www.phind.com',
74 'referer' : 'https://www.phind.com/search',
75 'user-agent' : 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36',
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',
76 87 }
77 88
78 89 return post('https://www.phind.com/api/bing/search', headers = headers, json = {
@@ -117,14 +128,24 @@ class Completion:
117 128 }
118 129
119 130 headers = {
120 'authority' : 'www.phind.com',
121 'origin' : 'https://www.phind.com',
122 'referer' : f'https://www.phind.com/search?q={quote(prompt)}&c=&source=searchbox&init=true',
123 'user-agent' : 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36',
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',
124 145 }
125 146
126 147 completion = ''
127 response = post('https://www.phind.com/api/infer/answer', headers = headers, json = json_data, timeout=99999)
148 response = post('https://www.phind.com/api/infer/answer', headers = headers, json = json_data, timeout=99999, impersonate='chrome110')
128 149 for line in response.text.split('\r\n\r\n'):
129 150 completion += (line.replace('data: ', ''))
130 151
@@ -172,14 +193,28 @@ class StreamingCompletion:
172 193 }
173 194 }
174 195
175 stream_req = post('https://www.phind.com/api/infer/answer', json=json_data, timeout=99999,
176 content_callback = StreamingCompletion.handle_stream_response,
177 headers = {
178 'authority' : 'www.phind.com',
179 'origin' : 'https://www.phind.com',
180 'referer' : f'https://www.phind.com/search?q={quote(prompt)}&c=&source=searchbox&init=true',
181 'user-agent' : 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36',
182 })
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
183 218
184 219 StreamingCompletion.stream_completed = True
185 220
Modified testing/phind_test.py +3 -0
@@ -1,5 +1,8 @@
1 1 import phind
2 2
3 # set cf_clearance cookie
4 phind.cf_clearance = 'hWfIdYKgcnxnU5ayolWe9t7eEmAbULywS.qfHkm1T_A-1682166681-0-160'
5
3 6 prompt = 'hello world'
4 7
5 8 # normal completion