import os
import subprocess
def show_missing_vars_in_env():
from fastapi.responses import HTMLResponse
from litellm.proxy.proxy_server import master_key, prisma_client
if prisma_client is None and master_key is None:
return HTMLResponse(
content=missing_keys_form(
missing_key_names="DATABASE_URL, LITELLM_MASTER_KEY"
),
status_code=200,
)
if prisma_client is None:
return HTMLResponse(
content=missing_keys_form(missing_key_names="DATABASE_URL"), status_code=200
)
if master_key is None:
return HTMLResponse(
content=missing_keys_form(missing_key_names="LITELLM_MASTER_KEY"),
status_code=200,
)
return None
# LiteLLM Admin UI - Non SSO Login
url_to_redirect_to = os.getenv("PROXY_BASE_URL", "")
url_to_redirect_to += "/login"
html_form = f"""
LiteLLM Login
"""
def missing_keys_form(missing_key_names: str):
missing_keys_html_form = """
Environment Setup Instructions
Environment Setup Instructions
Please add the following variables to your environment variables:
LITELLM_MASTER_KEY="sk-1234"
LITELLM_SALT_KEY="sk-XXXXXXXX"
DATABASE_URL="postgres://..."
PORT=4000
STORE_MODEL_IN_DB="True"
Missing Environment Variables
{missing_keys}
"""
return missing_keys_html_form.format(missing_keys=missing_key_names)
def setup_admin_ui_on_server_root_path(server_root_path: str):
"""
Helper util to setup Admin UI on Server root path
"""
from litellm._logging import verbose_proxy_logger
if server_root_path != "":
print("setting proxy base url to server root path") # noqa
if os.getenv("PROXY_BASE_URL") is None:
os.environ["PROXY_BASE_URL"] = server_root_path
# re-build admin UI on server root path
# Save the original directory
original_dir = os.getcwd()
current_dir = (
os.path.dirname(os.path.abspath(__file__))
+ "/../../../ui/litellm-dashboard/"
)
build_ui_path = os.path.join(current_dir, "build_ui_custom_path.sh")
package_path = os.path.join(current_dir, "package.json")
print(f"Setting up Admin UI on {server_root_path}/ui .......") # noqa
try:
# Change the current working directory
os.chdir(current_dir)
# Make the script executable
subprocess.run(["chmod", "+x", "build_ui_custom_path.sh"], check=True)
# Run npm install
subprocess.run(["npm", "install"], check=True)
# Run npm run build
subprocess.run(["npm", "run", "build"], check=True)
# Run the custom build script with the argument
subprocess.run(
["./build_ui_custom_path.sh", f"{server_root_path}/ui"], check=True
)
print("Admin UI setup completed successfully.") # noqa
except subprocess.CalledProcessError as e:
print(f"An error occurred during the Admin UI setup: {e}") # noqa
except Exception as e:
print(f"An unexpected error occurred: {e}") # noqa
finally:
# Always return to the original directory, even if an error occurred
os.chdir(original_dir)
print(f"Returned to original directory: {original_dir}") # noqa
pass