Untitled
unknown
plain_text
10 days ago
7.8 kB
10
No Index
@echo off setlocal enabledelayedexpansion echo ====================================== echo LiteLLM Proxy Launcher echo ====================================== echo This script will: echo 1. Check for API keys in text files echo 2. Generate the configuration YAML echo 3. Launch LiteLLM with the configuration echo ====================================== echo. :: Step 1: Check for API keys in the text files echo [Step 1/3] Checking for API keys... set "keys_found=0" :: Check GeminiKeys.txt if exist "GeminiKeys.txt" ( for /f "tokens=*" %%a in (GeminiKeys.txt) do ( set "line=%%a" if not "!line!"=="" ( set /a keys_found+=1 echo Found API key in GeminiKeys.txt ) ) ) :: Check OpenRouterKeys.txt if exist "OpenRouterKeys.txt" ( for /f "tokens=*" %%a in (OpenRouterKeys.txt) do ( set "line=%%a" if not "!line!"=="" ( set /a keys_found+=1 echo Found API key in OpenRouterKeys.txt ) ) ) :: If no keys found, alert the user and exit if !keys_found! EQU 0 ( echo ERROR: No API keys found in either GeminiKeys.txt or OpenRouterKeys.txt echo. echo Please add at least one API key to one of the following files: echo - GeminiKeys.txt echo - OpenRouterKeys.txt echo. echo Then run this script again. pause goto :eof ) echo SUCCESS: Found !keys_found! API key(s). :: Step 2: Generate the configuration YAML in the litellm folder echo. echo [Step 2/3] Generating configuration YAML... :: Create the litellm directory if it doesn't exist if not exist "litellm" ( echo The litellm directory does not exist. Make sure you have run setup_litellm.bat first. pause goto :eof ) :: Create the output file with initial content ( echo model_list: ) > litellm\proxy_config.yaml :: Read all Gemini API keys set gemini_key_count=0 for /f "tokens=*" %%k in (GeminiKeys.txt) do ( set /a gemini_key_count+=1 set "gemini_key[!gemini_key_count!]=%%k" ) echo Found !gemini_key_count! Gemini API keys :: Read all OpenRouter API keys set or_key_count=0 if exist "OpenRouterKeys.txt" ( for /f "tokens=*" %%k in (OpenRouterKeys.txt) do ( set /a or_key_count+=1 set "or_key[!or_key_count!]=%%k" ) echo Found !or_key_count! OpenRouter API keys ) :: Read all Gemini models set gemini_model_count=0 for /f "tokens=1,2 delims=;" %%a in (GeminiModels.txt) do ( set /a gemini_model_count+=1 set "gemini_model_name[!gemini_model_count!]=%%a" set "gemini_model_id[!gemini_model_count!]=%%b" ) :: Read all OpenRouter models if available set or_model_count=0 if exist "OpenRouterModels.txt" ( for /f "tokens=1,2 delims=;" %%a in (OpenRouterModels.txt) do ( set /a or_model_count+=1 set "or_model_name[!or_model_count!]=%%a" set "or_model_id[!or_model_count!]=%%b" ) ) :: Create Gemini model entries for each model with each key for /l %%m in (1,1,%gemini_model_count%) do ( for /l %%k in (1,1,%gemini_key_count%) do ( echo - model_name: "!gemini_model_name[%%m]!" >> litellm\proxy_config.yaml echo litellm_params: >> litellm\proxy_config.yaml echo model: !gemini_model_id[%%m]! >> litellm\proxy_config.yaml echo api_key: !gemini_key[%%k]! >> litellm\proxy_config.yaml echo rpm: 60 >> litellm\proxy_config.yaml echo model_info: >> litellm\proxy_config.yaml echo id: "!gemini_model_id[%%m]!-key%%k" >> litellm\proxy_config.yaml echo. >> litellm\proxy_config.yaml ) ) :: Create OpenRouter model entries for each model with each key if %or_key_count% GTR 0 ( for /l %%m in (1,1,%or_model_count%) do ( for /l %%k in (1,1,%or_key_count%) do ( echo - model_name: "!or_model_name[%%m]!" >> litellm\proxy_config.yaml echo litellm_params: >> litellm\proxy_config.yaml echo model: openrouter/!or_model_id[%%m]! >> litellm\proxy_config.yaml echo api_key: !or_key[%%k]! >> litellm\proxy_config.yaml echo rpm: 60 >> litellm\proxy_config.yaml echo model_info: >> litellm\proxy_config.yaml echo id: "openrouter-!or_model_id[%%m]!-key%%k" >> litellm\proxy_config.yaml echo. >> litellm\proxy_config.yaml ) ) ) :: Create the litellm_settings section echo litellm_settings: >> litellm\proxy_config.yaml echo drop_params: True >> litellm\proxy_config.yaml echo num_retries: 5 >> litellm\proxy_config.yaml echo request_timeout: 120 >> litellm\proxy_config.yaml echo telemetry: False >> litellm\proxy_config.yaml echo fallbacks: [ >> litellm\proxy_config.yaml :: Add fallbacks for each Gemini model for /l %%m in (1,1,%gemini_model_count%) do ( echo { >> litellm\proxy_config.yaml echo "!gemini_model_name[%%m]!": [ >> litellm\proxy_config.yaml :: Add all Gemini keys as fallbacks for this model set "fallback_list=" for /l %%k in (1,1,%gemini_key_count%) do ( if %%k NEQ %gemini_key_count% ( set "fallback_list=!fallback_list!"!gemini_model_id[%%m]!-key%%k", " ) else ( set "fallback_list=!fallback_list!"!gemini_model_id[%%m]!-key%%k"" ) ) echo !fallback_list! >> litellm\proxy_config.yaml echo ] >> litellm\proxy_config.yaml echo }, >> litellm\proxy_config.yaml ) :: Add fallbacks for each OpenRouter model if %or_key_count% GTR 0 ( for /l %%m in (1,1,%or_model_count%) do ( echo { >> litellm\proxy_config.yaml echo "!or_model_name[%%m]!": [ >> litellm\proxy_config.yaml :: Add all OpenRouter keys as fallbacks for this model set "fallback_list=" for /l %%k in (1,1,%or_key_count%) do ( if %%k NEQ %or_key_count% ( set "fallback_list=!fallback_list!"openrouter-!or_model_id[%%m]!-key%%k", " ) else ( set "fallback_list=!fallback_list!"openrouter-!or_model_id[%%m]!-key%%k"" ) ) echo !fallback_list! >> litellm\proxy_config.yaml echo ] >> litellm\proxy_config.yaml echo }, >> litellm\proxy_config.yaml ) ) :: Close the fallbacks section echo ] >> litellm\proxy_config.yaml echo. >> litellm\proxy_config.yaml :: Add router and general settings (keep our original format) echo router_settings: >> litellm\proxy_config.yaml echo routing_strategy: simple-shuffle >> litellm\proxy_config.yaml echo load_balancing_strategy_config: >> litellm\proxy_config.yaml echo num_available_model_limit: 0 >> litellm\proxy_config.yaml echo. >> litellm\proxy_config.yaml echo general_settings: >> litellm\proxy_config.yaml echo master_key: sk-1234 >> litellm\proxy_config.yaml echo SUCCESS: Configuration file generated at litellm\proxy_config.yaml :: Step 3: Launch LiteLLM with the configuration echo. echo [Step 3/3] Launching LiteLLM proxy server... echo. echo The LiteLLM proxy server will now start. Press Ctrl+C to stop it when done. echo You can access the proxy at http://localhost:4000 once it's running. echo. echo Starting server... echo ====================================== cd litellm litellm --config proxy_config.yaml --port 4000 :: Note: The script execution will stop here while the server is running. :: When the server is stopped (using Ctrl+C), the script will continue. echo. echo ====================================== echo LiteLLM proxy server has been stopped. echo ====================================== cd .. pause
Editor is loading...
Leave a Comment