mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-25 18:54:30 +00:00
fix(proxy_cli.py): read db url from config, not just environment
This commit is contained in:
parent
2b9a4717fc
commit
43533812a7
2 changed files with 34 additions and 3 deletions
|
@ -268,10 +268,10 @@ async def acompletion(
|
||||||
elif asyncio.iscoroutine(init_response):
|
elif asyncio.iscoroutine(init_response):
|
||||||
response = await init_response
|
response = await init_response
|
||||||
else:
|
else:
|
||||||
response = init_response
|
response = init_response # type: ignore
|
||||||
else:
|
else:
|
||||||
# Call the synchronous function using run_in_executor
|
# Call the synchronous function using run_in_executor
|
||||||
response = await loop.run_in_executor(None, func_with_context)
|
response = await loop.run_in_executor(None, func_with_context) # type: ignore
|
||||||
# if kwargs.get("stream", False): # return an async generator
|
# if kwargs.get("stream", False): # return an async generator
|
||||||
# return _async_streaming(
|
# return _async_streaming(
|
||||||
# response=response,
|
# response=response,
|
||||||
|
|
|
@ -6,7 +6,6 @@ from datetime import datetime
|
||||||
import importlib
|
import importlib
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
|
|
||||||
sys.path.append(os.getcwd())
|
sys.path.append(os.getcwd())
|
||||||
|
|
||||||
config_filename = "litellm.secrets"
|
config_filename = "litellm.secrets"
|
||||||
|
@ -349,6 +348,38 @@ def run_server(
|
||||||
raise ImportError(
|
raise ImportError(
|
||||||
"Uvicorn, gunicorn needs to be imported. Run - `pip 'litellm[proxy]'`"
|
"Uvicorn, gunicorn needs to be imported. Run - `pip 'litellm[proxy]'`"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if config is not None:
|
||||||
|
"""
|
||||||
|
Allow user to pass in db url via config
|
||||||
|
|
||||||
|
read from there and save it to os.env['DATABASE_URL']
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
import yaml
|
||||||
|
except:
|
||||||
|
raise ImportError(
|
||||||
|
"yaml needs to be imported. Run - `pip install 'litellm[proxy]'`"
|
||||||
|
)
|
||||||
|
|
||||||
|
if os.path.exists(config):
|
||||||
|
with open(config, "r") as config_file:
|
||||||
|
config = yaml.safe_load(config_file)
|
||||||
|
general_settings = config.get("general_settings", {})
|
||||||
|
database_url = general_settings.get("database_url", None)
|
||||||
|
if database_url and database_url.startswith("os.environ/"):
|
||||||
|
original_dir = os.getcwd()
|
||||||
|
# set the working directory to where this script is
|
||||||
|
sys.path.insert(
|
||||||
|
0, os.path.abspath("../..")
|
||||||
|
) # Adds the parent directory to the system path - for litellm local dev
|
||||||
|
import litellm
|
||||||
|
|
||||||
|
database_url = litellm.get_secret(database_url)
|
||||||
|
os.chdir(original_dir)
|
||||||
|
if database_url is not None and isinstance(database_url, str):
|
||||||
|
os.environ["DATABASE_URL"] = database_url
|
||||||
|
|
||||||
if os.getenv("DATABASE_URL", None) is not None:
|
if os.getenv("DATABASE_URL", None) is not None:
|
||||||
# run prisma db push, before starting server
|
# run prisma db push, before starting server
|
||||||
# Save the current working directory
|
# Save the current working directory
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue