2023-12-23 22:26:59 +03:00
|
|
|
from __future__ import annotations
|
2024-01-27 04:00:44 +03:00
|
|
|
|
2023-12-23 22:26:59 +03:00
|
|
|
from aiohttp import ClientSession
|
2024-01-27 04:00:44 +03:00
|
|
|
|
2023-12-23 22:26:59 +03:00
|
|
|
from ..typing import AsyncResult, Messages
|
|
|
|
from .base_provider import AsyncGeneratorProvider
|
2024-03-12 04:06:06 +03:00
|
|
|
from ..requests import get_args_from_browser
|
|
|
|
from ..webdriver import WebDriver
|
2023-12-23 22:26:59 +03:00
|
|
|
|
|
|
|
class Aura(AsyncGeneratorProvider):
|
2024-02-27 13:55:40 +03:00
|
|
|
url = "https://openchat.team"
|
|
|
|
working = True
|
2023-12-23 22:26:59 +03:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
async def create_async_generator(
|
|
|
|
cls,
|
|
|
|
model: str,
|
|
|
|
messages: Messages,
|
|
|
|
proxy: str = None,
|
2024-04-07 00:37:41 +03:00
|
|
|
temperature: float = 0.5,
|
2024-04-07 11:36:13 +03:00
|
|
|
max_tokens: int = 8192,
|
2024-03-12 04:06:06 +03:00
|
|
|
webdriver: WebDriver = None,
|
2023-12-23 22:26:59 +03:00
|
|
|
**kwargs
|
|
|
|
) -> AsyncResult:
|
2024-03-12 04:06:06 +03:00
|
|
|
args = get_args_from_browser(cls.url, webdriver, proxy)
|
|
|
|
async with ClientSession(**args) as session:
|
2023-12-23 22:33:23 +03:00
|
|
|
new_messages = []
|
|
|
|
system_message = []
|
2023-12-23 22:26:59 +03:00
|
|
|
for message in messages:
|
2023-12-23 22:33:23 +03:00
|
|
|
if message["role"] == "system":
|
|
|
|
system_message.append(message["content"])
|
2023-12-23 22:26:59 +03:00
|
|
|
else:
|
2023-12-23 22:33:23 +03:00
|
|
|
new_messages.append(message)
|
2023-12-23 22:26:59 +03:00
|
|
|
data = {
|
|
|
|
"model": {
|
|
|
|
"id": "openchat_v3.2_mistral",
|
|
|
|
"name": "OpenChat Aura",
|
|
|
|
"maxLength": 24576,
|
2024-04-07 00:37:41 +03:00
|
|
|
"tokenLimit": max_tokens
|
2023-12-23 22:33:23 +03:00
|
|
|
},
|
|
|
|
"messages": new_messages,
|
2023-12-23 22:26:59 +03:00
|
|
|
"key": "",
|
2023-12-23 22:33:23 +03:00
|
|
|
"prompt": "\n".join(system_message),
|
2024-04-07 00:37:41 +03:00
|
|
|
"temperature": temperature
|
2023-12-23 22:33:23 +03:00
|
|
|
}
|
|
|
|
async with session.post(f"{cls.url}/api/chat", json=data, proxy=proxy) as response:
|
2024-01-27 04:00:44 +03:00
|
|
|
response.raise_for_status()
|
2023-12-23 22:36:35 +03:00
|
|
|
async for chunk in response.content.iter_any():
|
2024-04-07 00:37:41 +03:00
|
|
|
yield chunk.decode(error="ignore")
|