mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-03 02:22:24 +00:00
fix: load .env from CWD with upward fallback in non-interactive CLI mode
load_dotenv() without arguments relies on find_dotenv() to locate the .env file. The find_dotenv() function decides the search starting point based on the environment: - Interactive (REPL, python -c): _is_interactive() returns True -> starts from os.getcwd() (user's working directory) -> works - Non-interactive (installed CLI entry point via pip/uv): _is_interactive() returns False -> walks up the call stack from the caller's frame, which resolves to site-packages/litellm/ -> never finds the user's .env Fix: pass find_dotenv(usecwd=True) to load_dotenv(), anchoring the search to CWD while preserving python-dotenv's upward directory traversal for users who keep .env in a parent directory.
This commit is contained in:
parent
7bb5eb5bac
commit
efad980f67
2 changed files with 3 additions and 3 deletions
|
|
@ -17,7 +17,7 @@ import os
|
|||
import dotenv as _dotenv
|
||||
|
||||
if os.getenv("LITELLM_MODE", "DEV") == "DEV":
|
||||
_dotenv.load_dotenv()
|
||||
_dotenv.load_dotenv(dotenv_path=_dotenv.find_dotenv(usecwd=True))
|
||||
|
||||
from typing import (
|
||||
Callable,
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ from typing import TYPE_CHECKING, Any, Optional, Union
|
|||
|
||||
import click
|
||||
import httpx
|
||||
from dotenv import load_dotenv
|
||||
from dotenv import find_dotenv, load_dotenv
|
||||
|
||||
import litellm
|
||||
from litellm.constants import DEFAULT_NUM_WORKERS_LITELLM_PROXY
|
||||
|
|
@ -27,7 +27,7 @@ config_filename = "litellm.secrets"
|
|||
|
||||
litellm_mode = os.getenv("LITELLM_MODE", "DEV") # "PRODUCTION", "DEV"
|
||||
if litellm_mode == "DEV":
|
||||
load_dotenv()
|
||||
load_dotenv(find_dotenv(usecwd=True))
|
||||
from enum import Enum
|
||||
|
||||
telemetry = None
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue