gpt4free/g4f/Provider/Yqcloud.py

44 lines
1.2 KiB
Python
Raw Normal View History

from aiohttp import ClientSession
2023-07-28 06:07:17 -04:00
from .base_provider import AsyncProvider, format_prompt
2023-07-28 06:07:17 -04:00
class Yqcloud(AsyncProvider):
url = "https://chat9.yqcloud.top/"
working = True
supports_gpt_35_turbo = True
2023-07-28 06:07:17 -04:00
@staticmethod
async def create_async(
2023-07-28 06:07:17 -04:00
model: str,
messages: list[dict[str, str]],
proxy: str = None,
**kwargs,
) -> str:
async with ClientSession(
headers=_create_header()
) as session:
payload = _create_payload(messages)
async with session.post("https://api.aichatos.cloud/api/generateStream", proxy=proxy, json=payload) as response:
response.raise_for_status()
return await response.text()
2023-07-28 06:07:17 -04:00
def _create_header():
return {
2023-08-27 11:37:44 -04:00
"accept" : "application/json, text/plain, */*",
"content-type" : "application/json",
"origin" : "https://chat9.yqcloud.top",
2023-07-28 06:07:17 -04:00
}
def _create_payload(messages: list[dict[str, str]]):
return {
"prompt": format_prompt(messages),
"network": True,
"system": "",
2023-07-28 06:07:17 -04:00
"withoutContext": False,
"stream": False,
"userId": "#/chat/1693025544336"
}