|
| 1 | +# GEMINI.md |
| 2 | + |
| 3 | +This file provides guidance to Gemini when working with code in this repository. |
| 4 | + |
| 5 | +## Development Commands |
| 6 | + |
| 7 | +### Installation |
| 8 | +- `make install-dev` - Install core development dependencies |
| 9 | +- `make install-proxy-dev` - Install proxy development dependencies with full feature set |
| 10 | +- `make install-test-deps` - Install all test dependencies |
| 11 | + |
| 12 | +### Testing |
| 13 | +- `make test` - Run all tests |
| 14 | +- `make test-unit` - Run unit tests (tests/test_litellm) with 4 parallel workers |
| 15 | +- `make test-integration` - Run integration tests (excludes unit tests) |
| 16 | +- `pytest tests/` - Direct pytest execution |
| 17 | + |
| 18 | +### Code Quality |
| 19 | +- `make lint` - Run all linting (Ruff, MyPy, Black, circular imports, import safety) |
| 20 | +- `make format` - Apply Black code formatting |
| 21 | +- `make lint-ruff` - Run Ruff linting only |
| 22 | +- `make lint-mypy` - Run MyPy type checking only |
| 23 | + |
| 24 | +### Single Test Files |
| 25 | +- `poetry run pytest tests/path/to/test_file.py -v` - Run specific test file |
| 26 | +- `poetry run pytest tests/path/to/test_file.py::test_function -v` - Run specific test |
| 27 | + |
| 28 | +## Architecture Overview |
| 29 | + |
| 30 | +LiteLLM is a unified interface for 100+ LLM providers with two main components: |
| 31 | + |
| 32 | +### Core Library (`litellm/`) |
| 33 | +- **Main entry point**: `litellm/main.py` - Contains core completion() function |
| 34 | +- **Provider implementations**: `litellm/llms/` - Each provider has its own subdirectory |
| 35 | +- **Router system**: `litellm/router.py` + `litellm/router_utils/` - Load balancing and fallback logic |
| 36 | +- **Type definitions**: `litellm/types/` - Pydantic models and type hints |
| 37 | +- **Integrations**: `litellm/integrations/` - Third-party observability, caching, logging |
| 38 | +- **Caching**: `litellm/caching/` - Multiple cache backends (Redis, in-memory, S3, etc.) |
| 39 | + |
| 40 | +### Proxy Server (`litellm/proxy/`) |
| 41 | +- **Main server**: `proxy_server.py` - FastAPI application |
| 42 | +- **Authentication**: `auth/` - API key management, JWT, OAuth2 |
| 43 | +- **Database**: `db/` - Prisma ORM with PostgreSQL/SQLite support |
| 44 | +- **Management endpoints**: `management_endpoints/` - Admin APIs for keys, teams, models |
| 45 | +- **Pass-through endpoints**: `pass_through_endpoints/` - Provider-specific API forwarding |
| 46 | +- **Guardrails**: `guardrails/` - Safety and content filtering hooks |
| 47 | +- **UI Dashboard**: Served from `_experimental/out/` (Next.js build) |
| 48 | + |
| 49 | +## Key Patterns |
| 50 | + |
| 51 | +### Provider Implementation |
| 52 | +- Providers inherit from base classes in `litellm/llms/base.py` |
| 53 | +- Each provider has transformation functions for input/output formatting |
| 54 | +- Support both sync and async operations |
| 55 | +- Handle streaming responses and function calling |
| 56 | + |
| 57 | +### Error Handling |
| 58 | +- Provider-specific exceptions mapped to OpenAI-compatible errors |
| 59 | +- Fallback logic handled by Router system |
| 60 | +- Comprehensive logging through `litellm/_logging.py` |
| 61 | + |
| 62 | +### Configuration |
| 63 | +- YAML config files for proxy server (see `proxy/example_config_yaml/`) |
| 64 | +- Environment variables for API keys and settings |
| 65 | +- Database schema managed via Prisma (`proxy/schema.prisma`) |
| 66 | + |
| 67 | +## Development Notes |
| 68 | + |
| 69 | +### Code Style |
| 70 | +- Uses Black formatter, Ruff linter, MyPy type checker |
| 71 | +- Pydantic v2 for data validation |
| 72 | +- Async/await patterns throughout |
| 73 | +- Type hints required for all public APIs |
| 74 | + |
| 75 | +### Testing Strategy |
| 76 | +- Unit tests in `tests/test_litellm/` |
| 77 | +- Integration tests for each provider in `tests/llm_translation/` |
| 78 | +- Proxy tests in `tests/proxy_unit_tests/` |
| 79 | +- Load tests in `tests/load_tests/` |
| 80 | + |
| 81 | +### Database Migrations |
| 82 | +- Prisma handles schema migrations |
| 83 | +- Migration files auto-generated with `prisma migrate dev` |
| 84 | +- Always test migrations against both PostgreSQL and SQLite |
| 85 | + |
| 86 | +### Enterprise Features |
| 87 | +- Enterprise-specific code in `enterprise/` directory |
| 88 | +- Optional features enabled via environment variables |
| 89 | +- Separate licensing and authentication for enterprise features |
0 commit comments