gpt4free
The official gpt4free repository | various collection of powerful language models
Top Related Projects
Reverse engineered ChatGPT API
AI agent stdlib that works with any LLM and TypeScript AI SDK.
AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
DeepSpeed is a deep learning optimization library that makes distributed training and inference easy, efficient, and effective.
The official Python library for the OpenAI API
🤗 Transformers: State-of-the-art Machine Learning for Pytorch, TensorFlow, and JAX.
Quick Overview
gpt4free is an open-source project that provides free access to various AI models, including GPT-4, through reverse-engineered APIs. It aims to make advanced language models accessible to developers and researchers without the need for paid subscriptions or API keys.
Pros
- Free access to powerful AI models
- Multiple providers and models available
- Active community and frequent updates
- Useful for testing and prototyping AI applications
Cons
- Potential legal and ethical concerns regarding API usage
- Reliability issues due to dependence on third-party services
- May not be suitable for production environments
- Limited support and documentation compared to official APIs
Code Examples
- Using the Forefront provider:
import g4f
response = g4f.ChatCompletion.create(
model="gpt-3.5-turbo",
provider=g4f.Provider.Forefront,
messages=[{"role": "user", "content": "Hello, how are you?"}],
stream=True,
)
for message in response:
print(message, flush=True, end='')
- Using the You provider:
import g4f
response = g4f.ChatCompletion.create(
model=g4f.models.gpt_35_turbo,
messages=[{"role": "user", "content": "Write a poem about AI"}],
provider=g4f.Provider.You,
)
print(response)
- Using the Bing provider:
import g4f
response = g4f.ChatCompletion.create(
model="gpt-4",
provider=g4f.Provider.Bing,
messages=[{"role": "user", "content": "Explain quantum computing"}],
cookies=g4f.get_cookies(".bing.com"),
)
print(response)
Getting Started
To get started with gpt4free, follow these steps:
- Install the library:
pip install -U g4f
- Import the library and use a provider:
import g4f
response = g4f.ChatCompletion.create(
model="gpt-3.5-turbo",
provider=g4f.Provider.OpenaiChat,
messages=[{"role": "user", "content": "Hello, world!"}],
)
print(response)
Note: Make sure to check the project's documentation for the latest updates and provider-specific instructions.
Competitor Comparisons
Reverse engineered ChatGPT API
Pros of ChatGPT
- More established project with a larger community and longer development history
- Offers a wider range of features, including support for multiple ChatGPT models
- Better documentation and more comprehensive setup instructions
Cons of ChatGPT
- Requires authentication and API keys, which may be less accessible for some users
- More complex setup process compared to gpt4free
- May have higher usage costs due to reliance on official OpenAI APIs
Code Comparison
ChatGPT:
from revChatGPT.V3 import Chatbot
chatbot = Chatbot(api_key="your_api_key")
response = chatbot.ask("Hello, how are you?")
print(response)
gpt4free:
import g4f
response = g4f.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[{"role": "user", "content": "Hello, how are you?"}]
)
print(response)
Both repositories provide access to ChatGPT-like functionality, but gpt4free aims to offer free access without authentication, while ChatGPT focuses on providing a more robust and official integration with OpenAI's services. The choice between them depends on the user's needs, budget, and ethical considerations regarding API usage.
AI agent stdlib that works with any LLM and TypeScript AI SDK.
Pros of agentic
- Focuses on building autonomous AI agents, offering a more specialized and advanced approach
- Provides a framework for creating complex, goal-oriented AI systems
- Emphasizes ethical considerations and responsible AI development
Cons of agentic
- Less accessible for users seeking simple, ready-to-use GPT-like functionality
- Requires more technical knowledge and setup compared to gpt4free
- Smaller community and fewer contributors, potentially leading to slower development
Code Comparison
gpt4free:
from g4f import ChatCompletion
response = ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[{"role": "user", "content": "Hello, how are you?"}]
)
print(response)
agentic:
from agentic import Agent, Task
agent = Agent()
task = Task("Greet the user and ask how they are")
result = agent.run(task)
print(result)
The code comparison shows that gpt4free provides a more straightforward interface for generating responses, while agentic focuses on creating autonomous agents to perform tasks. gpt4free is better suited for quick, chat-like interactions, whereas agentic is designed for more complex, goal-oriented AI applications.
AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
Pros of AutoGPT
- Autonomous task completion with minimal human intervention
- Versatile application across various domains (e.g., coding, research, analysis)
- Active development and community support
Cons of AutoGPT
- Requires API key and potentially higher costs for extended use
- More complex setup and configuration process
- May produce inconsistent or unexpected results due to its autonomous nature
Code Comparison
AutoGPT:
def start_interaction_loop(self):
# Interaction loop
while True:
# Get user input
user_input = input("Human: ")
if user_input.lower() == "exit":
break
gpt4free:
def create_chat(self, model="gpt-3.5-turbo", messages=None, **kwargs):
if messages is None:
messages = []
return ChatCompletion.create(
model=model, messages=messages, **kwargs
)
AutoGPT focuses on creating an autonomous agent that can perform tasks with minimal human intervention, while gpt4free aims to provide free access to various language models. AutoGPT offers more advanced features but requires more setup, while gpt4free is simpler to use but may have limitations in terms of available models and functionality.
DeepSpeed is a deep learning optimization library that makes distributed training and inference easy, efficient, and effective.
Pros of DeepSpeed
- Focuses on optimizing deep learning training and inference
- Offers advanced techniques like ZeRO (Zero Redundancy Optimizer)
- Supports various AI frameworks and models
Cons of DeepSpeed
- More complex setup and configuration
- Primarily targets large-scale AI training scenarios
- Steeper learning curve for beginners
Code Comparison
DeepSpeed:
import deepspeed
model_engine, optimizer, _, _ = deepspeed.initialize(args=args,
model=model,
model_parameters=params)
gpt4free:
import g4f
response = g4f.ChatCompletion.create(model="gpt-3.5-turbo",
messages=[{"role": "user", "content": "Hello"}])
Summary
DeepSpeed is a powerful library for optimizing deep learning workflows, particularly suited for large-scale AI training. It offers advanced techniques like ZeRO and supports various AI frameworks. However, it has a steeper learning curve and is more complex to set up compared to gpt4free.
gpt4free, on the other hand, provides a simpler interface for accessing GPT-like models, making it more accessible for quick prototyping and smaller projects. It lacks the advanced optimization features of DeepSpeed but offers easier integration for basic AI text generation tasks.
The official Python library for the OpenAI API
Pros of openai-python
- Official library maintained by OpenAI, ensuring reliability and up-to-date features
- Comprehensive documentation and support from OpenAI
- Seamless integration with OpenAI's API and services
Cons of openai-python
- Requires an API key and associated costs for usage
- Limited to OpenAI's models and services
Code Comparison
openai-python:
import openai
openai.api_key = "your-api-key"
response = openai.Completion.create(engine="text-davinci-002", prompt="Hello, world!")
print(response.choices[0].text)
gpt4free:
import g4f
response = g4f.ChatCompletion.create(model="gpt-3.5-turbo", messages=[{"role": "user", "content": "Hello, world!"}])
print(response)
Key Differences
- openai-python is the official library, while gpt4free is a third-party alternative
- gpt4free aims to provide free access to AI models, while openai-python requires an API key and associated costs
- openai-python offers more extensive features and model options, while gpt4free focuses on providing free alternatives
- gpt4free may have potential legal and ethical concerns due to its nature of bypassing official APIs
Use Cases
- openai-python: Ideal for professional and commercial applications requiring reliable and official API access
- gpt4free: Suitable for personal projects, experimentation, or scenarios where API costs are a concern, but with potential limitations and risks
🤗 Transformers: State-of-the-art Machine Learning for Pytorch, TensorFlow, and JAX.
Pros of transformers
- Comprehensive library with support for numerous pre-trained models
- Extensive documentation and community support
- Seamless integration with PyTorch and TensorFlow
Cons of transformers
- Steeper learning curve for beginners
- Larger library size and potentially higher resource requirements
Code Comparison
transformers:
from transformers import pipeline
classifier = pipeline("sentiment-analysis")
result = classifier("I love this library!")[0]
print(f"Label: {result['label']}, Score: {result['score']:.4f}")
gpt4free:
import g4f
response = g4f.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[{"role": "user", "content": "Hello, how are you?"}]
)
print(response)
Summary
transformers is a robust, well-documented library for working with various pre-trained models, offering extensive functionality and integration with popular deep learning frameworks. It's ideal for advanced users and large-scale projects.
gpt4free, on the other hand, provides a simpler interface for accessing GPT models, making it more accessible for quick implementations and experimentation. However, it may lack the comprehensive features and community support of transformers.
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Written by @xtekky
[!IMPORTANT] By using this repository or any code related to it, you agree to the legal notice. The author is not responsible for the usage of this repository nor endorses it, nor is the author responsible for any copies, forks, re-uploads made by other users, or anything else related to GPT4Free. This is the author's only account and repository. To prevent impersonation or irresponsible actions, please comply with the GNU GPL license this Repository uses.
[!WARNING] "gpt4free" serves as a PoC (proof of concept), demonstrating the development of an API package with multi-provider requests, with features like timeouts, load balance and flow control.
pip install -U g4f[all]
docker pull hlohaus789/g4f
ð What's New
-
Explore the latest features and updates
Find comprehensive details on our Releases Page. -
Stay updated with our Telegram Channel ð¨
Join us at telegram.me/g4f_channel. -
Subscribe to our Discord News Channel ð¬ðï¸
Stay informed about updates via our News Channel: discord.gg/5E39JUWUFa. -
Get support in our Discord Community ð¤ð»
Reach out for help in our Support Group: discord.gg/qXA4Wf4Fsm.
ð» Site Takedown
Is your site on this repository and you want to take it down? Send an email to takedown@g4f.ai with proof it is yours and it will be removed as fast as possible. To prevent reproduction please secure your API. ð
ð GPT4Free on HuggingFace
Is a proof-of-concept API package for multi-provider AI requests. It showcases features such as:
- Load balancing and request flow control.
- Seamless integration with multiple AI providers.
- Comprehensive text and image generation support.
Explore the Visit GPT4Free on HuggingFace Space for a hosted version or Duplicate GPT4Free Space it for personal use.
ð Table of Contents
- ð What's New
- ð Table of Contents
- â¡ Getting Started
- ð¡ Usage
- ð Providers and Models
- ð Powered by gpt4free
- ð¤ Contribute
- ð Contributors
- Â©ï¸ Copyright
- â Star History
- ð License
â¡ï¸ Getting Started
ð Installation
ð³ Using Docker
- Install Docker: Download and install Docker.
- Set Up Directories: Before running the container, make sure the necessary data directories exist or can be created. For example, you can create and set ownership on these directories by running:
mkdir -p ${PWD}/har_and_cookies ${PWD}/generated_images
sudo chown -R 1200:1201 ${PWD}/har_and_cookies ${PWD}/generated_images
- Run the Docker Container: Use the following commands to pull the latest image and start the container (Only x64):
docker pull hlohaus789/g4f
docker run -p 8080:8080 -p 7900:7900 \
--shm-size="2g" \
-v ${PWD}/har_and_cookies:/app/har_and_cookies \
-v ${PWD}/generated_images:/app/generated_images \
hlohaus789/g4f:latest
- Running the Slim Docker Image: And use the following commands to run the Slim Docker image. This command also updates the
g4f
package at startup and installs any additional dependencies: (x64 and arm64)
mkdir -p ${PWD}/har_and_cookies ${PWD}/generated_images
chown -R 1000:1000 ${PWD}/har_and_cookies ${PWD}/generated_images
docker run \
-p 1337:1337 \
-v ${PWD}/har_and_cookies:/app/har_and_cookies \
-v ${PWD}/generated_images:/app/generated_images \
hlohaus789/g4f:latest-slim \
rm -r -f /app/g4f/ \
&& pip install -U g4f[slim] \
&& python -m g4f --debug
-
Access the Client Interface:
- To use the included client, navigate to: http://localhost:8080/chat/
- Or set the API base for your client to: http://localhost:8080/v1
-
(Optional) Provider Login: If required, you can access the container's desktop here: http://localhost:7900/?autoconnect=1&resize=scale&password=secret for provider login purposes.
ðª Windows Guide (.exe)
To ensure the seamless operation of our application, please follow the instructions below. These steps are designed to guide you through the installation process on Windows operating systems.
Installation Steps:
- Download the Application: Visit our releases page and download the most recent version of the application, named
g4f.exe.zip
. - File Placement: After downloading, locate the
.zip
file in your Downloads folder. Unpack it to a directory of your choice on your system, then execute theg4f.exe
file to run the app. - Open GUI: The app starts a web server with the GUI. Open your favorite browser and navigate to http://localhost:8080/chat/ to access the application interface.
- Firewall Configuration (Hotfix): Upon installation, it may be necessary to adjust your Windows Firewall settings to allow the application to operate correctly. To do this, access your Windows Firewall settings and allow the application.
By following these steps, you should be able to successfully install and run the application on your Windows system. If you encounter any issues during the installation process, please refer to our Issue Tracker or try to get contact over Discord for assistance.
ð Python Installation
Prerequisites:
- Install Python 3.10+ from python.org.
- Install Google Chrome for certain providers.
Install with PyPI:
pip install -U g4f[all]
How do I install only parts or do disable parts? Use partial requirements: /docs/requirements
Install from Source:
git clone https://github.com/xtekky/gpt4free.git
cd gpt4free
pip install -r requirements.txt
How do I load the project using git and installing the project requirements? Read this tutorial and follow it step by step: /docs/git
ð¡ Usage
ð Text Generation
from g4f.client import Client
client = Client()
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": "Hello"}],
web_search=False
)
print(response.choices[0].message.content)
Hello! How can I assist you today?
ð¨ Image Generation
from g4f.client import Client
client = Client()
response = client.images.generate(
model="flux",
prompt="a white siamese cat",
response_format="url"
)
print(f"Generated image URL: {response.data[0].url}")
ð Web Interface
Run the GUI using Python:
from g4f.gui import run_gui
run_gui()
Run via CLI (To start the Flask Server):
python -m g4f.cli gui --port 8080 --debug
Or, start the FastAPI Server:
python -m g4f --port 8080 --debug
Learn More About the GUI: For detailed instructions on how to set up, configure, and use the GPT4Free GUI, refer to the GUI Documentation . This guide includes step-by-step details on provider selection, managing conversations, using advanced features like speech recognition, and more.
ð¤ Interference API
The Interference API enables seamless integration with OpenAI's services through G4F, allowing you to deploy efficient AI solutions.
- Documentation: Interference API Docs
- Endpoint:
http://localhost:1337/v1
- Swagger UI: Explore the OpenAPI documentation via Swagger UI at
http://localhost:1337/docs
- Provider Selection: How to Specify a Provider?
This API is designed for straightforward implementation and enhanced compatibility with other OpenAI integrations.
ð± Run on Smartphone
Run the Web UI on your smartphone for easy access on the go. Check out the dedicated guide to learn how to set up and use the GUI on your mobile device: Run on Smartphone Guide
ð Full Documentation for Python API
- Client API from G4F: /docs/client
- AsyncClient API from G4F: /docs/async_client
- Requests API from G4F: /docs/requests
- File API from G4F: /docs/file
- PydanticAI and LangChain Integration for G4F: /docs/pydantic_ai
- Legacy API with python modules: /docs/legacy
ð Powered by gpt4free
ð Projects | â Stars | ð Forks | ð Issues | ð¬ Pull requests |
gpt4free |
|
|
|
|
gpt4free-ts |
|
|
|
|
Free AI API's & Potential Providers List |
|
|
|
|
ChatGPT-Clone |
|
|
|
|
Ai agent |
|
|
|
|
ChatGpt Discord Bot |
|
|
|
|
chatGPT-discord-bot |
|
|
|
|
Nyx-Bot (Discord) |
|
|
|
|
LangChain gpt4free |
|
|
|
|
ChatGpt Telegram Bot |
|
|
|
|
ChatGpt Line Bot |
|
|
|
|
Action Translate Readme |
|
|
|
|
Langchain Document GPT |
|
|
|
|
python-tgpt |
|
|
|
|
GPT4js |
|
|
|
|
VividNode (pyqt-openai) |
|
|
|
|
ð¤ Contribute
We welcome contributions from the community. Whether you're adding new providers or features, or simply fixing typos and making small improvements, your input is valued. Creating a pull request is all it takes â our co-pilot will handle the code review process. Once all changes have been addressed, we'll merge the pull request into the main branch and release the updates at a later time.
Guide: How do i create a new Provider?
- Read: Create Provider Guide
Guide: How can AI help me with writing code?
- Read: AI Assistance Guide
Contributors
A list of all contributors is available here
- The
Vercel.py
file contains code from vercel-llm-api by @ading2210 - The
har_file.py
has input from xqdoo00o/ChatGPT-to-API - The
PerplexityLabs.py
has input from nathanrchn/perplexityai - The
Gemini.py
has input from dsdanielpark/Gemini-API - The
MetaAI.py
file contains code from meta-ai-api by @Strvm - The
proofofwork.py
has input from missuo/FreeGPT35 - The
Gemini.py
has input from HanaokaYuzu/Gemini-API
Having input implies that the AI's code generation utilized it as one of many sources.
Â©ï¸ Copyright
This program is licensed under the GNU GPL v3
xtekky/gpt4free: Copyright (C) 2023 xtekky
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
â Star History
ð License
|
This project is licensed under GNU_GPL_v3.0. |
Top Related Projects
Reverse engineered ChatGPT API
AI agent stdlib that works with any LLM and TypeScript AI SDK.
AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
DeepSpeed is a deep learning optimization library that makes distributed training and inference easy, efficient, and effective.
The official Python library for the OpenAI API
🤗 Transformers: State-of-the-art Machine Learning for Pytorch, TensorFlow, and JAX.
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot