Spaces:
Paused
Paused
Add API Provider: Ails
Browse files- client/html/index.html +2 -2
- g4f/Provider/Providers/Ails.py +87 -0
- g4f/Provider/__init__.py +1 -0
- g4f/models.py +1 -1
client/html/index.html
CHANGED
|
@@ -75,10 +75,10 @@
|
|
| 75 |
<div class="buttons">
|
| 76 |
<div class="field">
|
| 77 |
<select class="dropdown" name="model" id="model">
|
| 78 |
-
<option value="gpt-3.5-turbo">GPT-3.5</option>
|
| 79 |
<option value="gpt-3.5-turbo-0613">GPT-3.5-0613</option>
|
| 80 |
<option value="gpt-3.5-turbo-16k">GPT-3.5-turbo-16k</option>
|
| 81 |
-
<option value="gpt-3.5-turbo-16k-0613"
|
| 82 |
GPT-3.5-turbo-16k-0613
|
| 83 |
</option>
|
| 84 |
<option value="gpt-4">GPT-4</option>
|
|
|
|
| 75 |
<div class="buttons">
|
| 76 |
<div class="field">
|
| 77 |
<select class="dropdown" name="model" id="model">
|
| 78 |
+
<option value="gpt-3.5-turbo" selected>GPT-3.5</option>
|
| 79 |
<option value="gpt-3.5-turbo-0613">GPT-3.5-0613</option>
|
| 80 |
<option value="gpt-3.5-turbo-16k">GPT-3.5-turbo-16k</option>
|
| 81 |
+
<option value="gpt-3.5-turbo-16k-0613">
|
| 82 |
GPT-3.5-turbo-16k-0613
|
| 83 |
</option>
|
| 84 |
<option value="gpt-4">GPT-4</option>
|
g4f/Provider/Providers/Ails.py
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import time
|
| 3 |
+
import json
|
| 4 |
+
import uuid
|
| 5 |
+
import hashlib
|
| 6 |
+
import requests
|
| 7 |
+
|
| 8 |
+
from ...typing import sha256, Dict, get_type_hints
|
| 9 |
+
from datetime import datetime
|
| 10 |
+
|
| 11 |
+
url: str = 'https://ai.ls'
|
| 12 |
+
model: str = 'gpt-3.5-turbo'
|
| 13 |
+
supports_stream = True
|
| 14 |
+
needs_auth = False
|
| 15 |
+
working = True
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
class Utils:
|
| 19 |
+
def hash(json_data: Dict[str, str]) -> sha256:
|
| 20 |
+
|
| 21 |
+
base_string: str = '%s:%s:%s:%s' % (
|
| 22 |
+
json_data['t'],
|
| 23 |
+
json_data['m'],
|
| 24 |
+
'WI,2rU#_r:r~aF4aJ36[.Z(/8Rv93Rf',
|
| 25 |
+
len(json_data['m'])
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
return hashlib.sha256(base_string.encode()).hexdigest()
|
| 29 |
+
|
| 30 |
+
def format_timestamp(timestamp: int) -> str:
|
| 31 |
+
|
| 32 |
+
e = timestamp
|
| 33 |
+
n = e % 10
|
| 34 |
+
r = n + 1 if n % 2 == 0 else n
|
| 35 |
+
return str(e - n + r)
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
def _create_completion(model: str, messages: list, temperature: float = 0.6, stream: bool = False, **kwargs):
|
| 39 |
+
|
| 40 |
+
headers = {
|
| 41 |
+
'authority': 'api.caipacity.com',
|
| 42 |
+
'accept': '*/*',
|
| 43 |
+
'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',
|
| 44 |
+
'authorization': 'Bearer free',
|
| 45 |
+
'client-id': str(uuid.uuid4()),
|
| 46 |
+
'client-v': '0.1.249',
|
| 47 |
+
'content-type': 'application/json',
|
| 48 |
+
'origin': 'https://ai.ls',
|
| 49 |
+
'referer': 'https://ai.ls/',
|
| 50 |
+
'sec-ch-ua': '"Not.A/Brand";v="8", "Chromium";v="114", "Google Chrome";v="114"',
|
| 51 |
+
'sec-ch-ua-mobile': '?0',
|
| 52 |
+
'sec-ch-ua-platform': '"Windows"',
|
| 53 |
+
'sec-fetch-dest': 'empty',
|
| 54 |
+
'sec-fetch-mode': 'cors',
|
| 55 |
+
'sec-fetch-site': 'cross-site',
|
| 56 |
+
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36',
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
timestamp = Utils.format_timestamp(int(time.time() * 1000))
|
| 60 |
+
|
| 61 |
+
sig = {
|
| 62 |
+
'd': datetime.now().strftime('%Y-%m-%d'),
|
| 63 |
+
't': timestamp,
|
| 64 |
+
's': Utils.hash({
|
| 65 |
+
't': timestamp,
|
| 66 |
+
'm': messages[-1]['content']})}
|
| 67 |
+
|
| 68 |
+
json_data = json.dumps(separators=(',', ':'), obj={
|
| 69 |
+
'model': 'gpt-3.5-turbo',
|
| 70 |
+
'temperature': 0.6,
|
| 71 |
+
'stream': True,
|
| 72 |
+
'messages': messages} | sig)
|
| 73 |
+
|
| 74 |
+
response = requests.post('https://api.caipacity.com/v1/chat/completions',
|
| 75 |
+
headers=headers, data=json_data, stream=True)
|
| 76 |
+
|
| 77 |
+
for token in response.iter_lines():
|
| 78 |
+
if b'content' in token:
|
| 79 |
+
completion_chunk = json.loads(token.decode().replace('data: ', ''))
|
| 80 |
+
token = completion_chunk['choices'][0]['delta'].get('content')
|
| 81 |
+
if token != None:
|
| 82 |
+
yield token
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
params = f'g4f.Providers.{os.path.basename(__file__)[:-3]} supports: ' + \
|
| 86 |
+
'(%s)' % ', '.join(
|
| 87 |
+
[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
|
@@ -1,6 +1,7 @@
|
|
| 1 |
from . import Provider
|
| 2 |
from .Providers import (
|
| 3 |
Aichat,
|
|
|
|
| 4 |
Bard,
|
| 5 |
Better,
|
| 6 |
Bing,
|
|
|
|
| 1 |
from . import Provider
|
| 2 |
from .Providers import (
|
| 3 |
Aichat,
|
| 4 |
+
Ails,
|
| 5 |
Bard,
|
| 6 |
Better,
|
| 7 |
Bing,
|
g4f/models.py
CHANGED
|
@@ -10,7 +10,7 @@ class Model:
|
|
| 10 |
class gpt_35_turbo:
|
| 11 |
name: str = 'gpt-3.5-turbo'
|
| 12 |
base_provider: str = 'openai'
|
| 13 |
-
best_provider: Provider.Provider =
|
| 14 |
|
| 15 |
class gpt_35_turbo_0613:
|
| 16 |
name: str = 'gpt-3.5-turbo-0613'
|
|
|
|
| 10 |
class gpt_35_turbo:
|
| 11 |
name: str = 'gpt-3.5-turbo'
|
| 12 |
base_provider: str = 'openai'
|
| 13 |
+
best_provider: Provider.Provider = Provider.Ails
|
| 14 |
|
| 15 |
class gpt_35_turbo_0613:
|
| 16 |
name: str = 'gpt-3.5-turbo-0613'
|