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.
62 lines
1.9 KiB
Python
62 lines
1.9 KiB
Python
12 months ago
|
from __future__ import annotations
|
||
|
|
||
11 months ago
|
import random
|
||
7 months ago
|
from ...requests import StreamSession
|
||
1 year ago
|
|
||
7 months ago
|
from ...typing import AsyncResult, Messages
|
||
|
from ..base_provider import AsyncGeneratorProvider, format_prompt
|
||
1 year ago
|
|
||
|
|
||
12 months ago
|
class Yqcloud(AsyncGeneratorProvider):
|
||
1 year ago
|
url = "https://chat9.yqcloud.top/"
|
||
10 months ago
|
working = True
|
||
1 year ago
|
supports_gpt_35_turbo = True
|
||
1 year ago
|
|
||
|
@staticmethod
|
||
12 months ago
|
async def create_async_generator(
|
||
1 year ago
|
model: str,
|
||
11 months ago
|
messages: Messages,
|
||
1 year ago
|
proxy: str = None,
|
||
10 months ago
|
timeout: int = 120,
|
||
1 year ago
|
**kwargs,
|
||
11 months ago
|
) -> AsyncResult:
|
||
10 months ago
|
async with StreamSession(
|
||
10 months ago
|
headers=_create_header(), proxies={"https": proxy}, timeout=timeout
|
||
1 year ago
|
) as session:
|
||
11 months ago
|
payload = _create_payload(messages, **kwargs)
|
||
10 months ago
|
async with session.post("https://api.aichatos.cloud/api/generateStream", json=payload) as response:
|
||
1 year ago
|
response.raise_for_status()
|
||
10 months ago
|
async for chunk in response.iter_content():
|
||
11 months ago
|
if chunk:
|
||
|
chunk = chunk.decode()
|
||
|
if "sorry, 您的ip已由于触发防滥用检测而被封禁" in chunk:
|
||
11 months ago
|
raise RuntimeError("IP address is blocked by abuse detection.")
|
||
11 months ago
|
yield chunk
|
||
1 year ago
|
|
||
|
|
||
|
def _create_header():
|
||
|
return {
|
||
1 year ago
|
"accept" : "application/json, text/plain, */*",
|
||
|
"content-type" : "application/json",
|
||
|
"origin" : "https://chat9.yqcloud.top",
|
||
10 months ago
|
"referer" : "https://chat9.yqcloud.top/"
|
||
1 year ago
|
}
|
||
|
|
||
|
|
||
11 months ago
|
def _create_payload(
|
||
|
messages: Messages,
|
||
|
system_message: str = "",
|
||
|
user_id: int = None,
|
||
|
**kwargs
|
||
|
):
|
||
|
if not user_id:
|
||
|
user_id = random.randint(1690000544336, 2093025544336)
|
||
1 year ago
|
return {
|
||
1 year ago
|
"prompt": format_prompt(messages),
|
||
|
"network": True,
|
||
11 months ago
|
"system": system_message,
|
||
1 year ago
|
"withoutContext": False,
|
||
12 months ago
|
"stream": True,
|
||
11 months ago
|
"userId": f"#/chat/{user_id}"
|
||
1 year ago
|
}
|