mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-26 06:03:19 +00:00
* perf(cli): start lite without initializing the litellm SDK lite and litellm-proxy now enter through a small litellm_cli package that imports the CLI against an uninitialized litellm package and runs the SDK __init__ in place only when something first uses it, so commands start in a fraction of a second instead of loading about 3,000 modules first. * perf(cli): import only the lite subcommand being run Each lite subcommand now loads its module when Click looks it up, so lite logout no longer imports the autoroute wizard, agents, or the other command groups. importlib.import_module and attribute reads on the SDK also initialize it on first use, and an already imported litellm is kept as is. * fix(cli): initialize the SDK on a star import and test command bodies in thin mode A from litellm import * after lite loaded the CLI used to see only the names the thin package had, so it now runs the full SDK init first. The thin-vs-full parity test now also runs logout and whoami, not just --help * fix(cli): keep the import hooks until the lazy SDK init finishes A thread that imported SDK code after the init restored the interpreter imports could hold that module's import lock while waiting for the init, and the init then waited on the same lock, so both threads hung. Other threads now wait for the init before they load any new SDK code * fix(cli): retry a failed lazy SDK init on the next use instead of leaving it half-run * test(cli): bind the patched credentials client and autoroute dir in an order-independent way
24 lines
1.2 KiB
Python
24 lines
1.2 KiB
Python
import os
|
|
import warnings
|
|
|
|
import dotenv
|
|
|
|
|
|
def _dev_env_hot_reload_enabled() -> bool:
|
|
"""The proxy exports this flag when started with ``--reload``. A reloaded
|
|
worker is a fresh process that inherits the reloader's environment, so an
|
|
edited ``.env`` value stays masked by the stale inherited one unless we
|
|
let the file win; overriding makes the edit take effect on reload."""
|
|
return os.getenv("LITELLM_DEV_ENV_HOT_RELOAD") == "True"
|
|
|
|
|
|
def apply_process_defaults() -> None:
|
|
warnings.filterwarnings("ignore", message=".*conflict with protected namespace.*")
|
|
# Suppress Pydantic 2.11+ deprecation warning about accessing model_fields on instances
|
|
# This warning can accumulate during streaming and cause memory leaks
|
|
warnings.filterwarnings("ignore", message=".*Accessing the.*attribute on the instance is deprecated.*")
|
|
# ReadOnly on TypedDict fields is repo-wide static discipline (LIT012); pydantic warns it
|
|
# cannot enforce it at runtime, which floods proxy boot once such a type is schema-walked
|
|
warnings.filterwarnings("ignore", message=".*`ReadOnly` qualifier.*")
|
|
if os.getenv("LITELLM_MODE", "DEV") == "DEV":
|
|
dotenv.load_dotenv(override=_dev_env_hot_reload_enabled())
|