import subprocess
import os

# Load environment variables from .env file
from dotenv import load_dotenv
load_dotenv()

# Default values (can be overridden by environment variables)
DEFAULT_PORT = 8000
DEFAULT_CONFIG_PATH = "config.yaml"

# Get port from environment variables, or use the default
port = int(os.getenv("PORT", DEFAULT_PORT))

# Get config path from environment variables, or use the default
config_path = os.getenv("CONFIG_PATH", DEFAULT_CONFIG_PATH)

# Construct the litellm command
command = [
    "litellm",
    "--config", config_path,
    "--port", str(port),
    "--model_list_route", "/models",
    "--health_route", "/health"
]

print(f"Starting LiteLLM router with command: {' '.join(command)}")

# Execute the command
process = subprocess.Popen(command)

# Optionally, you can add error handling and logging here
try:
    process.wait()
    print(f"LiteLLM router exited with code: {process.returncode}")
except KeyboardInterrupt:
    print("LiteLLM router terminated by user.")
    process.terminate()
except Exception as e:
    print(f"An error occurred: {e}")
