- 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)
- [Getting Started](#getting-started)
- [Prerequisites](#prerequisites)
- [Prerequisites](#prerequisites)
@ -39,7 +40,7 @@ pip install -U g4f
- [Star History](#star-history)
- [Star History](#star-history)
- [License](#license)
- [License](#license)
## Getting Started
## 🛠️ Getting Started
#### Prerequisites:
#### Prerequisites:
@ -142,22 +143,23 @@ docker compose down
> **Note**
> **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`.
> 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
### The `g4f` Package
#### ChatCompletion
#### ChatCompletion
```py
```python
import g4f
import g4f
g4f.debug.logging = True # enable logging
g4f.debug.logging = True # Enable logging
g4f.check_version = False # Disable automatic version checking
g4f.check_version = False # Disable automatic version checking
Cookies are essential for the proper functioning of some service providers.
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.
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.
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.
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.
The total execution time will be determined by the duration of the slowest provider's execution.
```py
```python
import g4f, asyncio
import g4f
import asyncio
_providers = [
_providers = [
g4f.Provider.Aichat,
g4f.Provider.Aichat,
@ -290,11 +295,11 @@ async def run_all():
asyncio.run(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.
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:
#### Run interference API from PyPi package
```py
```python
from g4f.api import run_api
from g4f.api import run_api
run_api()
run_api()
```
```
#### run interference API from repo:
#### 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.
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
```sh
g4f api
g4f api
@ -332,7 +339,7 @@ or
python -m g4f.api
python -m g4f.api
```
```
```py
```python
import openai
import openai
# Set your Hugging Face token as the API key if you use embeddings
# 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)
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)
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)
Top 1 Contributor: [@hlohaus](https://github.com/hlohaus)