Create Phind.py
Browse files
g4f/Provider/Providers/Phind.py
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import json
|
3 |
+
import time
|
4 |
+
import subprocess
|
5 |
+
|
6 |
+
from ...typing import sha256, Dict, get_type_hints
|
7 |
+
|
8 |
+
url = 'https://phind.com'
|
9 |
+
model = ['gpt-4']
|
10 |
+
supports_stream = True
|
11 |
+
|
12 |
+
def _create_completion(model: str, messages: list, stream: bool, **kwargs):
|
13 |
+
|
14 |
+
path = os.path.dirname(os.path.realpath(__file__))
|
15 |
+
config = json.dumps({
|
16 |
+
'model': model,
|
17 |
+
'messages': messages}, separators=(',', ':'))
|
18 |
+
|
19 |
+
cmd = ['python', f'{path}/helpers/phind.py', config]
|
20 |
+
|
21 |
+
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
22 |
+
|
23 |
+
for line in iter(p.stdout.readline, b''):
|
24 |
+
if b'<title>Just a moment...</title>' in line:
|
25 |
+
os.system('clear' if os.name == 'posix' else 'cls')
|
26 |
+
yield 'Clouflare error, please try again...'
|
27 |
+
os._exit(0)
|
28 |
+
|
29 |
+
else:
|
30 |
+
if b'ping - 2023-' in line:
|
31 |
+
continue
|
32 |
+
|
33 |
+
yield line.decode('cp1251') #[:-1]
|
34 |
+
|
35 |
+
params = f'g4f.Providers.{os.path.basename(__file__)[:-3]} supports: ' + \
|
36 |
+
'(%s)' % ', '.join([f"{name}: {get_type_hints(_create_completion)[name].__name__}" for name in _create_completion.__code__.co_varnames[:_create_completion.__code__.co_argcount]])
|