返回提交历史
Modified
README.md
+91
-14
Modified
g4f/Provider/Bing.py
+2
-19
Modified
g4f/Provider/Liaobots.py
+1
-0
Modified
g4f/Provider/Wuguokai.py
+2
-4
Modified
g4f/Provider/__init__.py
+1
-1
Modified
testing/test_needs_auth.py
+3
-3
Modified
tool/readme_table.py
+39
-9
XFEstudio/gpt4free
Set working=True in Liaobots, Fix bing provider, Update readme
3e6b1d6b
代码差异
7 个文件
+139
-50
@@ -118,25 +118,98 @@ for message in response:
118
118
print(message)
119
119
```
120
120
121
providers:
121
##### Providers:
122
122
```py
123
123
from g4f.Provider import (
124
124
Acytoo,
125
125
Aichat,
126
126
Ails,
127
AiService,
128
AItianhu,
129
127
Bard,
130
128
Bing,
131
129
ChatgptAi,
132
130
ChatgptLogin,
133
131
DeepAi,
134
GetGpt
132
EasyChat,
133
Equing,
134
GetGpt,
135
H2o,
136
HuggingChat,
137
Opchatgpts,
138
OpenAssistant,
139
OpenaiChat,
140
Raycast,
141
Theb,
142
Vercel,
143
Wewordle,
144
Wuguokai,
145
You,
146
Yqcloud
135
147
)
148
# Usage:
149
response = g4f.ChatCompletion.create(..., provider=ProviderName)
150
```
136
151
152
##### Needs cookies:
137
153
138
# usage:
139
response = g4f.ChatCompletion.create(..., provider=ProviderName)
154
Many providers need cookies to work.
155
In Bing you need a session, where you have passed the captcha.
156
And in others providers you have to log-in into your account.
157
If you run the g4l package locally,
158
cookies from your browsers are readed with `get_cookies`.
159
Else you have pass them in the parameter `cookies`:
160
```py
161
from g4f.Provider import (
162
Bard,
163
Bing,
164
H2o,
165
HuggingChat,
166
OpenAssistant,
167
OpenaiChat,
168
You,
169
)
170
# Usage:
171
response = g4f.ChatCompletion.create(
172
model=g4f.models.default,
173
messages=[{"role": "user", "content": "Hello"}],
174
provider=g4f.Provider.Name,
175
#cookies=g4f.get_cookies(".google.com"),
176
cookies={"name": "value", "name1": "value1"},
177
auth=True
178
)
179
```
180
181
##### Async support:
182
183
Run providers `async` to improve speed / performance.
184
The full execution time corresponds to the maximum execution time of a provider.
185
186
```py
187
import g4f, asyncio
188
189
async def run_async():
190
_providers = [
191
g4f.Provider.Bard,
192
g4f.Provider.Bing,
193
g4f.Provider.H2o,
194
g4f.Provider.HuggingChat,
195
g4f.Provider.Liaobots,
196
g4f.Provider.OpenAssistant,
197
g4f.Provider.OpenaiChat,
198
g4f.Provider.You,
199
g4f.Provider.Yqcloud,
200
]
201
responses = [
202
provider.create_async(
203
model=None,
204
messages=[{"role": "user", "content": "Hello"}],
205
)
206
for provider in _providers
207
]
208
responses = await asyncio.gather(*responses)
209
for idx, provider in enumerate(_providers):
210
print(f"{provider.__name__}:", responses[idx])
211
212
asyncio.run(run_async())
140
213
```
141
214
142
215
### interference openai-proxy api (use with openai python package)
@@ -186,30 +259,34 @@ if __name__ == "__main__":
186
259
| Website| Provider| gpt-3.5 | gpt-4 | Streaming | Status | Auth |
187
260
| ------ | ------- | ------- | ----- | --------- | ------ | ---- |
188
261
| [chat.acytoo.com](https://chat.acytoo.com/) | g4f.provider.Acytoo | ✔️ | ❌ | ❌ |  | ❌ |
189
| [chat-gpt.org](https://chat-gpt.org/chat) | g4f.provider.Aichat | ✔️ | ❌ | ❌ |  | ❌ |
190
| [ai.ls](https://ai.ls) | g4f.provider.Ails | ✔️ | ❌ | ✔️ |  | ❌ |
262
| [chat-gpt.org](https://chat-gpt.org/chat) | g4f.provider.Aichat | ✔️ | ❌ | ❌ |  | ❌ |
263
| [ai.ls](https://ai.ls) | g4f.provider.Ails | ✔️ | ❌ | ✔️ |  | ❌ |
191
264
| [bard.google.com](https://bard.google.com) | g4f.provider.Bard | ❌ | ❌ | ❌ |  | ✔️ |
192
| [chatgpt.ai](https://chatgpt.ai/gpt-4/) | g4f.provider.ChatgptAi | ❌ | ✔️ | ❌ |  | ❌ |
193
| [opchatgpts.net](https://opchatgpts.net) | g4f.provider.ChatgptLogin | ✔️ | ❌ | ❌ |  | ❌ |
265
| [bing.com](https://bing.com/chat) | g4f.provider.Bing | ❌ | ✔️ | ✔️ |  | ✔️ |
266
| [chatgpt.ai](https://chatgpt.ai/gpt-4/) | g4f.provider.ChatgptAi | ❌ | ✔️ | ❌ |  | ❌ |
267
| [opchatgpts.net](https://opchatgpts.net) | g4f.provider.ChatgptLogin | ✔️ | ❌ | ❌ |  | ❌ |
194
268
| [deepai.org](https://deepai.org) | g4f.provider.DeepAi | ✔️ | ❌ | ✔️ |  | ❌ |
195
269
| [free.easychat.work](https://free.easychat.work) | g4f.provider.EasyChat | ✔️ | ❌ | ✔️ |  | ❌ |
196
270
| [next.eqing.tech](https://next.eqing.tech/) | g4f.provider.Equing | ✔️ | ❌ | ✔️ |  | ❌ |
197
271
| [chat.getgpt.world](https://chat.getgpt.world/) | g4f.provider.GetGpt | ✔️ | ❌ | ✔️ |  | ❌ |
198
272
| [gpt-gm.h2o.ai](https://gpt-gm.h2o.ai) | g4f.provider.H2o | ❌ | ❌ | ✔️ |  | ❌ |
199
| [opchatgpts.net](https://opchatgpts.net) | g4f.provider.Opchatgpts | ✔️ | ❌ | ❌ |  | ❌ |
273
| [huggingface.co](https://huggingface.co/chat/) | g4f.provider.HuggingChat | ❌ | ❌ | ❌ |  | ✔️ |
274
| [liaobots.com](https://liaobots.com) | g4f.provider.Liaobots | ✔️ | ✔️ | ✔️ |  | ❌ |
275
| [opchatgpts.net](https://opchatgpts.net) | g4f.provider.Opchatgpts | ✔️ | ❌ | ❌ |  | ❌ |
276
| [open-assistant.io](https://open-assistant.io/chat) | g4f.provider.OpenAssistant | ❌ | ❌ | ❌ |  | ✔️ |
277
| [chat.openai.com](https://chat.openai.com) | g4f.provider.OpenaiChat | ✔️ | ✔️ | ✔️ |  | ✔️ |
200
278
| [raycast.com](https://raycast.com) | g4f.provider.Raycast | ✔️ | ✔️ | ✔️ |  | ✔️ |
201
279
| [theb.ai](https://theb.ai) | g4f.provider.Theb | ✔️ | ❌ | ✔️ |  | ✔️ |
202
280
| [play.vercel.ai](https://play.vercel.ai) | g4f.provider.Vercel | ✔️ | ❌ | ❌ |  | ❌ |
203
281
| [wewordle.org](https://wewordle.org/) | g4f.provider.Wewordle | ✔️ | ❌ | ❌ |  | ❌ |
204
| [you.com](https://you.com) | g4f.provider.You | ✔️ | ❌ | ❌ |  | ❌ |
282
| [chat.wuguokai.xyz](https://chat.wuguokai.xyz) | g4f.provider.Wuguokai | ✔️ | ❌ | ❌ |  | ❌ |
283
| [you.com](https://you.com) | g4f.provider.You | ✔️ | ❌ | ✔️ |  | ❌ |
205
284
| [chat9.yqcloud.top](https://chat9.yqcloud.top/) | g4f.provider.Yqcloud | ✔️ | ❌ | ❌ |  | ❌ |
206
285
| [www.aitianhu.com](https://www.aitianhu.com/) | g4f.provider.AItianhu | ✔️ | ❌ | ❌ |  | ❌ |
207
286
| [aiservice.vercel.app](https://aiservice.vercel.app/) | g4f.provider.AiService | ✔️ | ❌ | ❌ |  | ❌ |
208
| [bing.com](https://bing.com/chat) | g4f.provider.Bing | ❌ | ✔️ | ❌ |  | ❌ |
209
287
| [chat.dfehub.com](https://chat.dfehub.com/) | g4f.provider.DfeHub | ✔️ | ❌ | ✔️ |  | ❌ |
210
288
| [chat9.fastgpt.me](https://chat9.fastgpt.me/) | g4f.provider.FastGpt | ✔️ | ❌ | ✔️ |  | ❌ |
211
289
| [forefront.com](https://forefront.com) | g4f.provider.Forefront | ✔️ | ❌ | ✔️ |  | ❌ |
212
| [liaobots.com](https://liaobots.com) | g4f.provider.Liaobots | ✔️ | ✔️ | ✔️ |  | ✔️ |
213
290
| [supertest.lockchat.app](http://supertest.lockchat.app) | g4f.provider.Lockchat | ✔️ | ✔️ | ✔️ |  | ❌ |
214
291
| [p5.v50.ltd](https://p5.v50.ltd) | g4f.provider.V50 | ✔️ | ❌ | ❌ |  | ❌ |
215
292
@@ -26,32 +26,15 @@ class Bing(AsyncGeneratorProvider):
26
26
prompt = messages[-1]["content"]
27
27
context = create_context(messages[:-1])
28
28
29
if cookies:
29
if cookies and "SRCHD" in cookies:
30
30
#TODO: Will implement proper cookie retrieval later and use a try-except mechanism in 'stream_generate' instead of defaulting the cookie value like this
31
31
cookies_dict = {
32
'MUID' : '',
33
'BCP' : '',
34
'MUIDB' : '',
35
'USRLOC' : '',
36
'SRCHD' : 'AF=hpcodx',
37
'MMCASM' : '',
38
'_UR' : '',
39
'ANON' : '',
40
'NAP' : '',
41
'ABDEF' : '',
32
'SRCHD' : cookies["SRCHD"],
42
33
'PPLState' : '1',
43
34
'KievRPSSecAuth': '',
44
'_U' : '',
45
35
'SUID' : '',
46
'_EDGE_S' : '',
47
'WLS' : '',
48
'_HPVN' : '',
49
'_SS' : '',
50
'_clck' : '',
51
36
'SRCHUSR' : '',
52
'_RwBf' : '',
53
37
'SRCHHPGUSR' : '',
54
'ipv6' : '',
55
38
}
56
39
57
40
return stream_generate(prompt, context, cookies_dict)
@@ -28,6 +28,7 @@ models = {
28
28
29
29
class Liaobots(AsyncGeneratorProvider):
30
30
url = "https://liaobots.com"
31
working = True
31
32
supports_stream = True
32
33
supports_gpt_35_turbo = True
33
34
supports_gpt_4 = True
@@ -1,4 +1,4 @@
1
import random, requests, json
1
import random, requests
2
2
from ..typing import Any, CreateResult
3
3
from .base_provider import BaseProvider
4
4
@@ -6,8 +6,6 @@ from .base_provider import BaseProvider
6
6
class Wuguokai(BaseProvider):
7
7
url = 'https://chat.wuguokai.xyz'
8
8
supports_gpt_35_turbo = True
9
supports_stream = False
10
needs_auth = False
11
9
working = True
12
10
13
11
@staticmethod
@@ -43,7 +41,7 @@ class Wuguokai(BaseProvider):
43
41
"userId": f"#/chat/{random.randint(1,99999999)}",
44
42
"usingContext": True
45
43
}
46
response = requests.post("https://ai-api20.wuguokai.xyz/api/chat-process", headers=headers, data=json.dumps(data),proxies=kwargs['proxy'] if 'proxy' in kwargs else {})
44
response = requests.post("https://ai-api20.wuguokai.xyz/api/chat-process", headers=headers, timeout=3, json=data, proxies=kwargs['proxy'] if 'proxy' in kwargs else {})
47
45
_split = response.text.split("> 若回答失败请重试或多刷新几次界面后重试")
48
46
if response.status_code == 200:
49
47
if len(_split) > 1:
@@ -30,7 +30,7 @@ from .FastGpt import FastGpt
30
30
from .V50 import V50
31
31
from .Wuguokai import Wuguokai
32
32
33
from .base_provider import BaseProvider
33
from .base_provider import BaseProvider, AsyncProvider, AsyncGeneratorProvider
34
34
35
35
__all__ = [
36
36
'BaseProvider',
@@ -36,14 +36,14 @@ Bing: Hello! How can I help you today? 3.28 secs
36
36
No Stream Total: 10.14 secs
37
37
"""
38
38
39
print("Yqcloud:", end="")
39
print("Bing: ", end="")
40
40
for response in log_time_yield(
41
41
g4f.ChatCompletion.create,
42
42
model=g4f.models.gpt_35_turbo,
43
43
messages=[{"role": "user", "content": _instruct}],
44
provider=g4f.Provider.Yqcloud,
44
provider=g4f.Provider.Bing,
45
45
#cookies=g4f.get_cookies(".huggingface.co"),
46
stream=True,
46
#stream=True,
47
47
auth=True
48
48
):
49
49
print(response, end="")
@@ -6,14 +6,35 @@ from urllib.parse import urlparse
6
6
sys.path.append(str(Path(__file__).parent.parent))
7
7
8
8
from g4f import models, Provider
9
from g4f.Provider.base_provider import BaseProvider
9
from g4f.Provider.base_provider import BaseProvider, AsyncProvider
10
10
from testing.test_providers import test
11
11
12
def main():
13
print_providers()
14
print("\n", "-" * 50, "\n")
15
print_models()
16
12
13
def print_imports():
14
print("##### Providers:")
15
print("```py")
16
print("from g4f.Provider import (")
17
for _provider in get_providers():
18
if _provider.working:
19
print(f" {_provider.__name__},")
20
print(")")
21
print("# Usage:")
22
print("response = g4f.ChatCompletion.create(..., provider=ProviderName)")
23
print("```")
24
print()
25
print()
26
27
def print_async():
28
print("##### Async support:")
29
print("```py")
30
print("from g4f.Provider import (")
31
for _provider in get_providers():
32
if issubclass(_provider, AsyncProvider):
33
print(f" {_provider.__name__},")
34
print(")")
35
print("```")
36
print()
37
print()
17
38
18
39
def print_providers():
19
40
lines = [
@@ -48,18 +69,23 @@ def print_providers():
48
69
print("\n".join(lines))
49
70
50
71
51
def get_providers() -> list[type[BaseProvider]]:
72
def get_provider_names() -> list[str]:
52
73
provider_names = dir(Provider)
53
74
ignore_names = [
54
75
"base_provider",
55
76
"BaseProvider",
77
"AsyncProvider",
78
"AsyncGeneratorProvider"
56
79
]
57
provider_names = [
80
return [
58
81
provider_name
59
82
for provider_name in provider_names
60
83
if not provider_name.startswith("__") and provider_name not in ignore_names
61
84
]
62
return [getattr(Provider, provider_name) for provider_name in provider_names]
85
86
87
def get_providers() -> list[type[BaseProvider]]:
88
return [getattr(Provider, provider_name) for provider_name in get_provider_names()]
63
89
64
90
65
91
def print_models():
@@ -107,4 +133,8 @@ def get_models():
107
133
108
134
109
135
if __name__ == "__main__":
110
main()
136
print_imports()
137
print_async()
138
print_providers()
139
print("\n", "-" * 50, "\n")
140
print_models()