返回提交历史
Added
g4f/Provider/Bestim.py
+78
-0
Modified
g4f/Provider/__init__.py
+1
-0
XFEstudio/gpt4free
New Provider 'Bestim' (#1416)
* Add new provider Bestim
90c80f80
代码差异
2 个文件
+79
-0
@@ -0,0 +1,78 @@
1
from __future__ import annotations
2
3
from ..typing import Messages, List, Dict
4
from .base_provider import BaseProvider, CreateResult
5
from uuid import uuid4
6
import requests
7
8
def format_prompt(messages) -> List[Dict[str, str]]:
9
10
return [{"id": str(uuid4()), "content": '\n'.join(f'{m["role"]}: {m["content"]}' for m in messages), "from": "you"}]
11
12
class Bestim(BaseProvider):
13
url = "https://chatgpt.bestim.org"
14
supports_gpt_35_turbo = True
15
supports_message_history = True
16
working = True
17
supports_stream = True
18
19
@staticmethod
20
def create_completion(
21
model: str,
22
messages: Messages,
23
stream: bool,
24
proxy: str = None,
25
**kwargs
26
) -> CreateResult:
27
28
headers = {
29
'POST': '/chat/send2/ HTTP/3',
30
'Host': 'chatgpt.bestim.org',
31
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:121.0) Gecko/20100101 Firefox/121.0',
32
'Accept': 'application/json, text/event-stream',
33
'Accept-Language': 'en-US,en;q=0.5',
34
'Accept-Encoding': 'gzip, deflate, br',
35
'Referer': 'https://chatgpt.bestim.org/chat/',
36
'Content-Type': 'application/json',
37
'Content-Length': '109',
38
'Origin': 'https://chatgpt.bestim.org',
39
'Cookie': 'NpZAER=qKkRHguMIOraVbJAWpoyzGLFjZwYlm; qKkRHguMIOraVbJAWpoyzGLFjZwYlm=8ebb5ae1561bde05354de5979b52c6e1-1704058188-1704058188; NpZAER_hits=2; _csrf-front=fcf20965823c0a152ae8f9cdf15b23022bb26cdc6bf32a9d4c8bfe78dcc6b807a%3A2%3A%7Bi%3A0%3Bs%3A11%3A%22_csrf-front%22%3Bi%3A1%3Bs%3A32%3A%22a5wP6azsc7dxV8rmwAXaNsl8XS1yvW5V%22%3B%7D',
40
'Alt-Used': 'chatgpt.bestim.org',
41
'Connection': 'keep-alive',
42
'Sec-Fetch-Dest': 'empty',
43
'Sec-Fetch-Mode': 'cors',
44
'Sec-Fetch-Site': 'same-origin',
45
'TE': 'trailers'
46
}
47
48
data = {
49
50
"messagesHistory": format_prompt(messages),
51
"type": "chat",
52
}
53
54
response = requests.post(
55
url="https://chatgpt.bestim.org/chat/send2/",
56
headers=headers,
57
json=data,
58
proxies={"https": proxy}
59
)
60
61
response.raise_for_status()
62
63
for chunk in response.iter_lines():
64
65
if b"event: trylimit" not in chunk:
66
67
yield chunk.decode().removeprefix("data: ")
68
69
70
71
72
73
74
75
76
77
78
@@ -54,6 +54,7 @@ from .Ylokh import Ylokh
54
54
from .You import You
55
55
from .Yqcloud import Yqcloud
56
56
from .GeekGpt import GeekGpt
57
from .Bestim import Bestim
57
58
58
59
import sys
59
60