- Explore the 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)
## 📚 Table of Contents
- [Getting Started](#getting-started)
- [Prerequisites](#prerequisites)
@ -39,7 +40,7 @@ pip install -U g4f
- [Star History](#star-history)
- [License](#license)
## Getting Started
## 🛠️ Getting Started
#### Prerequisites:
@ -142,22 +143,23 @@ docker compose down
> **Note**
> 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`.
## Usage
## 💡 Usage
### The `g4f` Package
#### ChatCompletion
```py
```python
import g4f
g4f.debug.logging = True # enable logging
g4f.check_version = False # Disable automatic version checking
print(g4f.version) # check version
print(g4f.Provider.Ails.params) # supported args
g4f.debug.logging = True # Enable logging
g4f.check_version = False # Disable automatic version checking
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.
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.
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.
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.
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.
```py
import g4f, asyncio
```python
import g4f
import asyncio
_providers = [
g4f.Provider.Aichat,
@ -290,11 +295,11 @@ async def run_all():
asyncio.run(run_all())
```
##### Proxy and Timeout Support:
##### Proxy and Timeout Support
All providers support specifying a proxy and increasing timeout in the create functions.
### interference openai-proxy API (use with openai python package)
### Interference openai-proxy API (Use with openai python package)
#### run interference API from PyPi package:
```py
#### Run interference API from PyPi package
```python
from g4f.api import run_api
run_api()
```
#### run interference API from repo:
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.
#### Run interference API from repo
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.
run server:
Run server:
```sh
g4f api
@ -332,7 +339,7 @@ or
python -m g4f.api
```
```py
```python
import openai
# Set your Hugging Face token as the API key if you use embeddings
A list of the contributors is available [here](https://github.com/xtekky/gpt4free/graphs/contributors)
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)
Top 1 Contributor: [@hlohaus](https://github.com/hlohaus)