Before you begin, ensure you have the following installed on your system:
- Docker
- Docker Compose
- Python 3.7 or higher
- pip (Python package manager)
Note: If you encounter issues with Docker, you can run the project directly using Python.
-
Clone the Repository
git clone https://github.com/xtekky/gpt4free.git cd gpt4free
-
Build and Run with Docker Compose
docker-compose up --build
-
Access the API The server will be accessible at
http://localhost:1337
If you encounter issues with Docker, you can run the project directly using Python:
-
Clone the Repository
git clone https://github.com/xtekky/gpt4free.git cd gpt4free
-
Install Dependencies
pip install -r requirements.txt
-
Run the Server
python -m g4f.api.run
-
Access the API The server will be accessible at
http://localhost:1337
You can test the API using curl or by creating a simple Python script:
curl -X POST -H "Content-Type: application/json" -d '{"prompt": "What is the capital of France?"}' http://localhost:1337/chat/completions
Create a file named test_g4f.py
with the following content:
import requests
url = "http://localhost:1337/v1/chat/completions"
body = {
"model": "gpt-3.5-turbo",
"stream": False,
"messages": [
{"role": "assistant", "content": "What can you do?"}
]
}
json_response = requests.post(url, json=body).json().get('choices', [])
for choice in json_response:
print(choice.get('message', {}).get('content', ''))
Run the script:
python test_g4f.py
- If you encounter issues with Docker, try running the project directly using Python as described in the Non-Docker Method.
- Ensure that you have the necessary permissions to run Docker commands. You might need to use
sudo
or add your user to thedocker
group. - If the server doesn't start, check the logs for any error messages and ensure all dependencies are correctly installed.
For more detailed information on API endpoints and usage, refer to the G4F API documentation.
To stop the Docker containers, use the following command:
docker-compose down
If you're running the server directly with Python, you can stop it by pressing Ctrl+C in the terminal where it's running.