t.me/xtekky commited on
Commit
6c64e45
1 Parent(s): 24ad26e

phind.com api (gpt-4 + internet) best answers

Browse files
Files changed (3) hide show
  1. README.md +22 -0
  2. phind/__init__.py +145 -0
  3. testing/phind_test.py +13 -0
README.md CHANGED
@@ -21,6 +21,7 @@ This repository provides reverse-engineered language models from various sources
21
  - [Sites with Authentication (Will Reverse Engineer but Need Account Access)](#sites-with-authentication)
22
  - [Usage Examples](#usage-examples)
23
  - [`quora (poe)`](#example-poe)
 
24
  - [`t3nsor`](#example-t3nsor)
25
  - [`ora`](#example-ora)
26
  - [`writesonic`](#example-writesonic)
@@ -36,6 +37,7 @@ This repository provides reverse-engineered language models from various sources
36
  | [writesonic.com](https://writesonic.com)|GPT-3.5 / Internet|
37
  | [t3nsor.com](https://t3nsor.com)|GPT-3.5|
38
  | [you.com](https://you.com)|GPT-3.5 / Internet / good search|
 
39
 
40
  ## Sites with Authentication <a name="sites-with-authentication"></a>
41
 
@@ -97,6 +99,26 @@ response = quora.Completion.create(model = 'gpt-4',
97
  print(response.completion.choices[0].text)
98
  ```
99
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
100
  ### Example: `t3nsor` (use like openai pypi package) <a name="example-t3nsor"></a>
101
 
102
  ```python
 
21
  - [Sites with Authentication (Will Reverse Engineer but Need Account Access)](#sites-with-authentication)
22
  - [Usage Examples](#usage-examples)
23
  - [`quora (poe)`](#example-poe)
24
+ - [`phind`](#example-phind)
25
  - [`t3nsor`](#example-t3nsor)
26
  - [`ora`](#example-ora)
27
  - [`writesonic`](#example-writesonic)
 
37
  | [writesonic.com](https://writesonic.com)|GPT-3.5 / Internet|
38
  | [t3nsor.com](https://t3nsor.com)|GPT-3.5|
39
  | [you.com](https://you.com)|GPT-3.5 / Internet / good search|
40
+ | [phind.com](https://phind.com)|GPT-4 / Internet / good search|
41
 
42
  ## Sites with Authentication <a name="sites-with-authentication"></a>
43
 
 
99
  print(response.completion.choices[0].text)
100
  ```
101
 
102
+ ### Example: `phind` (use like openai pypi package) <a name="example-phind"></a>
103
+
104
+ ```python
105
+ # HELP WANTED: tls_client does not accept stream and timeout gets hit with long responses
106
+
107
+ import phind
108
+
109
+ prompt = 'hello world'
110
+
111
+ result = phind.Completion.create(
112
+ model = 'gpt-4',
113
+ prompt = prompt,
114
+ results = phind.Search.create(prompt, actualSearch = False), # create search (set actualSearch to False to disable internet)
115
+ creative = False,
116
+ detailed = False,
117
+ codeContext = '') # up to 3000 chars of code
118
+
119
+ print(result.completion.choices[0].text)
120
+ ```
121
+
122
  ### Example: `t3nsor` (use like openai pypi package) <a name="example-t3nsor"></a>
123
 
124
  ```python
phind/__init__.py ADDED
@@ -0,0 +1,145 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from urllib.parse import quote
2
+ from tls_client import Session
3
+ from time import time
4
+ from datetime import datetime
5
+
6
+ client = Session(client_identifier='chrome110')
7
+ client.headers = {
8
+ 'authority': 'www.phind.com',
9
+ 'accept': '*/*',
10
+ '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',
11
+ 'content-type': 'application/json',
12
+ 'origin': 'https://www.phind.com',
13
+ 'referer': 'https://www.phind.com/search',
14
+ 'sec-ch-ua': '"Chromium";v="110", "Google Chrome";v="110", "Not:A-Brand";v="99"',
15
+ 'sec-ch-ua-mobile': '?0',
16
+ 'sec-ch-ua-platform': '"macOS"',
17
+ 'sec-fetch-dest': 'empty',
18
+ 'sec-fetch-mode': 'cors',
19
+ 'sec-fetch-site': 'same-origin',
20
+ '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',
21
+ }
22
+
23
+ class PhindResponse:
24
+
25
+ class Completion:
26
+
27
+ class Choices:
28
+ def __init__(self, choice: dict) -> None:
29
+ self.text = choice['text']
30
+ self.content = self.text.encode()
31
+ self.index = choice['index']
32
+ self.logprobs = choice['logprobs']
33
+ self.finish_reason = choice['finish_reason']
34
+
35
+ def __repr__(self) -> str:
36
+ return f'''<__main__.APIResponse.Completion.Choices(\n text = {self.text.encode()},\n index = {self.index},\n logprobs = {self.logprobs},\n finish_reason = {self.finish_reason})object at 0x1337>'''
37
+
38
+ def __init__(self, choices: dict) -> None:
39
+ self.choices = [self.Choices(choice) for choice in choices]
40
+
41
+ class Usage:
42
+ def __init__(self, usage_dict: dict) -> None:
43
+ self.prompt_tokens = usage_dict['prompt_tokens']
44
+ self.completion_tokens = usage_dict['completion_tokens']
45
+ self.total_tokens = usage_dict['total_tokens']
46
+
47
+ def __repr__(self):
48
+ return f'''<__main__.APIResponse.Usage(\n prompt_tokens = {self.prompt_tokens},\n completion_tokens = {self.completion_tokens},\n total_tokens = {self.total_tokens})object at 0x1337>'''
49
+
50
+ def __init__(self, response_dict: dict) -> None:
51
+
52
+ self.response_dict = response_dict
53
+ self.id = response_dict['id']
54
+ self.object = response_dict['object']
55
+ self.created = response_dict['created']
56
+ self.model = response_dict['model']
57
+ self.completion = self.Completion(response_dict['choices'])
58
+ self.usage = self.Usage(response_dict['usage'])
59
+
60
+ def json(self) -> dict:
61
+ return self.response_dict
62
+
63
+
64
+ class Search:
65
+ def create(prompt: str, actualSearch: bool = True, language: str = 'en') -> dict: # None = no search
66
+ if not actualSearch:
67
+ return {
68
+ '_type': 'SearchResponse',
69
+ 'queryContext': {
70
+ 'originalQuery': prompt
71
+ },
72
+ 'webPages': {
73
+ 'webSearchUrl': f'https://www.bing.com/search?q={quote(prompt)}',
74
+ 'totalEstimatedMatches': 0,
75
+ 'value': []
76
+ },
77
+ 'rankingResponse': {
78
+ 'mainline': {
79
+ 'items': []
80
+ }
81
+ }
82
+ }
83
+
84
+ return client.post('https://www.phind.com/api/bing/search', json = {
85
+ 'q': prompt,
86
+ 'userRankList': {},
87
+ 'browserLanguage': language}).json()['rawBingResults']
88
+
89
+ class Completion:
90
+ def create(
91
+ model = 'gpt-4',
92
+ prompt: str = '',
93
+ results: dict = None,
94
+ creative: bool = False,
95
+ detailed: bool = False,
96
+ codeContext: str = '',
97
+ language: str = 'en') -> PhindResponse:
98
+
99
+ if results is None:
100
+ results = Search.create(prompt, actualSearch = True)
101
+
102
+ if len(codeContext) > 2999:
103
+ raise ValueError('codeContext must be less than 3000 characters')
104
+
105
+ models = {
106
+ 'gpt-4' : 'expert',
107
+ 'gpt-3.5-turbo' : 'intermediate',
108
+ 'gpt-3.5': 'intermediate',
109
+ }
110
+
111
+ json_data = {
112
+ 'question' : prompt,
113
+ 'bingResults' : results, #response.json()['rawBingResults'],
114
+ 'codeContext' : codeContext,
115
+ 'options': {
116
+ 'skill' : models[model],
117
+ 'date' : datetime.now().strftime("%d/%m/%Y"),
118
+ 'language': language,
119
+ 'detailed': detailed,
120
+ 'creative': creative
121
+ }
122
+ }
123
+
124
+ completion = ''
125
+ response = client.post('https://www.phind.com/api/infer/answer', json=json_data, timeout_seconds=200)
126
+ for line in response.text.split('\r\n\r\n'):
127
+ completion += (line.replace('data: ', ''))
128
+
129
+ return PhindResponse({
130
+ 'id' : f'cmpl-1337-{int(time())}',
131
+ 'object' : 'text_completion',
132
+ 'created': int(time()),
133
+ 'model' : models[model],
134
+ 'choices': [{
135
+ 'text' : completion,
136
+ 'index' : 0,
137
+ 'logprobs' : None,
138
+ 'finish_reason' : 'stop'
139
+ }],
140
+ 'usage': {
141
+ 'prompt_tokens' : len(prompt),
142
+ 'completion_tokens' : len(completion),
143
+ 'total_tokens' : len(prompt) + len(completion)
144
+ }
145
+ })
testing/phind_test.py ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import phind
2
+
3
+ prompt = 'hello world'
4
+
5
+ result = phind.Completion.create(
6
+ model = 'gpt-4',
7
+ prompt = prompt,
8
+ results = phind.Search.create(prompt, actualSearch = False), # create search (set actualSearch to False to disable internet)
9
+ creative = False,
10
+ detailed = False,
11
+ codeContext = '') # up to 3000 chars of code
12
+
13
+ print(result.completion.choices[0].text)