返回提交历史
Added
g4f/Provider/FakeGpt.py
+94
-0
Modified
g4f/Provider/__init__.py
+3
-0
Modified
g4f/models.py
+11
-15
XFEstudio/gpt4free
Add FakeGpt Provider Update providers in models
a3af9fac
代码差异
3 个文件
+108
-15
@@ -0,0 +1,94 @@
1
from __future__ import annotations
2
3
import uuid, time, random, string, json
4
from aiohttp import ClientSession
5
6
from ..typing import AsyncResult, Messages
7
from .base_provider import AsyncGeneratorProvider
8
from .helper import format_prompt
9
10
11
class FakeGpt(AsyncGeneratorProvider):
12
url = "https://chat-shared2.zhile.io"
13
supports_gpt_35_turbo = True
14
working = True
15
_access_token = None
16
_cookie_jar = None
17
18
@classmethod
19
async def create_async_generator(
20
cls,
21
model: str,
22
messages: Messages,
23
proxy: str = None,
24
**kwargs
25
) -> AsyncResult:
26
headers = {
27
"Accept-Language": "en-US",
28
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36",
29
"Referer": "https://chat-shared2.zhile.io/?v=2",
30
"sec-ch-ua": '"Google Chrome";v="117", "Not;A=Brand";v="8", "Chromium";v="117"',
31
"sec-ch-ua-platform": '"Linux"',
32
"sec-ch-ua-mobile": "?0",
33
}
34
async with ClientSession(headers=headers, cookie_jar=cls._cookie_jar) as session:
35
if not cls._access_token:
36
async with session.get(f"{cls.url}/api/loads", params={"t": int(time.time())}, proxy=proxy) as response:
37
response.raise_for_status()
38
list = (await response.json())["loads"]
39
token_ids = [t["token_id"] for t in list if t["count"] == 0]
40
data = {
41
"token_key": random.choice(token_ids),
42
"session_password": random_string()
43
}
44
async with session.post(f"{cls.url}/auth/login", data=data, proxy=proxy) as response:
45
response.raise_for_status()
46
async with session.get(f"{cls.url}/api/auth/session", proxy=proxy) as response:
47
response.raise_for_status()
48
cls._access_token = (await response.json())["accessToken"]
49
cls._cookie_jar = session.cookie_jar
50
headers = {
51
"Content-Type": "application/json",
52
"Accept": "text/event-stream",
53
"X-Authorization": f"Bearer {cls._access_token}",
54
}
55
prompt = format_prompt(messages)
56
data = {
57
"action": "next",
58
"messages": [
59
{
60
"id": str(uuid.uuid4()),
61
"author": {"role": "user"},
62
"content": {"content_type": "text", "parts": [prompt]},
63
"metadata": {},
64
}
65
],
66
"parent_message_id": str(uuid.uuid4()),
67
"model": "text-davinci-002-render-sha",
68
"plugin_ids": [],
69
"timezone_offset_min": -120,
70
"suggestions": [],
71
"history_and_training_disabled": True,
72
"arkose_token": "",
73
"force_paragen": False,
74
}
75
last_message = ""
76
async with session.post(f"{cls.url}/api/conversation", json=data, headers=headers, proxy=proxy) as response:
77
async for line in response.content:
78
if line.startswith(b"data: "):
79
line = line[6:]
80
if line == b"[DONE]":
81
break
82
try:
83
line = json.loads(line)
84
if line["message"]["metadata"]["message_type"] == "next":
85
new_message = line["message"]["content"]["parts"][0]
86
yield new_message[len(last_message):]
87
last_message = new_message
88
except:
89
continue
90
if not last_message:
91
raise RuntimeError("No valid response")
92
93
def random_string(length: int = 10):
94
return ''.join(random.choice(string.ascii_lowercase + string.digits) for _ in range(length))
@@ -17,6 +17,7 @@ from .ChatgptFree import ChatgptFree
17
17
from .ChatgptLogin import ChatgptLogin
18
18
from .ChatgptX import ChatgptX
19
19
from .Cromicle import Cromicle
20
from .FakeGpt import FakeGpt
20
21
from .FreeGpt import FreeGpt
21
22
from .GPTalk import GPTalk
22
23
from .GptChatly import GptChatly
@@ -73,6 +74,7 @@ class ProviderUtils:
73
74
'Equing': Equing,
74
75
'FastGpt': FastGpt,
75
76
'Forefront': Forefront,
77
'FakeGpt': FakeGpt,
76
78
'FreeGpt': FreeGpt,
77
79
'GPTalk': GPTalk,
78
80
'GptChatly': GptChatly,
@@ -143,6 +145,7 @@ __all__ = [
143
145
'DfeHub',
144
146
'EasyChat',
145
147
'Forefront',
148
'FakeGpt',
146
149
'FreeGpt',
147
150
'GPTalk',
148
151
'GptChatly',
@@ -4,19 +4,18 @@ from .typing import Union
4
4
from .Provider import BaseProvider, RetryProvider
5
5
from .Provider import (
6
6
ChatgptLogin,
7
ChatgptDemo,
8
7
ChatgptDuo,
9
8
GptForLove,
10
Opchatgpts,
11
9
ChatgptAi,
12
10
GptChatly,
13
11
Liaobots,
14
12
ChatgptX,
13
ChatBase,
15
14
Yqcloud,
16
15
GeekGpt,
16
FakeGpt,
17
17
Myshell,
18
18
FreeGpt,
19
Cromicle,
20
19
NoowAi,
21
20
Vercel,
22
21
Aichat,
@@ -30,9 +29,6 @@ from .Provider import (
30
29
Bing,
31
30
You,
32
31
H2o,
33
34
ChatForAi,
35
ChatBase
36
32
)
37
33
38
34
@dataclass(unsafe_hash=True)
@@ -50,9 +46,8 @@ default = Model(
50
46
base_provider = "",
51
47
best_provider = RetryProvider([
52
48
Bing, # Not fully GPT 3 or 4
53
Yqcloud, # Answers short questions in chinese
54
ChatgptDuo, # Include search results
55
Aibn, Aichat, ChatgptAi, ChatgptLogin, FreeGpt, GptGo, Myshell, Ylokh, GeekGpt
49
AiAsk, Aichat, ChatgptAi, FreeGpt, GptGo, GeekGpt,
50
Phind, You
56
51
])
57
52
)
58
53
@@ -61,9 +56,10 @@ gpt_35_long = Model(
61
56
name = 'gpt-3.5-turbo',
62
57
base_provider = 'openai',
63
58
best_provider = RetryProvider([
64
AiAsk, Aichat, ChatgptDemo, FreeGpt, Liaobots, You,
65
GPTalk, ChatgptLogin, GptChatly, GptForLove, Opchatgpts,
66
NoowAi, GeekGpt, Phind
59
AiAsk, Aichat, FreeGpt, You,
60
GptChatly, GptForLove,
61
NoowAi, GeekGpt, Phind,
62
FakeGpt
67
63
])
68
64
)
69
65
@@ -72,8 +68,8 @@ gpt_35_turbo = Model(
72
68
name = 'gpt-3.5-turbo',
73
69
base_provider = 'openai',
74
70
best_provider=RetryProvider([
75
ChatgptX, ChatgptDemo, GptGo, You,
76
NoowAi, GPTalk, GptForLove, Phind, ChatBase, Cromicle
71
ChatgptX, GptGo, You,
72
NoowAi, GPTalk, GptForLove, Phind, ChatBase
77
73
])
78
74
)
79
75
@@ -81,7 +77,7 @@ gpt_4 = Model(
81
77
name = 'gpt-4',
82
78
base_provider = 'openai',
83
79
best_provider = RetryProvider([
84
Bing, GeekGpt, Liaobots, Phind
80
Bing, GeekGpt, Phind
85
81
])
86
82
)
87
83