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