AchyuthGamer
commited on
Commit
•
887d30a
1
Parent(s):
2f4bdc8
Create Aichat.py
Browse files
g4f/Provider/Providers/Aichat.py
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import requests
|
2 |
+
import os
|
3 |
+
import json
|
4 |
+
from ...typing import sha256, Dict, get_type_hints
|
5 |
+
|
6 |
+
url = 'https://hteyun.com'
|
7 |
+
model = ['gpt-3.5-turbo', 'gpt-3.5-turbo-16k', 'gpt-3.5-turbo-16k-0613', 'gpt-3.5-turbo-0613']
|
8 |
+
supports_stream = True
|
9 |
+
needs_auth = False
|
10 |
+
|
11 |
+
def _create_completion(model: str, messages: list, stream: bool, temperature: float = 0.7, **kwargs):
|
12 |
+
headers = {
|
13 |
+
'Content-Type': 'application/json',
|
14 |
+
}
|
15 |
+
data = {
|
16 |
+
'model': model,
|
17 |
+
'temperature': 0.7,
|
18 |
+
'presence_penalty': 0,
|
19 |
+
'messages': messages,
|
20 |
+
}
|
21 |
+
response = requests.post(url + '/api/chat-stream',
|
22 |
+
json=data, stream=True)
|
23 |
+
|
24 |
+
if stream:
|
25 |
+
for chunk in response.iter_content(chunk_size=None):
|
26 |
+
chunk = chunk.decode('utf-8')
|
27 |
+
if chunk.strip():
|
28 |
+
message = json.loads(chunk)['choices'][0]['message']['content']
|
29 |
+
yield message
|
30 |
+
else:
|
31 |
+
message = response.json()['choices'][0]['message']['content']
|
32 |
+
yield message
|
33 |
+
|
34 |
+
params = f'g4f.Providers.{os.path.basename(__file__)[:-3]} supports: ' + \
|
35 |
+
'(%s)' % ', '.join([f"{name}: {get_type_hints(_create_completion)[name].__name__}" for name in _create_completion.__code__.co_varnames[:_create_completion.__code__.co_argcount]])
|