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
|
2024-03-12 01:06:06 +00:00
|
|
|
from ..requests import get_args_from_browser
|
|
|
|
from ..webdriver import WebDriver
|
2023-12-23 19:26:59 +00:00
|
|
|
|
|
|
|
class Aura(AsyncGeneratorProvider):
|
2024-02-27 10:55:40 +00:00
|
|
|
url = "https://openchat.team"
|
|
|
|
working = True
|
2023-12-23 19:26:59 +00:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
async def create_async_generator(
|
|
|
|
cls,
|
|
|
|
model: str,
|
|
|
|
messages: Messages,
|
|
|
|
proxy: str = None,
|
2024-04-06 21:37:41 +00:00
|
|
|
temperature: float = 0.5,
|
2024-04-07 08:36:13 +00:00
|
|
|
max_tokens: int = 8192,
|
2024-03-12 01:06:06 +00:00
|
|
|
webdriver: WebDriver = None,
|
2023-12-23 19:26:59 +00:00
|
|
|
**kwargs
|
|
|
|
) -> AsyncResult:
|
2024-03-12 01:06:06 +00:00
|
|
|
args = get_args_from_browser(cls.url, webdriver, proxy)
|
|
|
|
async with ClientSession(**args) 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,
|
2024-04-06 21:37:41 +00:00
|
|
|
"tokenLimit": max_tokens
|
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),
|
2024-04-06 21:37:41 +00:00
|
|
|
"temperature": temperature
|
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():
|
2024-04-06 21:37:41 +00:00
|
|
|
yield chunk.decode(error="ignore")
|