summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--README.md3
-rw-r--r--phind/__init__.py69
-rw-r--r--testing/phind_test.py3
3 files changed, 58 insertions, 17 deletions
diff --git a/README.md b/README.md
index 24ff9608..00d78608 100644
--- a/README.md
+++ b/README.md
@@ -106,6 +106,9 @@ print(response.completion.choices[0].text)
```python
import phind
+# set cf_clearance cookie
+phind.cf_clearance = 'xx.xx-1682166681-0-160'
+
prompt = 'who won the quatar world cup'
# help needed: not getting newlines from the stream, please submit a PR if you know how to fix this
diff --git a/phind/__init__.py b/phind/__init__.py
index 69468703..8bae9f17 100644
--- a/phind/__init__.py
+++ b/phind/__init__.py
@@ -7,6 +7,8 @@ from re import findall
from curl_cffi.requests import post
+cf_clearance = ''
+
class PhindResponse:
class Completion:
@@ -69,10 +71,19 @@ class Search:
}
headers = {
- 'authority' : 'www.phind.com',
- 'origin' : 'https://www.phind.com',
- 'referer' : 'https://www.phind.com/search',
- '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',
+ 'authority': 'www.phind.com',
+ 'accept': '*/*',
+ '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',
+ 'cookie': f'cf_clearance={cf_clearance}',
+ 'origin': 'https://www.phind.com',
+ 'referer': 'https://www.phind.com/search?q=hi&c=&source=searchbox&init=true',
+ 'sec-ch-ua': '"Chromium";v="112", "Google Chrome";v="112", "Not:A-Brand";v="99"',
+ 'sec-ch-ua-mobile': '?0',
+ 'sec-ch-ua-platform': '"macOS"',
+ 'sec-fetch-dest': 'empty',
+ 'sec-fetch-mode': 'cors',
+ 'sec-fetch-site': 'same-origin',
+ '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',
}
return post('https://www.phind.com/api/bing/search', headers = headers, json = {
@@ -117,14 +128,24 @@ class Completion:
}
headers = {
- 'authority' : 'www.phind.com',
- 'origin' : 'https://www.phind.com',
- 'referer' : f'https://www.phind.com/search?q={quote(prompt)}&c=&source=searchbox&init=true',
- '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',
+ 'authority': 'www.phind.com',
+ 'accept': '*/*',
+ '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',
+ 'content-type': 'application/json',
+ 'cookie': f'cf_clearance={cf_clearance}',
+ 'origin': 'https://www.phind.com',
+ 'referer': 'https://www.phind.com/search?q=hi&c=&source=searchbox&init=true',
+ 'sec-ch-ua': '"Chromium";v="112", "Google Chrome";v="112", "Not:A-Brand";v="99"',
+ 'sec-ch-ua-mobile': '?0',
+ 'sec-ch-ua-platform': '"macOS"',
+ 'sec-fetch-dest': 'empty',
+ 'sec-fetch-mode': 'cors',
+ 'sec-fetch-site': 'same-origin',
+ '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',
}
completion = ''
- response = post('https://www.phind.com/api/infer/answer', headers = headers, json = json_data, timeout=99999)
+ response = post('https://www.phind.com/api/infer/answer', headers = headers, json = json_data, timeout=99999, impersonate='chrome110')
for line in response.text.split('\r\n\r\n'):
completion += (line.replace('data: ', ''))
@@ -172,14 +193,28 @@ class StreamingCompletion:
}
}
- stream_req = post('https://www.phind.com/api/infer/answer', json=json_data, timeout=99999,
- content_callback = StreamingCompletion.handle_stream_response,
- headers = {
- 'authority' : 'www.phind.com',
- 'origin' : 'https://www.phind.com',
- 'referer' : f'https://www.phind.com/search?q={quote(prompt)}&c=&source=searchbox&init=true',
- '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',
- })
+ print(cf_clearance)
+
+ headers = {
+ 'authority': 'www.phind.com',
+ 'accept': '*/*',
+ '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',
+ 'content-type': 'application/json',
+ 'cookie': f'cf_clearance={cf_clearance}',
+ 'origin': 'https://www.phind.com',
+ 'referer': 'https://www.phind.com/search?q=hi&c=&source=searchbox&init=true',
+ 'sec-ch-ua': '"Chromium";v="112", "Google Chrome";v="112", "Not:A-Brand";v="99"',
+ 'sec-ch-ua-mobile': '?0',
+ 'sec-ch-ua-platform': '"macOS"',
+ 'sec-fetch-dest': 'empty',
+ 'sec-fetch-mode': 'cors',
+ 'sec-fetch-site': 'same-origin',
+ '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',
+ }
+
+ response = post('https://www.phind.com/api/infer/answer',
+ headers = headers, json = json_data, timeout=99999, impersonate='chrome110', content_callback=StreamingCompletion.handle_stream_response)
+
StreamingCompletion.stream_completed = True
diff --git a/testing/phind_test.py b/testing/phind_test.py
index 6b78f02d..3e9217e1 100644
--- a/testing/phind_test.py
+++ b/testing/phind_test.py
@@ -1,5 +1,8 @@
import phind
+# set cf_clearance cookie
+phind.cf_clearance = 'hWfIdYKgcnxnU5ayolWe9t7eEmAbULywS.qfHkm1T_A-1682166681-0-160'
+
prompt = 'hello world'
# normal completion