gpt4free/g4f/Provider/Yqcloud.py

49 lines
1.3 KiB
Python
Raw Normal View History

2023-07-28 06:07:17 -04:00
import requests
2023-08-27 11:37:44 -04:00
from ..typing import Any, CreateResult
2023-07-28 06:07:17 -04:00
from .base_provider import BaseProvider
class Yqcloud(BaseProvider):
2023-08-27 11:37:44 -04:00
url = "https://chat9.yqcloud.top/"
working = True
supports_gpt_35_turbo = True
2023-07-28 06:07:17 -04:00
@staticmethod
def create_completion(
model: str,
messages: list[dict[str, str]],
2023-08-27 11:37:44 -04:00
stream: bool, **kwargs: Any) -> CreateResult:
2023-07-28 06:07:17 -04:00
headers = _create_header()
payload = _create_payload(messages)
2023-08-27 11:37:44 -04:00
response = requests.post("https://api.aichatos.cloud/api/generateStream",
headers=headers, json=payload)
2023-07-28 06:07:17 -04:00
response.raise_for_status()
response.encoding = 'utf-8'
2023-07-28 06:07:17 -04:00
yield response.text
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]]):
prompt = ""
for message in messages:
prompt += "%s: %s\n" % (message["role"], message["content"])
prompt += "assistant:"
2023-08-27 11:37:44 -04:00
2023-07-28 06:07:17 -04:00
return {
2023-08-27 11:37:44 -04:00
"prompt" : prompt,
"network" : True,
"system" : "",
2023-07-28 06:07:17 -04:00
"withoutContext": False,
2023-08-27 11:37:44 -04:00
"stream" : False,
}