返回提交历史
Modified
g4f/Provider/AItianhu.py
+18
-41
Added
g4f/Provider/GptGo.py
+78
-0
Modified
g4f/Provider/__init__.py
+2
-0
XFEstudio/gpt4free
Add GptGo Provider, Fix AItianhu Provider
e8d7bcd0
代码差异
3 个文件
+98
-41
@@ -1,61 +1,38 @@
1
1
from __future__ import annotations
2
2
3
3
import json
4
from aiohttp import ClientSession, http
4
from curl_cffi.requests import AsyncSession
5
5
6
from ..typing import AsyncGenerator
7
from .base_provider import AsyncGeneratorProvider, format_prompt
6
from .base_provider import AsyncProvider, format_prompt
8
7
9
8
10
class AItianhu(AsyncGeneratorProvider):
9
class AItianhu(AsyncProvider):
11
10
url = "https://www.aitianhu.com"
12
11
working = True
13
12
supports_gpt_35_turbo = True
14
13
15
14
@classmethod
16
async def create_async_generator(
15
async def create_async(
17
16
cls,
18
17
model: str,
19
18
messages: list[dict[str, str]],
20
19
proxy: str = None,
21
20
**kwargs
22
) -> AsyncGenerator:
23
headers = {
24
"User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/116.0",
25
"Accept": "application/json, text/plain, */*",
26
"Accept-Language": "de,en-US;q=0.7,en;q=0.3",
27
"Content-Type": "application/json",
28
"Origin": cls.url,
29
"Connection": "keep-alive",
30
"Referer": cls.url + "/",
31
"Sec-Fetch-Dest": "empty",
32
"Sec-Fetch-Mode": "cors",
33
"Sec-Fetch-Site": "same-origin",
21
) -> str:
22
data = {
23
"prompt": format_prompt(messages),
24
"options": {},
25
"systemMessage": "You are ChatGPT, a large language model trained by OpenAI. Follow the user's instructions carefully.",
26
"temperature": 0.8,
27
"top_p": 1,
28
**kwargs
34
29
}
35
async with ClientSession(
36
headers=headers,
37
version=http.HttpVersion10
38
) as session:
39
data = {
40
"prompt": format_prompt(messages),
41
"options": {},
42
"systemMessage": "You are ChatGPT, a large language model trained by OpenAI. Follow the user's instructions carefully.",
43
"temperature": 0.8,
44
"top_p": 1,
45
**kwargs
46
}
47
async with session.post(
48
cls.url + "/api/chat-process",
49
proxy=proxy,
50
json=data,
51
ssl=False,
52
) as response:
53
response.raise_for_status()
54
async for line in response.content:
55
line = json.loads(line.decode('utf-8'))
56
token = line["detail"]["choices"][0]["delta"].get("content")
57
if token:
58
yield token
30
async with AsyncSession(proxies={"https": proxy}, impersonate="chrome107", verify=False) as session:
31
response = await session.post(cls.url + "/api/chat-process", json=data)
32
response.raise_for_status()
33
line = response.text.splitlines()[-1]
34
line = json.loads(line)
35
return line["text"]
59
36
60
37
61
38
@classmethod
@@ -0,0 +1,78 @@
1
from __future__ import annotations
2
3
from aiohttp import ClientSession
4
import json
5
6
from ..typing import AsyncGenerator
7
from .base_provider import AsyncGeneratorProvider, format_prompt
8
9
10
class GptGo(AsyncGeneratorProvider):
11
url = "https://gptgo.ai"
12
supports_gpt_35_turbo = 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
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" : "*/*",
26
"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",
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
async with ClientSession(
34
headers=headers
35
) as session:
36
async with session.get(
37
"https://gptgo.ai/action_get_token.php",
38
params={
39
"q": format_prompt(messages),
40
"hlgpt": "default",
41
"hl": "en"
42
},
43
proxy=proxy
44
) as response:
45
response.raise_for_status()
46
token = (await response.json(content_type=None))["token"]
47
48
async with session.get(
49
"https://gptgo.ai/action_ai_gpt.php",
50
params={
51
"token": token,
52
},
53
proxy=proxy
54
) as response:
55
response.raise_for_status()
56
start = "data: "
57
async for line in response.content:
58
line = line.decode()
59
if line.startswith("data: "):
60
if line.startswith("data: [DONE]"):
61
break
62
line = json.loads(line[len(start):-1])
63
content = line["choices"][0]["delta"].get("content")
64
if content:
65
yield content
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})"
@@ -16,6 +16,7 @@ from .DfeHub import DfeHub
16
16
from .EasyChat import EasyChat
17
17
from .Forefront import Forefront
18
18
from .GetGpt import GetGpt
19
from .GptGo import GptGo
19
20
from .H2o import H2o
20
21
from .HuggingChat import HuggingChat
21
22
from .Liaobots import Liaobots
@@ -57,6 +58,7 @@ __all__ = [
57
58
'EasyChat',
58
59
'Forefront',
59
60
'GetGpt',
61
'GptGo',
60
62
'H2o',
61
63
'HuggingChat',
62
64
'Liaobots',