This guide provides step-by-step instructions for installing G4F from the source code using Git.
Before you begin, ensure you have the following installed on your system:
- Git
- Python 3.7 or higher
- pip (Python package installer)
Open your terminal and run the following command to clone the G4F repository:
git clone https://github.com/xtekky/gpt4free.git
Change to the project directory:
cd gpt4free
It's best practice to use a virtual environment to manage project dependencies:
python3 -m venv venv
Activate the virtual environment based on your operating system:
-
Windows:
.\venv\Scripts\activate
-
macOS and Linux:
source venv/bin/activate
You have two options for installing dependencies:
For a lightweight installation, use:
pip install -r requirements-min.txt
For a full installation with all features, use:
pip install -r requirements.txt
You can now create Python scripts and utilize the G4F functionalities. Here's a basic example:
Create a g4f-test.py
file in the root folder and start using the repository:
import g4f
# Your code here
After installation, you can start using G4F in your Python scripts. Here's a basic example:
import g4f
# Your G4F code here
# For example:
from g4f.client import Client
client = Client()
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[
{
"role": "user",
"content": "Say this is a test"
}
]
# Add any other necessary parameters
)
print(response.choices[0].message.content)
If you encounter any issues during installation or usage:
- Ensure all prerequisites are correctly installed.
- Check that you're in the correct directory and the virtual environment is activated.
- Try reinstalling the dependencies.
- Consult the G4F documentation for more detailed information.
For more information or support, please visit the G4F GitHub Issues page.