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

XFEstudio/gpt4free

phind, user_agent and cf_clearance param for cloudflare bypass

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

代码差异

3 个文件 +17 -7
Modified phind/README.md +1 -0
@@ -5,6 +5,7 @@ import phind
5 5
6 6 # set cf_clearance cookie
7 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
8 9
9 10 prompt = 'who won the quatar world cup'
10 11
Modified phind/__init__.py +14 -6
@@ -8,6 +8,7 @@ from re import findall
8 8 from curl_cffi.requests import post
9 9
10 10 cf_clearance = ''
11 user_agent = ''
11 12
12 13 class PhindResponse:
13 14
@@ -52,6 +53,9 @@ class PhindResponse:
52 53
53 54 class Search:
54 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
55 59 if not actualSearch:
56 60 return {
57 61 '_type': 'SearchResponse',
@@ -83,7 +87,7 @@ class Search:
83 87 'sec-fetch-dest': 'empty',
84 88 'sec-fetch-mode': 'cors',
85 89 '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',
90 'user-agent': user_agent
87 91 }
88 92
89 93 return post('https://www.phind.com/api/bing/search', headers = headers, json = {
@@ -102,6 +106,9 @@ class Completion:
102 106 codeContext: str = '',
103 107 language: str = 'en') -> PhindResponse:
104 108
109 if user_agent == '':
110 raise ValueError('user_agent must be set, refer to documentation')
111
105 112 if results is None:
106 113 results = Search.create(prompt, actualSearch = True)
107 114
@@ -141,7 +148,7 @@ class Completion:
141 148 'sec-fetch-dest': 'empty',
142 149 'sec-fetch-mode': 'cors',
143 150 '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',
151 'user-agent': user_agent
145 152 }
146 153
147 154 completion = ''
@@ -192,9 +199,7 @@ class StreamingCompletion:
192 199 'creative': creative
193 200 }
194 201 }
195
196 print(cf_clearance)
197
202
198 203 headers = {
199 204 'authority': 'www.phind.com',
200 205 'accept': '*/*',
@@ -209,7 +214,7 @@ class StreamingCompletion:
209 214 'sec-fetch-dest': 'empty',
210 215 'sec-fetch-mode': 'cors',
211 216 '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',
217 'user-agent': user_agent
213 218 }
214 219
215 220 response = post('https://www.phind.com/api/infer/answer',
@@ -228,6 +233,9 @@ class StreamingCompletion:
228 233 codeContext : str = '',
229 234 language : str = 'en'):
230 235
236 if user_agent == '':
237 raise ValueError('user_agent must be set, refer to documentation')
238
231 239 if results is None:
232 240 results = Search.create(prompt, actualSearch = True)
233 241
Renamed phind/phind_test.py +2 -1
@@ -1,7 +1,8 @@
1 1 import phind
2 2
3 3 # set cf_clearance cookie
4 phind.cf_clearance = 'hWfIdYKgcnxnU5ayolWe9t7eEmAbULywS.qfHkm1T_A-1682166681-0-160'
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'
5 6
6 7 prompt = 'hello world'
7 8