2023-12-23 19:26:59 +00:00
|
|
|
from __future__ import annotations
|
2024-01-27 01:00:44 +00:00
|
|
|
|
2023-12-23 19:26:59 +00:00
|
|
|
from aiohttp import ClientSession
|
2024-01-27 01:00:44 +00:00
|
|
|
|
2023-12-23 19:26:59 +00:00
|
|
|
from ..typing import AsyncResult, Messages
|
|
|
|
from .base_provider import AsyncGeneratorProvider
|
|
|
|
|
|
|
|
class Aura(AsyncGeneratorProvider):
|
|
|
|
url = "https://openchat.team"
|
|
|
|
working = True
|
|
|
|
supports_gpt_35_turbo = True
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
async def create_async_generator(
|
|
|
|
cls,
|
|
|
|
model: str,
|
|
|
|
messages: Messages,
|
|
|
|
proxy: str = None,
|
|
|
|
**kwargs
|
|
|
|
) -> AsyncResult:
|
|
|
|
headers = {
|
|
|
|
"Accept": "*/*",
|
|
|
|
"Accept-Encoding": "gzip, deflate, br",
|
|
|
|
"Accept-Language": "en-GB,en-US;q=0.9,en;q=0.8",
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
"Origin": f"{cls.url}",
|
|
|
|
"Referer": f"{cls.url}/",
|
2024-01-27 01:00:44 +00:00
|
|
|
"Sec-Ch-Ua": '"Not_A Brand";v="8", "Chromium";v="120", "Google Chrome";v="120"',
|
2023-12-23 19:26:59 +00:00
|
|
|
"Sec-Ch-Ua-Mobile": "?0",
|
|
|
|
"Sec-Ch-Ua-Platform": '"Linux"',
|
|
|
|
"Sec-Fetch-Dest": "empty",
|
|
|
|
"Sec-Fetch-Mode": "cors",
|
|
|
|
"Sec-Fetch-Site": "same-origin",
|
|
|
|
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
|
|
|
|
}
|
|
|
|
async with ClientSession(headers=headers) as session:
|
2023-12-23 19:33:23 +00:00
|
|
|
new_messages = []
|
|
|
|
system_message = []
|
2023-12-23 19:26:59 +00:00
|
|
|
for message in messages:
|
2023-12-23 19:33:23 +00:00
|
|
|
if message["role"] == "system":
|
|
|
|
system_message.append(message["content"])
|
2023-12-23 19:26:59 +00:00
|
|
|
else:
|
2023-12-23 19:33:23 +00:00
|
|
|
new_messages.append(message)
|
2023-12-23 19:26:59 +00:00
|
|
|
data = {
|
|
|
|
"model": {
|
|
|
|
"id": "openchat_v3.2_mistral",
|
|
|
|
"name": "OpenChat Aura",
|
|
|
|
"maxLength": 24576,
|
|
|
|
"tokenLimit": 8192
|
2023-12-23 19:33:23 +00:00
|
|
|
},
|
|
|
|
"messages": new_messages,
|
2023-12-23 19:26:59 +00:00
|
|
|
"key": "",
|
2023-12-23 19:33:23 +00:00
|
|
|
"prompt": "\n".join(system_message),
|
2023-12-23 19:26:59 +00:00
|
|
|
"temperature": 0.5
|
2023-12-23 19:33:23 +00:00
|
|
|
}
|
|
|
|
async with session.post(f"{cls.url}/api/chat", json=data, proxy=proxy) as response:
|
2024-01-27 01:00:44 +00:00
|
|
|
response.raise_for_status()
|
2023-12-23 19:36:35 +00:00
|
|
|
async for chunk in response.content.iter_any():
|
|
|
|
yield chunk.decode()
|