mirror of https://github.com/xtekky/gpt4free
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
2.2 KiB
Python
60 lines
2.2 KiB
Python
9 months ago
|
from __future__ import annotations
|
||
9 months ago
|
|
||
|
import json
|
||
9 months ago
|
from aiohttp import ClientSession
|
||
9 months ago
|
|
||
7 months ago
|
from ...typing import AsyncResult, Messages
|
||
|
from ..base_provider import AsyncGeneratorProvider
|
||
9 months ago
|
|
||
9 months ago
|
class Chatxyz(AsyncGeneratorProvider):
|
||
9 months ago
|
url = "https://chat.3211000.xyz"
|
||
7 months ago
|
working = False
|
||
9 months ago
|
supports_gpt_35_turbo = True
|
||
9 months ago
|
supports_message_history = True
|
||
9 months ago
|
|
||
|
@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 = {
|
||
9 months ago
|
"messages": messages,
|
||
9 months ago
|
"stream": True,
|
||
|
"model": "gpt-3.5-turbo",
|
||
|
"temperature": 0.5,
|
||
|
"presence_penalty": 0,
|
||
|
"frequency_penalty": 0,
|
||
9 months ago
|
"top_p": 1,
|
||
|
**kwargs
|
||
9 months ago
|
}
|
||
9 months ago
|
async with session.post(f'{cls.url}/api/openai/v1/chat/completions', json=data, proxy=proxy) as response:
|
||
9 months ago
|
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:])
|
||
9 months ago
|
chunk = line["choices"][0]["delta"].get("content")
|
||
|
if(chunk):
|
||
|
yield chunk
|