Spaces:
Paused
Paused
New GPT-4 API provider: Xiaor
Browse files- g4f/Provider/Providers/Xiaor.py +39 -0
- g4f/Provider/__init__.py +1 -0
g4f/Provider/Providers/Xiaor.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import requests
|
| 2 |
+
import os
|
| 3 |
+
import json
|
| 4 |
+
from ...typing import sha256, Dict, get_type_hints
|
| 5 |
+
|
| 6 |
+
url = 'https://xiaor.eu.org'
|
| 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, temperature: float = 0.7, **kwargs):
|
| 14 |
+
headers = {
|
| 15 |
+
'Content-Type': 'application/json',
|
| 16 |
+
}
|
| 17 |
+
data = {
|
| 18 |
+
'model': model,
|
| 19 |
+
'temperature': 0.7,
|
| 20 |
+
'presence_penalty': 0,
|
| 21 |
+
'messages': messages,
|
| 22 |
+
}
|
| 23 |
+
response = requests.post(url + '/p1/v1/chat/completions',
|
| 24 |
+
json=data, stream=True)
|
| 25 |
+
|
| 26 |
+
if stream:
|
| 27 |
+
for chunk in response.iter_content(chunk_size=None):
|
| 28 |
+
chunk = chunk.decode('utf-8')
|
| 29 |
+
if chunk.strip():
|
| 30 |
+
message = json.loads(chunk)['choices'][0]['message']['content']
|
| 31 |
+
yield message
|
| 32 |
+
else:
|
| 33 |
+
message = response.json()['choices'][0]['message']['content']
|
| 34 |
+
yield message
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
params = f'g4f.Providers.{os.path.basename(__file__)[:-3]} supports: ' + \
|
| 38 |
+
'(%s)' % ', '.join(
|
| 39 |
+
[f"{name}: {get_type_hints(_create_completion)[name].__name__}" for name in _create_completion.__code__.co_varnames[:_create_completion.__code__.co_argcount]])
|
g4f/Provider/__init__.py
CHANGED
|
@@ -24,6 +24,7 @@ from .Providers import (
|
|
| 24 |
Theb,
|
| 25 |
Vercel,
|
| 26 |
Weuseing,
|
|
|
|
| 27 |
Yqcloud,
|
| 28 |
You,
|
| 29 |
)
|
|
|
|
| 24 |
Theb,
|
| 25 |
Vercel,
|
| 26 |
Weuseing,
|
| 27 |
+
Xiaor,
|
| 28 |
Yqcloud,
|
| 29 |
You,
|
| 30 |
)
|