返回提交历史
Added
g4f/Provider/Allyfy.py
+71
-0
Added
g4f/Provider/ChatGot.py
+75
-0
Modified
g4f/Provider/Chatgpt4Online.py
+50
-51
Modified
g4f/Provider/GeminiProChat.py
+2
-2
Modified
g4f/Provider/HuggingChat.py
+2
-1
Modified
g4f/Provider/HuggingFace.py
+3
-2
Modified
g4f/Provider/Liaobots.py
+37
-8
Modified
g4f/Provider/PerplexityLabs.py
+1
-14
Modified
g4f/Provider/Pi.py
+2
-1
Modified
g4f/Provider/ReplicateHome.py
+27
-21
Modified
g4f/Provider/You.py
+10
-10
Modified
g4f/Provider/__init__.py
+2
-0
Modified
g4f/Provider/needs_auth/Openai.py
+2
-1
Modified
g4f/Provider/needs_auth/OpenaiChat.py
+1
-1
Modified
g4f/models.py
+201
-49
XFEstudio/gpt4free
Comprehensive Update: New Providers, Model Enhancements, and Functionality Improvements
29c13e26
代码差异
15 个文件
+486
-161
@@ -0,0 +1,71 @@
1
from __future__ import annotations
2
3
from aiohttp import ClientSession
4
import json
5
6
from ..typing import AsyncResult, Messages
7
from .base_provider import AsyncGeneratorProvider
8
from .helper import format_prompt
9
10
11
class Allyfy(AsyncGeneratorProvider):
12
url = "https://chatbot.allyfy.chat"
13
api_endpoint = "/api/v1/message/stream/super/chat"
14
working = True
15
supports_gpt_35_turbo = True
16
17
@classmethod
18
async def create_async_generator(
19
cls,
20
model: str,
21
messages: Messages,
22
proxy: str = None,
23
**kwargs
24
) -> AsyncResult:
25
headers = {
26
"accept": "text/event-stream",
27
"accept-language": "en-US,en;q=0.9",
28
"content-type": "application/json;charset=utf-8",
29
"dnt": "1",
30
"origin": "https://www.allyfy.chat",
31
"priority": "u=1, i",
32
"referer": "https://www.allyfy.chat/",
33
"referrer": "https://www.allyfy.chat",
34
'sec-ch-ua': '"Not/A)Brand";v="8", "Chromium";v="126"',
35
'sec-ch-ua-mobile': '?0',
36
'sec-ch-ua-platform': '"Linux"',
37
"sec-fetch-dest": "empty",
38
"sec-fetch-mode": "cors",
39
"sec-fetch-site": "same-site",
40
"user-agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36"
41
}
42
async with ClientSession(headers=headers) as session:
43
prompt = format_prompt(messages)
44
data = {
45
"messages": [{"content": prompt, "role": "user"}],
46
"content": prompt,
47
"baseInfo": {
48
"clientId": "q08kdrde1115003lyedfoir6af0yy531",
49
"pid": "38281",
50
"channelId": "100000",
51
"locale": "en-US",
52
"localZone": 180,
53
"packageName": "com.cch.allyfy.webh",
54
}
55
}
56
async with session.post(f"{cls.url}{cls.api_endpoint}", json=data, proxy=proxy) as response:
57
response.raise_for_status()
58
full_response = []
59
async for line in response.content:
60
line = line.decode().strip()
61
if line.startswith("data:"):
62
data_content = line[5:]
63
if data_content == "[DONE]":
64
break
65
try:
66
json_data = json.loads(data_content)
67
if "content" in json_data:
68
full_response.append(json_data["content"])
69
except json.JSONDecodeError:
70
continue
71
yield "".join(full_response)
@@ -0,0 +1,75 @@
1
from __future__ import annotations
2
3
import time
4
from hashlib import sha256
5
6
from aiohttp import BaseConnector, ClientSession
7
8
from ..errors import RateLimitError
9
from ..requests import raise_for_status
10
from ..requests.aiohttp import get_connector
11
from ..typing import AsyncResult, Messages
12
from .base_provider import AsyncGeneratorProvider, ProviderModelMixin
13
14
15
class ChatGot(AsyncGeneratorProvider, ProviderModelMixin):
16
url = "https://www.chatgot.one/"
17
working = True
18
supports_message_history = True
19
default_model = 'gemini-pro'
20
21
@classmethod
22
async def create_async_generator(
23
cls,
24
model: str,
25
messages: Messages,
26
proxy: str = None,
27
connector: BaseConnector = None,
28
**kwargs,
29
) -> AsyncResult:
30
headers = {
31
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:122.0) Gecko/20100101 Firefox/122.0",
32
"Accept": "*/*",
33
"Accept-Language": "en-US,en;q=0.5",
34
"Accept-Encoding": "gzip, deflate, br",
35
"Content-Type": "text/plain;charset=UTF-8",
36
"Referer": f"{cls.url}/",
37
"Origin": cls.url,
38
"Sec-Fetch-Dest": "empty",
39
"Sec-Fetch-Mode": "cors",
40
"Sec-Fetch-Site": "same-origin",
41
"Connection": "keep-alive",
42
"TE": "trailers",
43
}
44
async with ClientSession(
45
connector=get_connector(connector, proxy), headers=headers
46
) as session:
47
timestamp = int(time.time() * 1e3)
48
data = {
49
"messages": [
50
{
51
"role": "model" if message["role"] == "assistant" else "user",
52
"parts": [{"text": message["content"]}],
53
}
54
for message in messages
55
],
56
"time": timestamp,
57
"pass": None,
58
"sign": generate_signature(timestamp, messages[-1]["content"]),
59
}
60
async with session.post(
61
f"{cls.url}/api/generate", json=data, proxy=proxy
62
) as response:
63
if response.status == 500:
64
if "Quota exceeded" in await response.text():
65
raise RateLimitError(
66
f"Response {response.status}: Rate limit reached"
67
)
68
await raise_for_status(response)
69
async for chunk in response.content.iter_any():
70
yield chunk.decode(errors="ignore")
71
72
73
def generate_signature(time: int, text: str, secret: str = ""):
74
message = f"{time}:{text}:{secret}"
75
return sha256(message.encode()).hexdigest()
@@ -1,22 +1,18 @@
1
1
from __future__ import annotations
2
2
3
import re
4
3
import json
5
4
from aiohttp import ClientSession
6
5
7
from ..typing import Messages, AsyncResult
8
from ..requests import get_args_from_browser
9
from ..webdriver import WebDriver
6
from ..typing import AsyncResult, Messages
10
7
from .base_provider import AsyncGeneratorProvider
11
from .helper import get_random_string
8
from .helper import format_prompt
9
12
10
13
11
class Chatgpt4Online(AsyncGeneratorProvider):
14
12
url = "https://chatgpt4online.org"
15
supports_message_history = True
16
supports_gpt_35_turbo = True
17
working = True
18
_wpnonce = None
19
_context_id = None
13
api_endpoint = "/wp-json/mwai-ui/v1/chats/submit"
14
working = True
15
supports_gpt_4 = True
20
16
21
17
@classmethod
22
18
async def create_async_generator(
@@ -24,49 +20,52 @@ class Chatgpt4Online(AsyncGeneratorProvider):
24
20
model: str,
25
21
messages: Messages,
26
22
proxy: str = None,
27
webdriver: WebDriver = None,
28
23
**kwargs
29
24
) -> AsyncResult:
30
args = get_args_from_browser(f"{cls.url}/chat/", webdriver, proxy=proxy)
31
async with ClientSession(**args) as session:
32
if not cls._wpnonce:
33
async with session.get(f"{cls.url}/chat/", proxy=proxy) as response:
34
response.raise_for_status()
35
response = await response.text()
36
result = re.search(r'restNonce":"(.*?)"', response)
37
if result:
38
cls._wpnonce = result.group(1)
39
else:
40
raise RuntimeError("No nonce found")
41
result = re.search(r'contextId":(.*?),', response)
42
if result:
43
cls._context_id = result.group(1)
44
else:
45
raise RuntimeError("No contextId found")
25
headers = {
26
"accept": "text/event-stream",
27
"accept-language": "en-US,en;q=0.9",
28
"content-type": "application/json",
29
"dnt": "1",
30
"origin": cls.url,
31
"priority": "u=1, i",
32
"referer": f"{cls.url}/",
33
"sec-ch-ua": '"Not/A)Brand";v="8", "Chromium";v="126"',
34
"sec-ch-ua-mobile": "?0",
35
"sec-ch-ua-platform": '"Linux"',
36
"sec-fetch-dest": "empty",
37
"sec-fetch-mode": "cors",
38
"sec-fetch-site": "same-origin",
39
"user-agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36",
40
"x-wp-nonce": "d9505e9877",
41
}
42
43
async with ClientSession(headers=headers) as session:
44
prompt = format_prompt(messages)
46
45
data = {
47
"botId":"default",
48
"customId":None,
49
"session":"N/A",
50
"chatId":get_random_string(11),
51
"contextId":cls._context_id,
52
"messages":messages[:-1],
53
"newMessage":messages[-1]["content"],
54
"newImageId":None,
55
"stream":True
46
"botId": "default",
47
"newMessage": prompt,
48
"stream": True,
56
49
}
57
async with session.post(
58
f"{cls.url}/wp-json/mwai-ui/v1/chats/submit",
59
json=data,
60
proxy=proxy,
61
headers={"x-wp-nonce": cls._wpnonce}
62
) as response:
50
51
async with session.post(f"{cls.url}{cls.api_endpoint}", json=data, proxy=proxy) as response:
63
52
response.raise_for_status()
64
async for line in response.content:
65
if line.startswith(b"data: "):
66
line = json.loads(line[6:])
67
if "type" not in line:
68
raise RuntimeError(f"Response: {line}")
69
elif line["type"] == "live":
70
yield line["data"]
71
elif line["type"] == "end":
72
break
53
full_response = ""
54
55
async for chunk in response.content.iter_any():
56
if chunk:
57
try:
58
# Extract the JSON object from the chunk
59
for line in chunk.decode().splitlines():
60
if line.startswith("data: "):
61
json_data = json.loads(line[6:])
62
if json_data["type"] == "live":
63
full_response += json_data["data"]
64
elif json_data["type"] == "end":
65
final_data = json.loads(json_data["data"])
66
full_response = final_data["reply"]
67
break
68
except json.JSONDecodeError:
69
continue
70
71
yield full_response
@@ -13,10 +13,10 @@ from .base_provider import AsyncGeneratorProvider, ProviderModelMixin
13
13
14
14
15
15
class GeminiProChat(AsyncGeneratorProvider, ProviderModelMixin):
16
url = "https://www.chatgot.one/"
16
url = "https://gemini-pro.chat/"
17
17
working = True
18
18
supports_message_history = True
19
default_model = ''
19
default_model = 'gemini-pro'
20
20
21
21
@classmethod
22
22
async def create_async_generator(
@@ -13,8 +13,9 @@ class HuggingChat(AbstractProvider, ProviderModelMixin):
13
13
supports_stream = True
14
14
default_model = "mistralai/Mixtral-8x7B-Instruct-v0.1"
15
15
models = [
16
'meta-llama/Meta-Llama-3.1-70B-Instruct',
17
'meta-llama/Meta-Llama-3.1-405B-Instruct-FP8',
16
18
'CohereForAI/c4ai-command-r-plus',
17
'meta-llama/Meta-Llama-3-70B-Instruct',
18
19
'mistralai/Mixtral-8x7B-Instruct-v0.1',
19
20
'NousResearch/Nous-Hermes-2-Mixtral-8x7B-DPO',
20
21
'01-ai/Yi-1.5-34B-Chat',
@@ -14,16 +14,17 @@ class HuggingFace(AsyncGeneratorProvider, ProviderModelMixin):
14
14
working = True
15
15
needs_auth = True
16
16
supports_message_history = True
17
default_model = "mistralai/Mixtral-8x7B-Instruct-v0.1"
17
18
models = [
19
'meta-llama/Meta-Llama-3.1-70B-Instruct',
20
'meta-llama/Meta-Llama-3.1-405B-Instruct-FP8',
18
21
'CohereForAI/c4ai-command-r-plus',
19
'meta-llama/Meta-Llama-3-70B-Instruct',
20
22
'mistralai/Mixtral-8x7B-Instruct-v0.1',
21
23
'NousResearch/Nous-Hermes-2-Mixtral-8x7B-DPO',
22
24
'01-ai/Yi-1.5-34B-Chat',
23
25
'mistralai/Mistral-7B-Instruct-v0.2',
24
26
'microsoft/Phi-3-mini-4k-instruct',
25
27
]
26
default_model = "mistralai/Mixtral-8x7B-Instruct-v0.1"
27
28
28
29
@classmethod
29
30
async def create_async_generator(
@@ -10,14 +10,23 @@ from .helper import get_connector
10
10
from ..requests import raise_for_status
11
11
12
12
models = {
13
"gpt-3.5-turbo": {
14
"id": "gpt-3.5-turbo",
15
"name": "GPT-3.5-Turbo",
13
"gpt-4o-mini-free": {
14
"id": "gpt-4o-mini-free",
15
"name": "GPT-4o-Mini-Free",
16
16
"model": "ChatGPT",
17
17
"provider": "OpenAI",
18
"maxLength": 48000,
19
"tokenLimit": 14000,
20
"context": "16K",
18
"maxLength": 31200,
19
"tokenLimit": 7800,
20
"context": "8K",
21
},
22
"gpt-4o-mini": {
23
"id": "gpt-4o-mini",
24
"name": "GPT-4o-Mini",
25
"model": "ChatGPT",
26
"provider": "OpenAI",
27
"maxLength": 260000,
28
"tokenLimit": 126000,
29
"context": "128K",
21
30
},
22
31
"gpt-4o-free": {
23
32
"context": "8K",
@@ -91,6 +100,15 @@ models = {
91
100
"tokenLimit": 200000,
92
101
"context": "200K",
93
102
},
103
"claude-3-5-sonnet-20240620": {
104
"id": "claude-3-5-sonnet-20240620",
105
"name": "Claude-3.5-Sonnet",
106
"model": "Claude",
107
"provider": "Anthropic",
108
"maxLength": 800000,
109
"tokenLimit": 200000,
110
"context": "200K",
111
},
94
112
"claude-3-haiku-20240307": {
95
113
"id": "claude-3-haiku-20240307",
96
114
"name": "Claude-3-Haiku",
@@ -155,10 +173,21 @@ class Liaobots(AsyncGeneratorProvider, ProviderModelMixin):
155
173
supports_system_message = True
156
174
supports_gpt_35_turbo = True
157
175
supports_gpt_4 = True
158
default_model = "gpt-3.5-turbo"
176
default_model = "gpt-4o"
159
177
models = list(models.keys())
160
178
model_aliases = {
161
"claude-v2": "claude-2.0"
179
"gpt-4o-mini": "gpt-4o-mini-free",
180
"gpt-4o": "gpt-4o-free",
181
"claude-3-opus": "claude-3-opus-20240229",
182
"claude-3-opus": "claude-3-opus-20240229-aws",
183
"claude-3-opus": "claude-3-opus-20240229-gcp",
184
"claude-3-sonnet": "claude-3-sonnet-20240229",
185
"claude-3-5-sonnet": "claude-3-5-sonnet-20240620",
186
"claude-3-haiku": "claude-3-haiku-20240307",
187
"gpt-4-turbo": "gpt-4-turbo-2024-04-09",
188
"gemini-pro": "gemini-1.5-pro-latest",
189
"gemini-pro": "gemini-1.0-pro-latest",
190
"gemini-flash": "gemini-1.5-flash-latest",
162
191
}
163
192
_auth_code = ""
164
193
_cookie_jar = None
@@ -15,21 +15,8 @@ class PerplexityLabs(AsyncGeneratorProvider, ProviderModelMixin):
15
15
working = True
16
16
default_model = "mixtral-8x7b-instruct"
17
17
models = [
18
"llama-3-sonar-large-32k-online", "llama-3-sonar-small-32k-online", "llama-3-sonar-large-32k-chat", "llama-3-sonar-small-32k-chat",
19
"dbrx-instruct", "claude-3-haiku-20240307", "llama-3-8b-instruct", "llama-3-70b-instruct", "codellama-70b-instruct", "mistral-7b-instruct",
20
"llava-v1.5-7b-wrapper", "llava-v1.6-34b", "mixtral-8x7b-instruct", "mixtral-8x22b-instruct", "mistral-medium", "gemma-2b-it", "gemma-7b-it",
21
"related"
18
"llama-3-sonar-large-32k-online", "llama-3-sonar-small-32k-online", "llama-3-sonar-large-32k-chat", "llama-3-sonar-small-32k-chat", "llama-3-8b-instruct", "llama-3-70b-instruct", "gemma-2-9b-it", "gemma-2-27b-it", "nemotron-4-340b-instruct", "mixtral-8x7b-instruct",
22
19
]
23
model_aliases = {
24
"mistralai/Mistral-7B-Instruct-v0.1": "mistral-7b-instruct",
25
"mistralai/Mistral-7B-Instruct-v0.2": "mistral-7b-instruct",
26
"mistralai/Mixtral-8x7B-Instruct-v0.1": "mixtral-8x7b-instruct",
27
"codellama/CodeLlama-70b-Instruct-hf": "codellama-70b-instruct",
28
"llava-v1.5-7b": "llava-v1.5-7b-wrapper",
29
"databricks/dbrx-instruct": "dbrx-instruct",
30
"meta-llama/Meta-Llama-3-70B-Instruct": "llama-3-70b-instruct",
31
"meta-llama/Meta-Llama-3-8B-Instruct": "llama-3-8b-instruct"
32
}
33
20
34
21
@classmethod
35
22
async def create_async_generator(
@@ -11,6 +11,7 @@ class Pi(AbstractProvider):
11
11
working = True
12
12
supports_stream = True
13
13
_session = None
14
default_model = "pi"
14
15
15
16
@classmethod
16
17
def create_completion(
@@ -65,4 +66,4 @@ class Pi(AbstractProvider):
65
66
yield json.loads(line.split(b'data: ')[1])
66
67
elif line.startswith(b'data: {"title":'):
67
68
yield json.loads(line.split(b'data: ')[1])
68
69
@@ -14,40 +14,46 @@ class ReplicateHome(AsyncGeneratorProvider, ProviderModelMixin):
14
14
url = "https://replicate.com"
15
15
parent = "Replicate"
16
16
working = True
17
default_model = 'stability-ai/sdxl'
17
default_model = 'stability-ai/stable-diffusion-3'
18
18
models = [
19
# image
20
'stability-ai/sdxl',
21
'ai-forever/kandinsky-2.2',
19
# Models for image generation
20
'stability-ai/stable-diffusion-3',
21
'bytedance/sdxl-lightning-4step',
22
'playgroundai/playground-v2.5-1024px-aesthetic',
22
23
23
# text
24
'meta/llama-2-70b-chat',
25
'mistralai/mistral-7b-instruct-v0.2'
24
# Models for image generation
25
'meta/meta-llama-3-70b-instruct',
26
'mistralai/mixtral-8x7b-instruct-v0.1',
27
'google-deepmind/gemma-2b-it',
26
28
]
27
29
28
30
versions = {
29
# image
30
'stability-ai/sdxl': [
31
"39ed52f2a78e934b3ba6e2a89f5b1c712de7dfea535525255b1aa35c5565e08b",
32
"2b017d9b67edd2ee1401238df49d75da53c523f36e363881e057f5dc3ed3c5b2",
33
"7762fd07cf82c948538e41f63f77d685e02b063e37e496e96eefd46c929f9bdc"
31
# Model versions for generating images
32
'stability-ai/stable-diffusion-3': [
33
"527d2a6296facb8e47ba1eaf17f142c240c19a30894f437feee9b91cc29d8e4f"
34
34
],
35
'ai-forever/kandinsky-2.2': [
36
"ad9d7879fbffa2874e1d909d1d37d9bc682889cc65b31f7bb00d2362619f194a"
35
'bytedance/sdxl-lightning-4step': [
36
"5f24084160c9089501c1b3545d9be3c27883ae2239b6f412990e82d4a6210f8f"
37
],
38
'playgroundai/playground-v2.5-1024px-aesthetic': [
39
"a45f82a1382bed5c7aeb861dac7c7d191b0fdf74d8d57c4a0e6ed7d4d0bf7d24"
37
40
],
38
39
41
40
# Text
41
'meta/llama-2-70b-chat': [
42
"dp-542693885b1777c98ef8c5a98f2005e7"
42
43
# Model versions for text generation
44
'meta/meta-llama-3-70b-instruct': [
45
"dp-cf04fe09351e25db628e8b6181276547"
43
46
],
44
'mistralai/mistral-7b-instruct-v0.2': [
47
'mistralai/mixtral-8x7b-instruct-v0.1': [
45
48
"dp-89e00f489d498885048e94f9809fbc76"
49
],
50
'google-deepmind/gemma-2b-it': [
51
"dff94eaf770e1fc211e425a50b51baa8e4cac6c39ef074681f9e39d778773626"
46
52
]
47
53
}
48
54
49
image_models = {"stability-ai/sdxl", "ai-forever/kandinsky-2.2"}
50
text_models = {"meta/llama-2-70b-chat", "mistralai/mistral-7b-instruct-v0.2"}
55
image_models = {"stability-ai/stable-diffusion-3", "bytedance/sdxl-lightning-4step", "playgroundai/playground-v2.5-1024px-aesthetic"}
56
text_models = {"meta/meta-llama-3-70b-instruct", "mistralai/mixtral-8x7b-instruct-v0.1", "google-deepmind/gemma-2b-it"}
51
57
52
58
@classmethod
53
59
async def create_async_generator(
@@ -24,27 +24,27 @@ class You(AsyncGeneratorProvider, ProviderModelMixin):
24
24
image_models = ["dall-e"]
25
25
models = [
26
26
default_model,
27
"gpt-4o-mini",
27
28
"gpt-4o",
28
"gpt-4",
29
29
"gpt-4-turbo",
30
"claude-instant",
31
"claude-2",
30
"gpt-4",
31
"claude-3.5-sonnet",
32
32
"claude-3-opus",
33
33
"claude-3-sonnet",
34
34
"claude-3-haiku",
35
"gemini-pro",
35
"claude-2",
36
"llama-3.1-70b",
37
"llama-3",
38
"gemini-1-5-flash",
36
39
"gemini-1-5-pro",
40
"gemini-1-0-pro",
37
41
"databricks-dbrx-instruct",
38
42
"command-r",
39
43
"command-r-plus",
40
"llama3",
41
"zephyr",
44
"dolphin-2.5",
42
45
default_vision_model,
43
46
*image_models
44
47
]
45
model_aliases = {
46
"claude-v2": "claude-2",
47
}
48
48
_cookies = None
49
49
_cookies_used = 0
50
50
_telemetry_ids = []
@@ -220,4 +220,4 @@ class You(AsyncGeneratorProvider, ProviderModelMixin):
220
220
'stytch_session_jwt': session["session_jwt"],
221
221
'ydc_stytch_session': session["session_token"],
222
222
'ydc_stytch_session_jwt': session["session_jwt"],
223
}
223
}
@@ -11,10 +11,12 @@ from .selenium import *
11
11
from .needs_auth import *
12
12
13
13
from .AI365VIP import AI365VIP
14
from .Allyfy import Allyfy
14
15
from .Aura import Aura
15
16
from .Bing import Bing
16
17
from .BingCreateImages import BingCreateImages
17
18
from .Blackbox import Blackbox
19
from .ChatGot import ChatGot
18
20
from .Chatgpt4o import Chatgpt4o
19
21
from .Chatgpt4Online import Chatgpt4Online
20
22
from .ChatgptFree import ChatgptFree