Create Providers/ChatFree.py
Browse files- Providers/ChatFree.py +48 -0
Providers/ChatFree.py
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os, requests
|
2 |
+
from ...typing import sha256, Dict, get_type_hints
|
3 |
+
import json
|
4 |
+
|
5 |
+
url = "https://v.chatfree.cc"
|
6 |
+
model = ['gpt-3.5-turbo', 'gpt-3.5-turbo-16k']
|
7 |
+
supports_stream = False
|
8 |
+
needs_auth = False
|
9 |
+
|
10 |
+
|
11 |
+
def _create_completion(model: str, messages: list, stream: bool, **kwargs):
|
12 |
+
headers = {
|
13 |
+
'authority': 'chat.dfehub.com',
|
14 |
+
'accept': '*/*',
|
15 |
+
'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',
|
16 |
+
'content-type': 'application/json',
|
17 |
+
'origin': 'https://v.chatfree.cc',
|
18 |
+
'referer': 'https://v.chatfree.cc/',
|
19 |
+
'sec-ch-ua': '"Not.A/Brand";v="8", "Chromium";v="114", "Google Chrome";v="114"',
|
20 |
+
'sec-ch-ua-mobile': '?0',
|
21 |
+
'sec-ch-ua-platform': '"macOS"',
|
22 |
+
'sec-fetch-dest': 'empty',
|
23 |
+
'sec-fetch-mode': 'cors',
|
24 |
+
'sec-fetch-site': 'same-origin',
|
25 |
+
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36',
|
26 |
+
'x-requested-with': 'XMLHttpRequest',
|
27 |
+
}
|
28 |
+
|
29 |
+
json_data = {
|
30 |
+
'messages': messages,
|
31 |
+
'stream': True,
|
32 |
+
'model': model,
|
33 |
+
'temperature': 0.5,
|
34 |
+
'presence_penalty': 0,
|
35 |
+
'frequency_penalty': 0,
|
36 |
+
'top_p': 1,
|
37 |
+
}
|
38 |
+
|
39 |
+
response = requests.post('https://v.chatfree.cc/api/openai/v1/chat/completions',
|
40 |
+
headers=headers, json=json_data)
|
41 |
+
|
42 |
+
for chunk in response.iter_lines():
|
43 |
+
if b'content' in chunk:
|
44 |
+
data = json.loads(chunk.decode().split('data: ')[1])
|
45 |
+
yield (data['choices'][0]['delta']['content'])
|
46 |
+
|
47 |
+
params = f'g4f.Providers.{os.path.basename(__file__)[:-3]} supports: ' + \
|
48 |
+
'(%s)' % ', '.join([f"{name}: {get_type_hints(_create_completion)[name].__name__}" for name in _create_completion.__code__.co_varnames[:_create_completion.__code__.co_argcount]])
|