返回提交历史
Modified
README.md
+54
-49
XFEstudio/gpt4free
Improve readme
b7afedda
代码差异
1 个文件
+54
-49
@@ -14,11 +14,11 @@ new discord server: [discord.gg/XfybzPXPH5](https://discord.gg/XfybzPXPH5)
14
14
pip install -U g4f
15
15
```
16
16
17
## New features
17
## 🚀 New Features
18
18
* Telegram Channel: [t.me/g4f_channel](https://telegram.me/g4f_channel)
19
* g4f documentation (unfinished): [g4f.mintlify.app](https://g4f.mintlify.app) | Contribute to the docs via: [github.com/xtekky/gpt4free-docs](https://github.com/xtekky/gpt4free-docs)
19
* g4f Documentation (unfinished): [g4f.mintlify.app](https://g4f.mintlify.app) | Contribute to the docs via: [github.com/xtekky/gpt4free-docs](https://github.com/xtekky/gpt4free-docs)
20
20
21
## Table of Contents
21
## 📚 Table of Contents
22
22
23
23
- [Getting Started](#getting-started)
24
24
- [Prerequisites](#prerequisites)
@@ -39,7 +39,7 @@ pip install -U g4f
39
39
- [Star History](#star-history)
40
40
- [License](#license)
41
41
42
## Getting Started
42
## 🛠️ Getting Started
43
43
44
44
#### Prerequisites:
45
45
@@ -142,22 +142,23 @@ docker compose down
142
142
> **Note**
143
143
> When using Docker, any changes you make to your local files will be reflected in the Docker container thanks to the volume mapping in the `docker-compose.yml` file. If you add or remove dependencies, however, you'll need to rebuild the Docker image using `docker compose build`.
144
144
145
## Usage
145
## 💡 Usage
146
146
147
147
### The `g4f` Package
148
148
149
149
#### ChatCompletion
150
```py
150
151
```python
151
152
import g4f
152
153
153
g4f.debug.logging = True # enable logging
154
g4f.check_version = False # Disable automatic version checking
155
print(g4f.version) # check version
156
print(g4f.Provider.Ails.params) # supported args
154
g4f.debug.logging = True # Enable logging
155
g4f.check_version = False # Disable automatic version checking
156
print(g4f.version) # Check version
157
print(g4f.Provider.Ails.params) # Supported args
157
158
158
159
# Automatic selection of provider
159
160
160
# streamed completion
161
# Streamed completion
161
162
response = g4f.ChatCompletion.create(
162
163
model="gpt-3.5-turbo",
163
164
messages=[{"role": "user", "content": "Hello"}],
@@ -167,16 +168,18 @@ response = g4f.ChatCompletion.create(
167
168
for message in response:
168
169
print(message, flush=True, end='')
169
170
170
# normal response
171
# Normal response
171
172
response = g4f.ChatCompletion.create(
172
173
model=g4f.models.gpt_4,
173
174
messages=[{"role": "user", "content": "Hello"}],
174
) # alternative model setting
175
) # Alternative model setting
175
176
176
177
print(response)
177
178
```
179
178
180
##### Completion
179
```py
181
182
```python
180
183
import g4f
181
184
182
185
allowed_models = [
@@ -189,14 +192,16 @@ allowed_models = [
189
192
]
190
193
191
194
response = g4f.Completion.create(
192
model = 'text-davinci-003',
193
prompt = 'say this is a test')
195
model='text-davinci-003',
196
prompt='say this is a test'
197
)
194
198
195
199
print(response)
196
200
```
197
201
198
##### Providers:
199
```py
202
##### Providers
203
204
```python
200
205
import g4f
201
206
202
207
from g4f.Provider import (
@@ -224,14 +229,13 @@ for message in response:
224
229
print(message)
225
230
```
226
231
227
##### Cookies Required:
232
##### Cookies Required
228
233
229
Cookies are essential for the proper functioning of some service providers.
230
It is imperative to maintain an active session, typically achieved by logging into your account.
234
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.
231
235
232
236
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.
233
237
234
```py
238
```python
235
239
import g4f
236
240
237
241
from g4f.Provider import (
@@ -242,7 +246,7 @@ from g4f.Provider import (
242
246
OpenaiChat,
243
247
)
244
248
245
# Usage:
249
# Usage
246
250
response = g4f.ChatCompletion.create(
247
251
model=g4f.models.default,
248
252
messages=[{"role": "user", "content": "Hello"}],
@@ -253,13 +257,13 @@ response = g4f.ChatCompletion.create(
253
257
)
254
258
```
255
259
256
##### Async Support:
260
##### Async Support
257
261
258
To enhance speed and overall performance, execute providers asynchronously.
259
The total execution time will be determined by the duration of the slowest provider's execution.
262
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.
260
263
261
```py
262
import g4f, asyncio
264
```python
265
import g4f
266
import asyncio
263
267
264
268
_providers = [
265
269
g4f.Provider.Aichat,
@@ -290,11 +294,11 @@ async def run_all():
290
294
asyncio.run(run_all())
291
295
```
292
296
293
##### Proxy and Timeout Support:
297
##### Proxy and Timeout Support
294
298
295
299
All providers support specifying a proxy and increasing timeout in the create functions.
296
300
297
```py
301
```python
298
302
import g4f
299
303
300
304
response = g4f.ChatCompletion.create(
@@ -302,25 +306,27 @@ response = g4f.ChatCompletion.create(
302
306
messages=[{"role": "user", "content": "Hello"}],
303
307
proxy="http://host:port",
304
308
# or socks5://user:pass@host:port
305
timeout=120, # in secs
309
timeout=120, # in secs
306
310
)
307
311
308
312
print(f"Result:", response)
309
313
```
310
314
311
### interference openai-proxy API (use with openai python package)
315
### Interference openai-proxy API (Use with openai python package)
312
316
313
#### run interference API from PyPi package:
314
```py
317
#### Run interference API from PyPi package
318
319
```python
315
320
from g4f.api import run_api
316
321
317
322
run_api()
318
323
```
319
324
320
#### run interference API from repo:
321
If you want to use the embedding function, you need to get a Hugging Face token. You can get one at https://huggingface.co/settings/tokens make sure your role is set to write. If you have your token, just use it instead of the OpenAI api-key.
325
#### Run interference API from repo
326
327
If you want to use the embedding function, you need to get a Hugging Face token. You can get one at [Hugging Face Tokens](https://huggingface.co/settings/tokens). Make sure your role is set to write. If you have your token, just use it instead of the OpenAI api-key.
322
328
323
run server:
329
Run server:
324
330
325
331
```sh
326
332
g4f api
@@ -332,7 +338,7 @@ or
332
338
python -m g4f.api
333
339
```
334
340
335
```py
341
```python
336
342
import openai
337
343
338
344
# Set your Hugging Face token as the API key if you use embeddings
@@ -359,13 +365,12 @@ def main():
359
365
if content is not None:
360
366
print(content, end="", flush=True)
361
367
362
if __name__ == "__main":
368
if __name__ == "__main__":
363
369
main()
364
365
370
```
366
371
367
## Models
368
### gpt-4
372
## 🚀 Providers and Models
373
### GPT-4
369
374
| Website| Provider| gpt-3.5 | gpt-4 | Stream | Async | Status | Auth |
370
375
| ------ | ------- | ------- | ----- | --------- | --------- | ------ | ---- |
371
376
| [bing.com](https://bing.com/chat) | `g4f.Provider.Bing` | ❌ | ✔️ | ✔️ | ✔️ |  | ❌ |
@@ -378,7 +383,7 @@ if __name__ == "__main":
378
383
| [supertest.lockchat.app](http://supertest.lockchat.app) | `g4f.Provider.Lockchat` | ✔️ | ✔️ | ✔️ | ❌ |  | ❌ |
379
384
| [app.myshell.ai](https://app.myshell.ai/chat) | `g4f.Provider.Myshell` | ✔️ | ✔️ | ✔️ | ✔️ |  | ❌ |
380
385
381
### gpt-3.5
386
### GPT-3.5
382
387
383
388
| Website| Provider| gpt-3.5 | Stream | Async | Status | Auth |
384
389
| ------ | ------- | ------- | --------- | --------- | ------ | ---- |
@@ -462,7 +467,7 @@ if __name__ == "__main":
462
467
| llama13b-v2-chat | Replicate | g4f.Provider.Vercel | [sdk.vercel.ai](https://sdk.vercel.ai/) |
463
468
| llama7b-v2-chat | Replicate | g4f.Provider.Vercel | [sdk.vercel.ai](https://sdk.vercel.ai/) |
464
469
465
## Related gpt4free projects
470
## 🔗 Related GPT4Free Projects
466
471
467
472
<table>
468
473
<thead align="center">
@@ -548,7 +553,7 @@ if __name__ == "__main":
548
553
</tbody>
549
554
</table>
550
555
551
## Contribute
556
## 🤝 Contribute
552
557
553
558
#### Create Provider with AI Tool
554
559
@@ -613,13 +618,13 @@ for message in response:
613
618
print(message, flush=True, end='')
614
619
```
615
620
616
## Contributors
621
## 🙌 Contributors
617
622
618
623
A list of the contributors is available [here](https://github.com/xtekky/gpt4free/graphs/contributors)
619
624
The [`Vercel.py`](https://github.com/xtekky/gpt4free/blob/main/g4f/Provider/Vercel.py) file contains code from [vercel-llm-api](https://github.com/ading2210/vercel-llm-api) by [@ading2210](https://github.com/ading2210), which is licensed under the [GNU GPL v3](https://www.gnu.org/licenses/gpl-3.0.txt)
620
625
Top 1 Contributor: [@hlohaus](https://github.com/hlohaus)
621
626
622
## Copyright
627
## ©️ Copyright
623
628
624
629
This program is licensed under the [GNU GPL v3](https://www.gnu.org/licenses/gpl-3.0.txt)
625
630
@@ -640,13 +645,13 @@ You should have received a copy of the GNU General Public License
640
645
along with this program. If not, see <https://www.gnu.org/licenses/>.
641
646
```
642
647
643
## Star History
648
## ⭐ Star History
644
649
645
650
<a href="https://github.com/xtekky/gpt4free/stargazers">
646
651
<img width="500" alt="Star History Chart" src="https://api.star-history.com/svg?repos=xtekky/gpt4free&type=Date">
647
652
</a>
648
653
649
## License
654
## 📄 License
650
655
651
656
<table>
652
657
<tr>