2023-12-27 08:13:52 +03:00
|
|
|
from __future__ import annotations
|
2023-12-27 08:46:42 +03:00
|
|
|
|
|
|
|
import json
|
2023-12-27 08:13:52 +03:00
|
|
|
from aiohttp import ClientSession
|
2023-12-27 08:46:42 +03:00
|
|
|
|
2023-12-27 08:13:52 +03:00
|
|
|
from ..typing import AsyncResult, Messages
|
|
|
|
from .base_provider import AsyncGeneratorProvider
|
2023-12-27 08:46:42 +03:00
|
|
|
|
2023-12-27 08:13:52 +03:00
|
|
|
class Chatxyz(AsyncGeneratorProvider):
|
2023-12-27 08:46:42 +03:00
|
|
|
url = "https://chat.3211000.xyz"
|
|
|
|
working = True
|
2023-12-27 08:13:52 +03:00
|
|
|
supports_gpt_35_turbo = True
|
2023-12-27 08:46:42 +03:00
|
|
|
supports_message_history = True
|
2023-12-27 08:13:52 +03:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
async def create_async_generator(
|
|
|
|
cls,
|
|
|
|
model: str,
|
|
|
|
messages: Messages,
|
|
|
|
proxy: str = None,
|
|
|
|
**kwargs
|
|
|
|
) -> AsyncResult:
|
|
|
|
headers = {
|
|
|
|
'Accept': 'text/event-stream',
|
|
|
|
'Accept-Encoding': 'gzip, deflate, br',
|
|
|
|
'Accept-Language': 'en-US,en;q=0.5',
|
|
|
|
'Alt-Used': 'chat.3211000.xyz',
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
'Host': 'chat.3211000.xyz',
|
|
|
|
'Origin': 'https://chat.3211000.xyz',
|
|
|
|
'Referer': 'https://chat.3211000.xyz/',
|
|
|
|
'Sec-Fetch-Dest': 'empty',
|
|
|
|
'Sec-Fetch-Mode': 'cors',
|
|
|
|
'Sec-Fetch-Site': 'same-origin',
|
|
|
|
'TE': 'trailers',
|
|
|
|
'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:121.0) Gecko/20100101 Firefox/121.0',
|
|
|
|
'x-requested-with': 'XMLHttpRequest'
|
|
|
|
}
|
|
|
|
async with ClientSession(headers=headers) as session:
|
|
|
|
data = {
|
2023-12-27 08:46:42 +03:00
|
|
|
"messages": messages,
|
2023-12-27 08:13:52 +03:00
|
|
|
"stream": True,
|
|
|
|
"model": "gpt-3.5-turbo",
|
|
|
|
"temperature": 0.5,
|
|
|
|
"presence_penalty": 0,
|
|
|
|
"frequency_penalty": 0,
|
2023-12-27 08:46:42 +03:00
|
|
|
"top_p": 1,
|
|
|
|
**kwargs
|
2023-12-27 08:13:52 +03:00
|
|
|
}
|
2023-12-27 08:46:42 +03:00
|
|
|
async with session.post(f'{cls.url}/api/openai/v1/chat/completions', json=data, proxy=proxy) as response:
|
2023-12-27 08:13:52 +03:00
|
|
|
response.raise_for_status()
|
|
|
|
async for chunk in response.content:
|
|
|
|
line = chunk.decode()
|
|
|
|
if line.startswith("data: [DONE]"):
|
|
|
|
break
|
|
|
|
elif line.startswith("data: "):
|
|
|
|
line = json.loads(line[6:])
|
2023-12-27 08:46:42 +03:00
|
|
|
chunk = line["choices"][0]["delta"].get("content")
|
|
|
|
if(chunk):
|
|
|
|
yield chunk
|