$ show xtekky/gpt4free
gpt4free (g4f) is a large-scale, community-driven Python library that aggregates dozens of free AI providers (LLMs, image, audio, video) into a unified, OpenAI-compatible interface. It provides multiple access modes: a Python client library (sync/async), a FastAPI-based API server, a Flask web GUI, a CLI tool, a Model Context Protocol (MCP) server for tool calling, a browser extension, a Discord bot, an Android app, and a Go launcher. The architecture is provider-based: each AI service (e.g., ChatGPT, Gemini, DeepSeek, Copilot, Grok, Perplexity) is wrapped in an adapter class implementing a common `AsyncGeneratorProvider` interface. The system handles authentication via cookies, OAuth flows, HAR files, and browser automation (CDP/nodriver), and supports streaming, tool/function calling, image generation, audio synthesis, and web search. It is primarily an application for consuming free AI models, not a research or data pipeline project, though it includes some data-oriented utilities like token optimization and usage tracking.
The LLM identified 6 files worth highlighting for reuse:
Implements RetryProvider, RotatedProvider, and ProviderCircuitBreaker for automatic fallback between multiple AI providers. Self-contained and reusable for any multi-provider system requiring retry logic with circuit breaker semantics.
Provides QuotaCache with TTL-based expiration and ErrorCounter with rolling window for tracking provider health, plus a recursive-descent condition parser for YAML-based routing rules. Reusable for any rate-limited service requiring health-aware routing.
CDPSession wrapper for Chrome DevTools Protocol with shared browser pooling, reference counting, idle shutdown, stealth injection, turnstile bypass, and Android WebView support. Well-crafted and could be extracted as a standalone library for browser automation.
Faithful Python transcription of ChatGPT's sentinel challenge VM, enabling programmatic solving of Cloudflare Turnstile challenges. Demonstrates non-obvious reverse-engineering skill and is self-contained for reuse in other projects needing Turnstile bypass.
Thread-safe singleton token manager with file-based persistence, TTL-based expiration, and cross-process locking via file locks. Reusable for any OAuth token caching scenario requiring persistence across process restarts.
Defines AbstractProvider, AsyncGeneratorProvider, and ProviderModelMixin with parameter handling, auth caching, and timeout logic. The foundation for all provider implementations, demonstrating clean abstraction design for pluggable backends.