gpt4free/g4f/Provider/Aura.py

50 lines
1.7 KiB
Python
Raw Normal View History

from __future__ import annotations
from aiohttp import ClientSession
from ..typing import AsyncResult, Messages
from .base_provider import AsyncGeneratorProvider
from ..requests import get_args_from_browser
from ..webdriver import WebDriver
class Aura(AsyncGeneratorProvider):
url = "https://openchat.team"
2024-09-24 13:23:53 +03:00
working = False
@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,
max_tokens: int = 8192,
webdriver: WebDriver = None,
**kwargs
) -> AsyncResult:
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 = []
for message in messages:
2023-12-23 22:33:23 +03:00
if message["role"] == "system":
system_message.append(message["content"])
else:
2023-12-23 22:33:23 +03:00
new_messages.append(message)
data = {
"model": {
2024-08-25 11:00:06 +03:00
"id": "openchat_3.6",
"name": "OpenChat 3.6 (latest)",
"maxLength": 24576,
2024-04-07 00:37:41 +03:00
"tokenLimit": max_tokens
2023-12-23 22:33:23 +03:00
},
"messages": new_messages,
"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:
response.raise_for_status()
2023-12-23 22:36:35 +03:00
async for chunk in response.content.iter_any():
2024-09-24 13:23:53 +03:00
yield chunk.decode(error="ignore")