forked from phoenix/litellm-mirror
build ui on custom path
This commit is contained in:
parent
dab556660d
commit
091449e81b
3 changed files with 68 additions and 6 deletions
|
@ -1,4 +1,5 @@
|
||||||
import os
|
import os
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
|
||||||
def show_missing_vars_in_env():
|
def show_missing_vars_in_env():
|
||||||
|
@ -165,3 +166,67 @@ def missing_keys_form(missing_key_names: str):
|
||||||
</html>
|
</html>
|
||||||
"""
|
"""
|
||||||
return missing_keys_html_form.format(missing_keys=missing_key_names)
|
return missing_keys_html_form.format(missing_keys=missing_key_names)
|
||||||
|
|
||||||
|
|
||||||
|
def setup_admin_ui_on_server_root_path():
|
||||||
|
"""
|
||||||
|
Helper util to setup Admin UI on Server root path
|
||||||
|
"""
|
||||||
|
from litellm._logging import verbose_proxy_logger
|
||||||
|
|
||||||
|
server_root_path = os.getenv("SERVER_ROOT_PATH", "")
|
||||||
|
if server_root_path != "":
|
||||||
|
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")
|
||||||
|
|
||||||
|
verbose_proxy_logger.debug(
|
||||||
|
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
|
||||||
|
)
|
||||||
|
|
||||||
|
verbose_proxy_logger.debug("Admin UI setup completed successfully.") # noqa
|
||||||
|
|
||||||
|
except subprocess.CalledProcessError as e:
|
||||||
|
verbose_proxy_logger.debug(
|
||||||
|
f"An error occurred during the Admin UI setup: {e}"
|
||||||
|
) # noqa
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
verbose_proxy_logger.debug(f"An unexpected error occurred: {e}")
|
||||||
|
|
||||||
|
finally:
|
||||||
|
# Always return to the original directory, even if an error occurred
|
||||||
|
os.chdir(original_dir)
|
||||||
|
verbose_proxy_logger.debug(
|
||||||
|
f"Returned to original directory: {original_dir}"
|
||||||
|
) # noqa
|
||||||
|
|
||||||
|
pass
|
||||||
|
|
|
@ -138,6 +138,7 @@ from litellm.proxy.auth.user_api_key_auth import user_api_key_auth
|
||||||
from litellm.proxy.caching_routes import router as caching_router
|
from litellm.proxy.caching_routes import router as caching_router
|
||||||
from litellm.proxy.common_utils.admin_ui_utils import (
|
from litellm.proxy.common_utils.admin_ui_utils import (
|
||||||
html_form,
|
html_form,
|
||||||
|
setup_admin_ui_on_server_root_path,
|
||||||
show_missing_vars_in_env,
|
show_missing_vars_in_env,
|
||||||
)
|
)
|
||||||
from litellm.proxy.common_utils.debug_utils import router as debugging_endpoints_router
|
from litellm.proxy.common_utils.debug_utils import router as debugging_endpoints_router
|
||||||
|
@ -282,8 +283,8 @@ except Exception as e:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
server_root_path = os.getenv("SERVER_ROOT_PATH", "")
|
server_root_path = os.getenv("SERVER_ROOT_PATH", "")
|
||||||
if server_root_path != "" and os.getenv("PROXY_BASE_URL") is None:
|
if server_root_path != "":
|
||||||
os.environ["PROXY_BASE_URL"] = server_root_path
|
setup_admin_ui_on_server_root_path()
|
||||||
_license_check = LicenseCheck()
|
_license_check = LicenseCheck()
|
||||||
premium_user: bool = _license_check.is_premium()
|
premium_user: bool = _license_check.is_premium()
|
||||||
ui_link = f"{server_root_path}/ui/"
|
ui_link = f"{server_root_path}/ui/"
|
||||||
|
|
|
@ -29,10 +29,6 @@ if [ $? -ne 0 ]; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# print contents of ui_colors.json
|
|
||||||
echo "Contents of ui_colors.json:"
|
|
||||||
cat ui_colors.json
|
|
||||||
|
|
||||||
# Run npm build with the environment variable
|
# Run npm build with the environment variable
|
||||||
UI_BASE_PATH=$UI_BASE_PATH npm run build
|
UI_BASE_PATH=$UI_BASE_PATH npm run build
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue