返回提交历史
Modified
README.md
+39
-58
Modified
g4f/Provider/retry_provider.py
+1
-1
Modified
g4f/gui/server/backend.py
+2
-2
XFEstudio/gpt4free
Update readme. Add docker hub
bb34642f
代码差异
3 个文件
+42
-61
@@ -6,11 +6,13 @@
6
6
> By using this repository or any code related to it, you agree to the [legal notice](LEGAL_NOTICE.md). The author is not responsible for any copies, forks, re-uploads made by other users, or anything else related to GPT4Free. This is the author's only account and repository. To prevent impersonation or irresponsible actions, please comply with the GNU GPL license this Repository uses.
7
7
8
8
> [!Note]
9
Lastet version:
10
>> [](https://pypi.org/project/g4f)
9
<sup><strong>Lastet version:</strong></sup> [](https://pypi.org/project/g4f) [](https://hub.docker.com/r/hlohaus789/g4f)
11
10
```sh
12
11
pip install -U g4f
13
12
```
13
```sh
14
docker pull hlohaus789/g4f:latest
15
```
14
16
15
17
## 🆕 What's New
16
18
- <a href="./README-DE.md"><img src="https://img.shields.io/badge/öffnen in-🇩🇪 deutsch-bleu.svg" alt="Öffnen en DE"></a>
@@ -55,19 +57,35 @@ pip install -U g4f
55
57
56
58
## 🛠️ Getting Started
57
59
58
#### Prerequisites:
60
#### Docker container
59
61
60
1. [Download and install Python](https://www.python.org/downloads/) (Version 3.10+ is recommended).
62
##### Quick start:
63
64
1. [Download and install Docker](https://docs.docker.com/get-docker/)
65
2. Pull lastet image and run the container:
66
67
```sh
68
docker pull hlohaus789/g4f:latest
69
docker run -p 8080:80 -p 1337:1337 -p 7900:7900 --shm-size="2g" hlohaus789/g4f:latest
70
```
71
5. Open the included gui on: [http://localhost:8080/chat/](http://localhost:8080/chat/)
72
or set the api base in your client to: [http://localhost:1337/v1](http://localhost:1337/v1)
73
6. (Optional) If you need to log in to your provider, you can open the desktop in the container here: http://localhost:7900/?autoconnect=1&resize=scale&password=secret.
74
75
#### Use python package
61
76
62
#### Setting up the project:
77
##### Prerequisites:
63
78
64
##### Install using pypi
79
1. [Download and install Python](https://www.python.org/downloads/) (Version 3.10+ is recommended).
80
2. [Install Google Chrome](https://www.google.com/chrome/) for providers with webdriver
81
82
##### Install using pypi:
65
83
66
84
```
67
85
pip install -U g4f
68
86
```
69
87
70
##### or
88
##### or:
71
89
72
90
1. Clone the GitHub repository:
73
91
@@ -108,11 +126,10 @@ pip install -r requirements.txt
108
126
109
127
```py
110
128
import g4f
111
112
129
...
113
130
```
114
131
115
##### Setting up with Docker:
132
#### Docker for Developers
116
133
117
134
If you have Docker installed, you can easily set up and run the project without manually installing dependencies.
118
135
@@ -165,23 +182,21 @@ docker-compose down
165
182
```python
166
183
import g4f
167
184
168
g4f.debug.logging = True # Enable logging
185
g4f.debug.logging = True # Enable debug logging
169
186
g4f.debug.check_version = False # Disable automatic version checking
170
print(g4f.Provider.Ails.params) # Supported args
171
172
# Automatic selection of provider
187
print(g4f.Provider.Bing.params) # Print supported args for Bing
173
188
174
# Streamed completion
189
# Using automatic a provider for the given model
190
## Streamed completion
175
191
response = g4f.ChatCompletion.create(
176
192
model="gpt-3.5-turbo",
177
193
messages=[{"role": "user", "content": "Hello"}],
178
194
stream=True,
179
195
)
180
181
196
for message in response:
182
197
print(message, flush=True, end='')
183
198
184
# Normal response
199
## Normal response
185
200
response = g4f.ChatCompletion.create(
186
201
model=g4f.models.gpt_4,
187
202
messages=[{"role": "user", "content": "Hello"}],
@@ -217,27 +232,20 @@ print(response)
217
232
```python
218
233
import g4f
219
234
220
from g4f.Provider import (
221
AItianhu,
222
Aichat,
223
Bard,
224
Bing,
225
ChatBase,
226
ChatgptAi,
227
OpenaiChat,
228
Vercel,
229
You,
230
Yqcloud,
231
)
235
# Print all available providers
236
print([
237
provider.__name__
238
for provider in g4f.Provider.__providers__
239
if provider.working
240
])
232
241
233
# Set with provider
242
# Execute with a specific provider
234
243
response = g4f.ChatCompletion.create(
235
244
model="gpt-3.5-turbo",
236
245
provider=g4f.Provider.Aichat,
237
246
messages=[{"role": "user", "content": "Hello"}],
238
247
stream=True,
239
248
)
240
241
249
for message in response:
242
250
print(message)
243
251
```
@@ -254,7 +262,6 @@ from g4f.Provider import (
254
262
Poe,
255
263
AItianhuSpace,
256
264
MyShell,
257
Phind,
258
265
PerplexityAi,
259
266
)
260
267
@@ -264,7 +271,7 @@ webdriver = Chrome(options=options, headless=True)
264
271
for idx in range(10):
265
272
response = g4f.ChatCompletion.create(
266
273
model=g4f.models.default,
267
provider=g4f.Provider.Phind,
274
provider=g4f.Provider.MyShell,
268
275
messages=[{"role": "user", "content": "Suggest me a name."}],
269
276
webdriver=webdriver
270
277
)
@@ -272,32 +279,6 @@ for idx in range(10):
272
279
webdriver.quit()
273
280
```
274
281
275
##### Cookies Required
276
277
Cookies are essential for the proper functioning of some service providers. It is imperative to maintain an active session, typically achieved by logging into your account.
278
279
When running the g4f package locally, the package automatically retrieves cookies from your web browser using the `get_cookies` function. However, if you're not running it locally, you'll need to provide the cookies manually by passing them as parameters using the `cookies` parameter.
280
281
```python
282
import g4f
283
284
from g4f.Provider import (
285
Bing,
286
HuggingChat,
287
OpenAssistant,
288
)
289
290
# Usage
291
response = g4f.ChatCompletion.create(
292
model=g4f.models.default,
293
messages=[{"role": "user", "content": "Hello"}],
294
provider=Bing,
295
#cookies=g4f.get_cookies(".google.com"),
296
cookies={"cookie_name": "value", "cookie_name2": "value2"},
297
auth=True
298
)
299
```
300
301
282
##### Async Support
302
283
303
284
To enhance speed and overall performance, execute providers asynchronously. The total execution time will be determined by the duration of the slowest provider's execution.
@@ -10,7 +10,6 @@ from .. import debug
10
10
11
11
class RetryProvider(AsyncProvider):
12
12
__name__: str = "RetryProvider"
13
working: bool = True
14
13
supports_stream: bool = True
15
14
16
15
def __init__(
@@ -20,6 +19,7 @@ class RetryProvider(AsyncProvider):
20
19
) -> None:
21
20
self.providers: List[Type[BaseProvider]] = providers
22
21
self.shuffle: bool = shuffle
22
self.working = True
23
23
24
24
def create_completion(
25
25
self,
@@ -1,4 +1,5 @@
1
1
import g4f
2
from g4f.Provider import __providers__
2
3
3
4
from flask import request
4
5
from .internet import get_search_message
@@ -45,8 +46,7 @@ class Backend_Api:
45
46
46
47
def providers(self):
47
48
return [
48
provider.__name__ for provider in g4f.Provider.__providers__
49
if provider.working and provider is not g4f.Provider.RetryProvider
49
provider.__name__ for provider in __providers__ if provider.working
50
50
]
51
51
52
52
def version(self):