返回提交历史
Added
g4f/Provider/Aivvm.py
+78
-0
Modified
g4f/Provider/ChatBase.py
+4
-4
Modified
g4f/Provider/Vercel.py
+1
-1
Added
g4f/Provider/Vitalentum.py
+66
-0
Added
g4f/Provider/Ylokh.py
+76
-0
Modified
g4f/Provider/You.py
+20
-20
Modified
g4f/Provider/__init__.py
+6
-0
XFEstudio/gpt4free
Add new providers: Aivvm, Vitalentum and Ylokh
d6382a21
代码差异
7 个文件
+251
-25
@@ -0,0 +1,78 @@
1
from __future__ import annotations
2
3
from aiohttp import ClientSession
4
5
from .base_provider import AsyncGeneratorProvider
6
from ..typing import AsyncGenerator
7
8
models = {
9
"gpt-4": {
10
"id": "gpt-4",
11
"name": "GPT-4",
12
},
13
"gpt-3.5-turbo": {
14
"id": "gpt-3.5-turbo",
15
"name": "GPT-3.5",
16
},
17
"gpt-3.5-turbo-16k": {
18
"id": "gpt-3.5-turbo-16k",
19
"name": "GPT-3.5-16k",
20
},
21
}
22
23
class Aivvm(AsyncGeneratorProvider):
24
url = "https://chat.aivvm.com"
25
working = True
26
supports_gpt_35_turbo = True
27
supports_gpt_4 = True
28
29
30
@classmethod
31
async def create_async_generator(
32
cls,
33
model: str,
34
messages: list[dict[str, str]],
35
proxy: str = None,
36
**kwargs
37
) -> AsyncGenerator:
38
model = model if model else "gpt-3.5-turbo"
39
if model not in models:
40
raise ValueError(f"Model are not supported: {model}")
41
headers = {
42
"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",
43
"Accept" : "*/*",
44
"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",
45
"Origin" : cls.url,
46
"Referer" : cls.url + "/",
47
"Sec-Fetch-Dest" : "empty",
48
"Sec-Fetch-Mode" : "cors",
49
"Sec-Fetch-Site" : "same-origin",
50
}
51
async with ClientSession(
52
headers=headers
53
) as session:
54
data = {
55
"temperature": 1,
56
"key": "",
57
"messages": messages,
58
"model": models[model],
59
"prompt": "",
60
**kwargs
61
}
62
async with session.post(cls.url + "/api/chat", json=data, proxy=proxy) as response:
63
response.raise_for_status()
64
async for stream in response.content.iter_any():
65
yield stream.decode()
66
67
68
@classmethod
69
@property
70
def params(cls):
71
params = [
72
("model", "str"),
73
("messages", "list[dict[str, str]]"),
74
("stream", "bool"),
75
("temperature", "float"),
76
]
77
param = ", ".join([": ".join(p) for p in params])
78
return f"g4f.provider.{cls.__name__} supports: ({param})"
@@ -21,8 +21,10 @@ class ChatBase(AsyncGeneratorProvider):
21
21
) -> AsyncGenerator:
22
22
if model == "gpt-4":
23
23
chat_id = "quran---tafseer-saadi-pdf-wbgknt7zn"
24
elif model == "gpt-3.5-turbo" or True:
24
elif model == "gpt-3.5-turbo" or not model:
25
25
chat_id = "chatbase--1--pdf-p680fxvnm"
26
else:
27
raise ValueError(f"Model are not supported: {model}")
26
28
headers = {
27
29
"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
30
"Accept" : "*/*",
@@ -45,9 +47,7 @@ class ChatBase(AsyncGeneratorProvider):
45
47
async with session.post("https://www.chatbase.co/api/fe/chat", json=data) as response:
46
48
response.raise_for_status()
47
49
async for stream in response.content.iter_any():
48
stream = stream.decode()
49
if stream:
50
yield stream
50
yield stream.decode()
51
51
52
52
53
53
@classmethod
@@ -55,7 +55,7 @@ class Vercel(AsyncProvider):
55
55
56
56
def _create_payload(model: str, messages: list[dict[str, str]]) -> dict[str, Any]:
57
57
if model not in model_info:
58
raise RuntimeError(f'Model "{model}" are not supported')
58
raise ValueError(f'Model are not supported: {model}')
59
59
default_params = model_info[model]["default_params"]
60
60
return {
61
61
"messages": messages,
@@ -0,0 +1,66 @@
1
from __future__ import annotations
2
3
import json
4
from aiohttp import ClientSession
5
6
from .base_provider import AsyncGeneratorProvider
7
from ..typing import AsyncGenerator
8
9
class Vitalentum(AsyncGeneratorProvider):
10
url = "https://app.vitalentum.io"
11
working = True
12
supports_gpt_35_turbo = True
13
14
15
@classmethod
16
async def create_async_generator(
17
cls,
18
model: str,
19
messages: list[dict[str, str]],
20
proxy: str = None,
21
**kwargs
22
) -> AsyncGenerator:
23
headers = {
24
"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",
25
"Accept" : "text/event-stream",
26
"Accept-language" : "de,en-US;q=0.7,en;q=0.3",
27
"Origin" : cls.url,
28
"Referer" : cls.url + "/",
29
"Sec-Fetch-Dest" : "empty",
30
"Sec-Fetch-Mode" : "cors",
31
"Sec-Fetch-Site" : "same-origin",
32
}
33
conversation = json.dumps({"history": [{
34
"speaker": "human" if message["role"] == "user" else "bot",
35
"text": message["content"],
36
} for message in messages]})
37
data = {
38
"conversation": conversation,
39
"temperature": 0.7,
40
**kwargs
41
}
42
async with ClientSession(
43
headers=headers
44
) as session:
45
async with session.post(cls.url + "/api/converse-edge", json=data, proxy=proxy) as response:
46
response.raise_for_status()
47
async for line in response.content:
48
line = line.decode()
49
if line.startswith("data: ") and not line.startswith("data: [DONE]"):
50
line = json.loads(line[6:-1])
51
content = line["choices"][0]["delta"].get("content")
52
if content:
53
yield content
54
55
56
@classmethod
57
@property
58
def params(cls):
59
params = [
60
("model", "str"),
61
("messages", "list[dict[str, str]]"),
62
("stream", "bool"),
63
("temperature", "float"),
64
]
65
param = ", ".join([": ".join(p) for p in params])
66
return f"g4f.provider.{cls.__name__} supports: ({param})"
@@ -0,0 +1,76 @@
1
from __future__ import annotations
2
3
import json
4
from aiohttp import ClientSession
5
6
from .base_provider import AsyncGeneratorProvider
7
from ..typing import AsyncGenerator
8
9
class Ylokh(AsyncGeneratorProvider):
10
url = "https://chat.ylokh.xyz"
11
working = True
12
supports_gpt_35_turbo = True
13
14
15
@classmethod
16
async def create_async_generator(
17
cls,
18
model: str,
19
messages: list[dict[str, str]],
20
stream: bool = True,
21
proxy: str = None,
22
**kwargs
23
) -> AsyncGenerator:
24
model = model if model else "gpt-3.5-turbo"
25
headers = {
26
"User-Agent" : "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/116.0",
27
"Accept" : "*/*",
28
"Accept-language" : "de,en-US;q=0.7,en;q=0.3",
29
"Origin" : cls.url,
30
"Referer" : cls.url + "/",
31
"Sec-Fetch-Dest" : "empty",
32
"Sec-Fetch-Mode" : "cors",
33
"Sec-Fetch-Site" : "same-origin",
34
}
35
data = {
36
"messages": messages,
37
"model": model,
38
"temperature": 1,
39
"presence_penalty": 0,
40
"top_p": 1,
41
"frequency_penalty": 0,
42
"allow_fallback": True,
43
"stream": stream,
44
**kwargs
45
}
46
async with ClientSession(
47
headers=headers
48
) as session:
49
async with session.post("https://chatapi.ylokh.xyz/v1/chat/completions", json=data, proxy=proxy) as response:
50
response.raise_for_status()
51
if stream:
52
async for line in response.content:
53
line = line.decode()
54
if line.startswith("data: ") and not line.startswith("data: [DONE]"):
55
line = json.loads(line[6:-1])
56
content = line["choices"][0]["delta"].get("content")
57
if content:
58
yield content
59
else:
60
chat = await response.json()
61
yield chat["choices"][0]["message"].get("content")
62
63
64
65
@classmethod
66
@property
67
def params(cls):
68
params = [
69
("model", "str"),
70
("messages", "list[dict[str, str]]"),
71
("stream", "bool"),
72
("proxy", "str"),
73
("temperature", "float"),
74
]
75
param = ", ".join([": ".join(p) for p in params])
76
return f"g4f.provider.{cls.__name__} supports: ({param})"
@@ -2,39 +2,39 @@ from __future__ import annotations
2
2
3
3
import json
4
4
5
from aiohttp import ClientSession
5
from curl_cffi.requests import AsyncSession
6
6
7
7
from ..typing import AsyncGenerator
8
from .base_provider import AsyncGeneratorProvider, format_prompt, get_cookies
8
from .base_provider import AsyncGeneratorProvider, format_prompt
9
9
10
10
11
11
class You(AsyncGeneratorProvider):
12
12
url = "https://you.com"
13
13
working = True
14
14
supports_gpt_35_turbo = True
15
supports_stream = True
15
supports_stream = False
16
16
17
@staticmethod
17
18
@classmethod
18
19
async def create_async_generator(
20
cls,
19
21
model: str,
20
22
messages: list[dict[str, str]],
21
cookies: dict = None,
23
proxy: str = None,
22
24
**kwargs,
23
25
) -> AsyncGenerator:
24
if not cookies:
25
cookies = get_cookies("you.com")
26
headers = {
27
"Accept": "text/event-stream",
28
"Referer": "https://you.com/search?fromSearchBar=true&tbm=youchat",
29
"User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/116.0"
30
}
31
async with ClientSession(headers=headers, cookies=cookies) as session:
32
async with session.get(
26
async with AsyncSession(proxies={"https": proxy}, impersonate="chrome107") as session:
27
headers = {
28
"Accept": "text/event-stream",
29
"Referer": "https://you.com/search?fromSearchBar=true&tbm=youchat",
30
}
31
response = await session.get(
33
32
"https://you.com/api/streamingSearch",
34
33
params={"q": format_prompt(messages), "domain": "youchat", "chat": ""},
35
) as response:
36
start = 'data: {"youChatToken": '
37
async for line in response.content:
38
line = line.decode('utf-8')
39
if line.startswith(start):
40
yield json.loads(line[len(start): -2])
34
headers=headers
35
)
36
response.raise_for_status()
37
start = 'data: {"youChatToken": '
38
for line in response.text.splitlines():
39
if line.startswith(start):
40
yield json.loads(line[len(start): -1])
@@ -4,6 +4,7 @@ from .Aichat import Aichat
4
4
from .Ails import Ails
5
5
from .AiService import AiService
6
6
from .AItianhu import AItianhu
7
from .Aivvm import Aivvm
7
8
from .Bard import Bard
8
9
from .Bing import Bing
9
10
from .ChatBase import ChatBase
@@ -25,7 +26,9 @@ from .OpenAssistant import OpenAssistant
25
26
from .Raycast import Raycast
26
27
from .Theb import Theb
27
28
from .Vercel import Vercel
29
from .Vitalentum import Vitalentum
28
30
from .Wewordle import Wewordle
31
from .Ylokh import Ylokh
29
32
from .You import You
30
33
from .Yqcloud import Yqcloud
31
34
from .Equing import Equing
@@ -42,6 +45,7 @@ __all__ = [
42
45
'Ails',
43
46
'AiService',
44
47
'AItianhu',
48
'Aivvm',
45
49
'Bard',
46
50
'Bing',
47
51
'ChatBase',
@@ -63,7 +67,9 @@ __all__ = [
63
67
'OpenAssistant',
64
68
'Theb',
65
69
'Vercel',
70
'Vitalentum',
66
71
'Wewordle',
72
'Ylokh',
67
73
'You',
68
74
'Yqcloud',
69
75
'Equing',