返回提交历史
Modified
g4f/Provider/Theb.py
+72
-15
XFEstudio/gpt4free
fix theb but need auth
b3621b87
代码差异
1 个文件
+72
-15
@@ -1,16 +1,15 @@
1
import json
2
3
from curl_cffi import requests
4
1
import json,random,requests
2
# from curl_cffi import requests
5
3
from ..typing import Any, CreateResult
6
4
from .base_provider import BaseProvider
7
5
8
6
9
7
class Theb(BaseProvider):
10
8
url = "https://theb.ai"
11
working = False
9
working = True
12
10
supports_stream = True
13
11
supports_gpt_35_turbo = True
12
needs_auth = True
14
13
15
14
@staticmethod
16
15
def create_completion(
@@ -19,21 +18,79 @@ class Theb(BaseProvider):
19
18
stream: bool,
20
19
**kwargs: Any,
21
20
) -> CreateResult:
22
prompt = messages[-1]["content"]
23
21
conversation = ''
22
for message in messages:
23
conversation += '%s: %s\n' % (message['role'], message['content'])
24
25
conversation += 'assistant: '
26
auth = kwargs.get("auth", {
27
"bearer_token":"free",
28
"org_id":"theb",
29
})
30
bearer_token = auth["bearer_token"]
31
org_id = auth["org_id"]
24
32
headers = {
25
"accept": "application/json, text/plain, */*",
26
"content-type": "application/json",
33
'authority': 'beta.theb.ai',
34
'accept': 'text/event-stream',
35
'accept-language': 'id-ID,id;q=0.9,en-US;q=0.8,en;q=0.7',
36
'authorization': 'Bearer '+bearer_token,
37
'content-type': 'application/json',
38
'origin': 'https://beta.theb.ai',
39
'referer': 'https://beta.theb.ai/home',
40
'sec-ch-ua': '"Chromium";v="116", "Not)A;Brand";v="24", "Google Chrome";v="116"',
41
'sec-ch-ua-mobile': '?0',
42
'sec-ch-ua-platform': '"Windows"',
43
'sec-fetch-dest': 'empty',
44
'sec-fetch-mode': 'cors',
45
'sec-fetch-site': 'same-origin',
46
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36',
47
'x-ai-model': 'ee8d4f29cb7047f78cbe84313ed6ace8',
27
48
}
49
# generate 10 random number
50
# 0.1 - 0.9
51
req_rand = random.randint(100000000, 9999999999)
28
52
29
json_data: dict[str, Any] = {"prompt": prompt, "options": {}}
53
json_data: dict[str, Any] = {
54
"text": conversation,
55
"category": "04f58f64a4aa4191a957b47290fee864",
56
"model": "ee8d4f29cb7047f78cbe84313ed6ace8",
57
"model_params": {
58
"system_prompt": "You are ChatGPT, a large language model trained by OpenAI, based on the GPT-3.5 architecture.\nKnowledge cutoff: 2021-09\nCurrent date: {{YYYY-MM-DD}}",
59
"temperature": kwargs.get("temperature", 1),
60
"top_p": kwargs.get("top_p", 1),
61
"frequency_penalty": kwargs.get("frequency_penalty", 0),
62
"presence_penalty": kwargs.get("presence_penalty", 0),
63
"long_term_memory": "auto"
64
}
65
}
30
66
response = requests.post(
31
"https://chatbot.theb.ai/api/chat-process",
67
"https://beta.theb.ai/api/conversation?org_id="+org_id+"&req_rand="+str(req_rand),
32
68
headers=headers,
33
69
json=json_data,
34
impersonate="chrome110",
70
stream=True,
35
71
)
36
72
response.raise_for_status()
37
line = response.text.splitlines()[-1]
38
text = json.loads(line)["text"]
39
yield text
73
content = ""
74
next_content = ""
75
for chunk in response.iter_lines():
76
if b"content" in chunk:
77
next_content = content
78
data = json.loads(chunk.decode().split("data: ")[1])
79
content = data["content"]
80
yield data["content"].replace(next_content, "")
81
82
@classmethod
83
@property
84
def params(cls):
85
params = [
86
("model", "str"),
87
("messages", "list[dict[str, str]]"),
88
("auth", "list[dict[str, str]]"),
89
("stream", "bool"),
90
("temperature", "float"),
91
("presence_penalty", "int"),
92
("frequency_penalty", "int"),
93
("top_p", "int")
94
]
95
param = ", ".join([": ".join(p) for p in params])
96
return f"g4f.provider.{cls.__name__} supports: ({param})"