3.4 KiB
G4F - Git Installation Guide
This guide provides step-by-step instructions for installing G4F from the source code using Git.
Table of Contents
Prerequisites
Before you begin, ensure you have the following installed on your system:
- Git
- Python 3.7 or higher
- pip (Python package installer)
Installation Steps
1. Clone the Repository
Open your terminal and run the following command to clone the G4F repository:
git clone https://github.com/xtekky/gpt4free.git
2. Navigate to the Project Directory
Change to the project directory:
cd gpt4free
3. Set Up a Python Virtual Environment (Recommended)
It's best practice to use a virtual environment to manage project dependencies:
python3 -m venv venv
4. Activate the Virtual Environment
Activate the virtual environment based on your operating system:
-
Windows:
.\venv\Scripts\activate
-
macOS and Linux:
source venv/bin/activate
5. Install Dependencies
You have two options for installing dependencies:
Option A: Install Minimum Requirements
For a lightweight installation, use:
pip install -r requirements-min.txt
Option B: Install All Packages
For a full installation with all features, use:
pip install -r requirements.txt
6. Verify Installation
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
Usage
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-3.5-turbo",
messages=[
{
"role": "user",
"content": "Say this is a test"
}
]
# Add any other necessary parameters
)
print(response.choices[0].message.content)
Troubleshooting
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.
Additional Resources
For more information or support, please visit the G4F GitHub Issues page.