返回提交历史
Added
g4f/Provider/Wuguokai.py
+65
-0
Modified
g4f/Provider/__init__.py
+3
-1
XFEstudio/gpt4free
add provider
0b5d1d3d
代码差异
2 个文件
+68
-1
@@ -0,0 +1,65 @@
1
import random, requests, json
2
from ..typing import Any, CreateResult
3
from .base_provider import BaseProvider
4
5
6
class Wuguokai(BaseProvider):
7
url = 'https://chat.wuguokai.xyz'
8
supports_gpt_35_turbo = True
9
supports_stream = False
10
needs_auth = False
11
working = True
12
13
@staticmethod
14
def create_completion(
15
model: str,
16
messages: list[dict[str, str]],
17
stream: bool,
18
**kwargs: Any,
19
) -> CreateResult:
20
base = ''
21
for message in messages:
22
base += '%s: %s\n' % (message['role'], message['content'])
23
base += 'assistant:'
24
25
headers = {
26
'authority': 'ai-api.wuguokai.xyz',
27
'accept': 'application/json, text/plain, */*',
28
'accept-language': 'id-ID,id;q=0.9,en-US;q=0.8,en;q=0.7',
29
'content-type': 'application/json',
30
'origin': 'https://chat.wuguokai.xyz',
31
'referer': 'https://chat.wuguokai.xyz/',
32
'sec-ch-ua': '"Not.A/Brand";v="8", "Chromium";v="114", "Google Chrome";v="114"',
33
'sec-ch-ua-mobile': '?0',
34
'sec-ch-ua-platform': '"Windows"',
35
'sec-fetch-dest': 'empty',
36
'sec-fetch-mode': 'cors',
37
'sec-fetch-site': 'same-site',
38
'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'
39
}
40
data ={
41
"prompt": base,
42
"options": {},
43
"userId": f"#/chat/{random.randint(1,99999999)}",
44
"usingContext": True
45
}
46
response = requests.post("https://ai-api20.wuguokai.xyz/api/chat-process", headers=headers, data=json.dumps(data),proxies=kwargs['proxy'] if 'proxy' in kwargs else {})
47
_split = response.text.split("> 若回答失败请重试或多刷新几次界面后重试")
48
if response.status_code == 200:
49
if len(_split) > 1:
50
yield _split[1].strip()
51
else:
52
yield _split[0].strip()
53
else:
54
raise Exception(f"Error: {response.status_code} {response.reason}")
55
56
@classmethod
57
@property
58
def params(cls):
59
params = [
60
("model", "str"),
61
("messages", "list[dict[str, str]]"),
62
("stream", "bool")
63
]
64
param = ", ".join([": ".join(p) for p in params])
65
return f"g4f.provider.{cls.__name__} supports: ({param})"
@@ -25,6 +25,7 @@ from .You import You
25
25
from .Yqcloud import Yqcloud
26
26
from .Equing import Equing
27
27
from .FastGpt import FastGpt
28
from .Wuguokai import Wuguokai
28
29
29
30
__all__ = [
30
31
"BaseProvider",
@@ -53,5 +54,6 @@ __all__ = [
53
54
"You",
54
55
"Yqcloud",
55
56
"Equing",
56
"FastGpt"
57
"FastGpt",
58
"Wuguokai"
57
59
]