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()
|
2023-08-17 16:59:25 -04:00
|
|
|
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]]):
|
2023-08-23 03:34:38 -04:00
|
|
|
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,
|
|
|
|
}
|