🚀 GPT4Free (g4f) - 免费使用现代AI模型的终极解决方案

✨ 项目简介
GPT4Free是一个社区驱动的开源项目,集成了多个可访问的AI提供商和接口,让使用现代大语言模型和媒体生成模型变得更加简单灵活。项目旨在提供多提供商支持、本地GUI、OpenAI兼容的REST API以及便捷的Python和JavaScript客户端。
官方网站与文档: https://g4f.dev | https://g4f.dev/docs
🎯 核心特性
- Python客户端库(同步和异步版本)
- 本地Web GUI界面
- OpenAI兼容的FastAPI接口
- 官方浏览器JS客户端
- Docker镜像支持(完整版和精简版)
- 多提供商适配器(LLM、媒体生成、本地推理)
- 图像/音频/视频生成工具
🛠️ 快速安装
Docker推荐方式
# 拉取镜像
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\_media:/app/generated\_media \\
hlohaus789/g4f:latest
Python pip安装
pip install -U g4f[all]
Windows用户
👉 专为Windows打造的启动器:https://github.com/gpt4free/g4f.exe 🚀
🚀 快速开始
启动Web GUI
python -m g4f.cli gui --port 8080 --debug
访问: http://localhost:8080/chat/
Python客户端使用
from g4f.client import Client
client = Client()
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": "Hello, how are you?"}],
web\_search=False
)
print(response.choices[0].message.content)
图像生成示例
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}")
🌐 浏览器JS客户端
<script type="module">
import Client from '[https://g4f.dev/dist/js/client.js](https://g4f.dev/dist/js/client.js)';
const client = new Client();
const result = await client.chat.completions.create({
model: 'gpt-4.1',
messages: [{ role: 'user', content: 'Explain quantum computing' }]
});
console.log(result.choices[0].message.content);
</script>
🔧 MCP服务器支持
GPT4Free现在包含Model Context Protocol服务器,允许AI助手访问网络搜索、网页抓取和图像生成功能。
启动MCP服务器:
g4f mcp --http --port 8765
📊 支持的提供商
项目集成众多AI提供商,包括但不限于:
- OpenAI兼容端点
- PerplexityLabs
- Gemini
- MetaAI
- Pollinations(媒体生成)
- 本地推理后端
🤝 参与贡献
我们欢迎各种形式的贡献!无论是新提供商、功能改进、文档完善还是问题修复。
如何创建新提供商:
- 阅读指南: https://g4f.dev/docs/guides/create_provider.md
- 在
g4f/Provider/目录实现提供商适配器 - 添加配置和依赖说明
- 包含测试和用法示例
📄 许可证
本项目采用GNU General Public License v3.0 (GPLv3)许可证。
- 允许在GPLv3条款下重新分发和修改
- 软件按"原样"提供,不附带任何担保
💝 支持项目
喜欢这个项目?请考虑支持我们的开发工作:
- GitHub Sponsors: https://github.com/sponsors/hlohaus
- 提交问题与建议: https://github.com/xtekky/gpt4free/issues
🔗 重要链接
-
官方文档: https://g4f.dev/docs
-
PyPI包: https://pypi.org/project/g4f
-
Docker镜像: https://hub.docker.com/r/hlohaus789/g4f
-
社区交流:
- Telegram: https://telegram.me/g4f_channel
- Discord: https://discord.gg/5E39JUWUFa
让我们一起推动AI技术的开放与普及! 🚀
GPT4Free致力于让强大的AI工具变得可访问、灵活且社区驱动。加入我们,共同塑造AI的未来!
#AI #开源 #GPT4 #机器学习 #Python #开发者工具
评论区