返回提交历史
Added
g4f/Provider/ChatBase.py
+62
-0
Modified
g4f/Provider/__init__.py
+2
-0
XFEstudio/gpt4free
Add ChatBase Provider
c2741a9a
代码差异
2 个文件
+64
-0
@@ -0,0 +1,62 @@
1
from __future__ import annotations
2
3
from aiohttp import ClientSession
4
5
from ..typing import AsyncGenerator
6
from .base_provider import AsyncGeneratorProvider
7
8
9
class ChatBase(AsyncGeneratorProvider):
10
url = "https://www.chatbase.co"
11
supports_gpt_35_turbo = True
12
supports_gpt_4 = True
13
working = True
14
15
@classmethod
16
async def create_async_generator(
17
cls,
18
model: str,
19
messages: list[dict[str, str]],
20
**kwargs
21
) -> AsyncGenerator:
22
if model == "gpt-4":
23
chat_id = "quran---tafseer-saadi-pdf-wbgknt7zn"
24
elif model == "gpt-3.5-turbo" or True:
25
chat_id = "chatbase--1--pdf-p680fxvnm"
26
headers = {
27
"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",
28
"Accept" : "*/*",
29
"Accept-language" : "en,fr-FR;q=0.9,fr;q=0.8,es-ES;q=0.7,es;q=0.6,en-US;q=0.5,am;q=0.4,de;q=0.3",
30
"Origin" : cls.url,
31
"Referer" : cls.url + "/",
32
"Sec-Fetch-Dest" : "empty",
33
"Sec-Fetch-Mode" : "cors",
34
"Sec-Fetch-Site" : "same-origin",
35
}
36
async with ClientSession(
37
headers=headers
38
) as session:
39
data = {
40
"messages": messages,
41
"captchaCode": "hadsa",
42
"chatId": chat_id,
43
"conversationId": f"kcXpqEnqUie3dnJlsRi_O-{chat_id}"
44
}
45
async with session.post("https://www.chatbase.co/api/fe/chat", json=data) as response:
46
response.raise_for_status()
47
async for stream in response.content.iter_any():
48
stream = stream.decode()
49
if stream:
50
yield stream
51
52
53
@classmethod
54
@property
55
def params(cls):
56
params = [
57
("model", "str"),
58
("messages", "list[dict[str, str]]"),
59
("stream", "bool"),
60
]
61
param = ", ".join([": ".join(p) for p in params])
62
return f"g4f.provider.{cls.__name__} supports: ({param})"
@@ -6,6 +6,7 @@ from .AiService import AiService
6
6
from .AItianhu import AItianhu
7
7
from .Bard import Bard
8
8
from .Bing import Bing
9
from .ChatBase import ChatBase
9
10
from .ChatgptAi import ChatgptAi
10
11
from .ChatgptLogin import ChatgptLogin
11
12
from .CodeLinkAva import CodeLinkAva
@@ -43,6 +44,7 @@ __all__ = [
43
44
'AItianhu',
44
45
'Bard',
45
46
'Bing',
47
'ChatBase',
46
48
'ChatgptAi',
47
49
'ChatgptLogin',
48
50
'CodeLinkAva',