The G4F Client API introduces a new way to integrate advanced AI functionalities into your Python applications. This guide will help you transition from using the OpenAI client to the new G4F Client, offering compatibility with the existing OpenAI API alongside additional features.
#### Getting Started
#### Start
This new client could:
**Switching to G4F Client:**
Replace the OpenAI client import statement in your Python code as follows:
Old Import:
```python
from g4f.client import Client
from openai import OpenAI
```
replaces this:
New Import:
```python
from openai import OpenAI
from g4f.client import Client
```
in your Python Code.
New client have the same API as OpenAI.
The G4F Client maintains the same API interface as OpenAI, ensuring a seamless transition.
#### Client
#### Initializing the Client
Create the client with custom providers:
To use the G4F Client, create an instance with customized providers:
```python
from g4f.client import Client
from g4f.Provider import BingCreateImages, OpenaiChat, Gemini
from g4f.providers import BingCreateImages, OpenaiChat, Gemini
client = Client(
provider=OpenaiChat,
text_provider=OpenaiChat,
image_provider=Gemini,
proxies=None
)
```
#### Examples
#### Usage Examples
**Text Completions:**
Use the ChatCompletions:
You can use the `ChatCompletions` endpoint to generate text completions as follows: