Spaces:
Running
Running
Update API Provider: Easychat
Browse files
g4f/Provider/Providers/Easychat.py
CHANGED
@@ -4,24 +4,52 @@ import json
|
|
4 |
from ...typing import sha256, Dict, get_type_hints
|
5 |
|
6 |
url = 'https://free.easychat.work'
|
7 |
-
model = ['gpt-3.5-turbo
|
|
|
8 |
supports_stream = True
|
9 |
needs_auth = False
|
10 |
|
11 |
-
|
|
|
12 |
headers = {
|
13 |
-
'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
}
|
15 |
-
|
16 |
-
|
17 |
-
'temperature': 0.7,
|
18 |
-
'presence_penalty': 0,
|
19 |
'messages': messages,
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
}
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
|
|
|
|
|
|
|
|
|
|
25 |
|
26 |
params = f'g4f.Providers.{os.path.basename(__file__)[:-3]} supports: ' + \
|
27 |
-
'(%s)' % ', '.join(
|
|
|
|
4 |
from ...typing import sha256, Dict, get_type_hints
|
5 |
|
6 |
url = 'https://free.easychat.work'
|
7 |
+
model = ['gpt-3.5-turbo', 'gpt-3.5-turbo-16k',
|
8 |
+
'gpt-3.5-turbo-16k-0613', 'gpt-3.5-turbo-0613']
|
9 |
supports_stream = True
|
10 |
needs_auth = False
|
11 |
|
12 |
+
|
13 |
+
def _create_completion(model: str, messages: list, stream: bool, **kwargs):
|
14 |
headers = {
|
15 |
+
'authority': 'free.easychat.work',
|
16 |
+
'accept': 'text/event-stream',
|
17 |
+
'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',
|
18 |
+
'content-type': 'application/json',
|
19 |
+
'endpoint': '',
|
20 |
+
'origin': 'https://free.easychat.work',
|
21 |
+
'plugins': '0',
|
22 |
+
'referer': 'https://free.easychat.work/',
|
23 |
+
'sec-ch-ua': '"Not.A/Brand";v="8", "Chromium";v="114", "Google Chrome";v="114"',
|
24 |
+
'sec-ch-ua-mobile': '?0',
|
25 |
+
'sec-ch-ua-platform': '"macOS"',
|
26 |
+
'sec-fetch-dest': 'empty',
|
27 |
+
'sec-fetch-mode': 'cors',
|
28 |
+
'sec-fetch-site': 'same-origin',
|
29 |
+
'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',
|
30 |
+
'usesearch': 'false',
|
31 |
+
'x-requested-with': 'XMLHttpRequest',
|
32 |
}
|
33 |
+
|
34 |
+
json_data = {
|
|
|
|
|
35 |
'messages': messages,
|
36 |
+
'stream': True,
|
37 |
+
'model': model,
|
38 |
+
'temperature': 0.5,
|
39 |
+
'presence_penalty': 0,
|
40 |
+
'frequency_penalty': 0,
|
41 |
+
'top_p': 1,
|
42 |
}
|
43 |
+
|
44 |
+
response = requests.post('https://free.easychat.work/api/openai/v1/chat/completions',
|
45 |
+
headers=headers, json=json_data)
|
46 |
+
|
47 |
+
for chunk in response.iter_lines():
|
48 |
+
if b'content' in chunk:
|
49 |
+
data = json.loads(chunk.decode().split('data: ')[1])
|
50 |
+
yield (data['choices'][0]['delta']['content'])
|
51 |
+
|
52 |
|
53 |
params = f'g4f.Providers.{os.path.basename(__file__)[:-3]} supports: ' + \
|
54 |
+
'(%s)' % ', '.join(
|
55 |
+
[f"{name}: {get_type_hints(_create_completion)[name].__name__}" for name in _create_completion.__code__.co_varnames[:_create_completion.__code__.co_argcount]])
|