2023-09-03 08:26:26 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
import random
|
|
|
|
|
|
|
|
import requests
|
|
|
|
|
2023-10-04 05:20:51 +00:00
|
|
|
from ...typing import Any, CreateResult
|
2024-01-01 16:48:57 +00:00
|
|
|
from ..base_provider import AbstractProvider, format_prompt
|
2023-08-17 15:36:33 +00:00
|
|
|
|
|
|
|
|
2024-01-01 16:48:57 +00:00
|
|
|
class Wuguokai(AbstractProvider):
|
2023-08-17 15:36:33 +00:00
|
|
|
url = 'https://chat.wuguokai.xyz'
|
|
|
|
supports_gpt_35_turbo = True
|
2023-09-12 02:40:10 +00:00
|
|
|
working = False
|
2023-08-17 15:36:33 +00:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def create_completion(
|
|
|
|
model: str,
|
|
|
|
messages: list[dict[str, str]],
|
|
|
|
stream: bool,
|
|
|
|
**kwargs: Any,
|
|
|
|
) -> CreateResult:
|
|
|
|
headers = {
|
|
|
|
'authority': 'ai-api.wuguokai.xyz',
|
|
|
|
'accept': 'application/json, text/plain, */*',
|
|
|
|
'accept-language': 'id-ID,id;q=0.9,en-US;q=0.8,en;q=0.7',
|
|
|
|
'content-type': 'application/json',
|
|
|
|
'origin': 'https://chat.wuguokai.xyz',
|
|
|
|
'referer': 'https://chat.wuguokai.xyz/',
|
|
|
|
'sec-ch-ua': '"Not.A/Brand";v="8", "Chromium";v="114", "Google Chrome";v="114"',
|
|
|
|
'sec-ch-ua-mobile': '?0',
|
|
|
|
'sec-ch-ua-platform': '"Windows"',
|
|
|
|
'sec-fetch-dest': 'empty',
|
|
|
|
'sec-fetch-mode': 'cors',
|
|
|
|
'sec-fetch-site': 'same-site',
|
|
|
|
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36'
|
|
|
|
}
|
|
|
|
data ={
|
2023-09-12 02:40:10 +00:00
|
|
|
"prompt": format_prompt(messages),
|
2023-08-17 15:36:33 +00:00
|
|
|
"options": {},
|
|
|
|
"userId": f"#/chat/{random.randint(1,99999999)}",
|
|
|
|
"usingContext": True
|
|
|
|
}
|
2023-10-23 07:46:25 +00:00
|
|
|
response = requests.post(
|
|
|
|
"https://ai-api20.wuguokai.xyz/api/chat-process",
|
|
|
|
headers=headers,
|
|
|
|
timeout=3,
|
|
|
|
json=data,
|
|
|
|
proxies=kwargs.get('proxy', {}),
|
|
|
|
)
|
2023-08-17 15:36:33 +00:00
|
|
|
_split = response.text.split("> 若回答失败请重试或多刷新几次界面后重试")
|
2023-10-23 07:46:25 +00:00
|
|
|
if response.status_code != 200:
|
2023-08-17 15:36:33 +00:00
|
|
|
raise Exception(f"Error: {response.status_code} {response.reason}")
|
2023-10-23 07:46:25 +00:00
|
|
|
if len(_split) > 1:
|
|
|
|
yield _split[1].strip()
|
|
|
|
else:
|
2023-11-20 12:59:14 +00:00
|
|
|
yield _split[0].strip()
|