Skip to content

Commit 5eb9312

Browse files
committed
Best practices applied to all remaining files
1 parent 8307fa3 commit 5eb9312

File tree

5 files changed

+60
-26
lines changed

5 files changed

+60
-26
lines changed

launch.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
#!/bin/bash
22

3+
############################################################
4+
# launch.sh - Bootstrap script for LiteLLM Service
5+
# Launches the main interactive menu.
6+
############################################################
7+
38
# Minimal bootstrap, defer to menu script
49
if [ -f src/menu.sh ]; then
510
source src/menu.sh

src/common.sh

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,36 @@
33
set -Eeuo pipefail
44
IFS=$'\n\t'
55

6-
# Load environment if present
6+
############################################################
7+
# common.sh - Shared functions and environment setup for LiteLLM Service
8+
# This script loads environment variables, sets defaults, and provides utility functions.
9+
############################################################
10+
11+
# Load environment variables from .env if not already loaded
712
if [ -z "${COMMON_ENV_LOADED:-}" ]; then
813
if [ -f src/config/.env ]; then
914
source src/config/.env
1015
fi
1116
export COMMON_ENV_LOADED=1
1217
fi
1318

14-
# Defaults
19+
# Default values for key variables
1520
: "${CUSTOM_MODEL_NAME:=elon}"
1621
: "${CUSTOM_MODEL_FILE:=src/model/developer}"
1722
: "${LITELLM_HOST:=127.0.0.1}"
1823
: "${LITELLM_PORT:=4000}"
1924
: "${OLLAMA_API_BASE:=http://localhost:11434}"
2025

21-
# Directories
26+
# Directory for logs
2227
LOG_DIR="./.log"
2328

29+
# Ensure the log directory exists
2430
function ensure_log_dir() {
2531
mkdir -p "$LOG_DIR"
2632
}
2733

34+
# Prompt for a required value if not set
35+
# Usage: require_value VAR_NAME PROMPT [DEFAULT]
2836
function require_value() {
2937
local var_name="$1"
3038
local prompt="$2"
@@ -33,9 +41,10 @@ function require_value() {
3341
local current_value="${!var_name:-}"
3442

3543
if [ -z "$current_value" ]; then
44+
local input
3645
if [ -n "$default_value" ]; then
3746
read -p "$prompt [$default_value]: " input
38-
if [ -z "${input:-}" ]; then input="$default_value"; fi
47+
if [ -z "$input" ]; then input="$default_value"; fi
3948
else
4049
read -p "$prompt: " input
4150
fi

src/cursor.sh

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,43 @@
11
#!/bin/bash
22

3-
function cursor_start(){
4-
# Start cursor after running the proxy
3+
4+
############################################################
5+
# cursor.sh - Functions for integrating Cursor editor with LiteLLM Service
6+
# Provides automation and health-check utilities for Cursor.
7+
############################################################
8+
9+
# Start Cursor after running the LiteLLM proxy
10+
function cursor_start() {
511
source ./src/common.sh
612
source ./src/litellm.sh
713
class_LiteLLMProxy proxy
814

9-
proxy.check_status "$customModelName" || proxy.start_bg "$customModelName"
15+
local model_name="$CUSTOM_MODEL_NAME"
16+
proxy.check_status "$model_name" || proxy.start_bg "$model_name"
1017

11-
# Launch Cursor
18+
# Launch Cursor editor
1219
"C:\Users\<you>\AppData\Local\Programs\cursor\Cursor.exe"
1320
}
1421

15-
function cursor_scheduler(){
16-
# Create a scheduled task that runs at user login
17-
$PATH_TO_PROJECT="C:\path\to\your\project"
18-
bash -lc 'cd $PATH_TO_PROJECT && ./src/menu.sh --auto-start'
22+
# Create a scheduled task that runs at user login to auto-start the service
23+
function cursor_scheduler() {
24+
local PATH_TO_PROJECT="C:\path\to\your\project"
25+
bash -lc "cd $PATH_TO_PROJECT && ./src/menu.sh --auto-start"
1926
}
2027

2128
# Proxy health-check in Cursor
22-
function cursor_health_check(){
29+
function cursor_health_check() {
2330
source ./src/common.sh
2431
source ./src/litellm.sh
25-
2632
class_LiteLLMProxy proxy
2733

28-
proxy.check_status "$customModelName" || proxy.start_bg "$customModelName"
34+
local model_name="$CUSTOM_MODEL_NAME"
35+
proxy.check_status "$model_name" || proxy.start_bg "$model_name"
2936

30-
# Launch Cursor
37+
# Launch Cursor editor
3138
"C:\Users\<you>\AppData\Local\Programs\cursor\Cursor.exe"
3239
}
40+
3341
# Note: Cursor does not support custom ports or hosts for LLM API.
3442
# It always calls localhost:4000.
35-
36-
# To change the port, you must modify the LiteLLM proxy to listen on port 4000.
37-
# This can be done by changing the LITELLM_PORT variable in src/common.sh to 4000
38-
# and restarting the proxy.
43+
# To change the port, modify LITELLM_PORT in src/common.sh and restart the proxy.

src/litellm.sh

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,28 @@
11
#!/bin/bash
22

3+
############################################################
4+
# litellm.sh - Functions for managing LiteLLM proxy lifecycle
5+
# Includes install, upgrade, start, and background start utilities.
6+
############################################################
7+
38
source "$(dirname "$0")/common.sh"
49

5-
function litellm_install(){
10+
# Install LiteLLM proxy
11+
function litellm_install() {
612
need_cmd pip
713
info "Installing LiteLLM proxy..."
814
pip install "litellm[proxy]"
915
}
1016

11-
function litellm_upgrade(){
17+
# Upgrade LiteLLM proxy
18+
function litellm_upgrade() {
1219
need_cmd pip
1320
info "Upgrading LiteLLM proxy..."
1421
pip install --upgrade "litellm[proxy]"
1522
}
1623

17-
function litellm_start(){
24+
# Start LiteLLM proxy for the selected Ollama model
25+
function litellm_start() {
1826
need_cmd litellm
1927
require_value CUSTOM_MODEL_NAME "Enter model name" "$CUSTOM_MODEL_NAME"
2028

@@ -23,7 +31,8 @@ function litellm_start(){
2331
--model "ollama/$CUSTOM_MODEL_NAME" --api_base "$OLLAMA_API_BASE"
2432
}
2533

26-
function litellm_start_bg(){
34+
# Start LiteLLM proxy in the background and log output
35+
function litellm_start_bg() {
2736
need_cmd litellm
2837
require_value CUSTOM_MODEL_NAME "Enter model name" "$CUSTOM_MODEL_NAME"
2938

@@ -37,7 +46,7 @@ function litellm_start_bg(){
3746
--model "ollama/$CUSTOM_MODEL_NAME" --api_base "$OLLAMA_API_BASE" \
3847
> "$logfile" 2>&1 &
3948
echo $! > "${LOG_DIR}/litellm_${CUSTOM_MODEL_NAME}.pid"
40-
info "LiteLLM proxy started with PID $(cat ${LOG_DIR}/litellm_${CUSTOM_MODEL_NAME}.pid)"
49+
info "LiteLLM proxy started with PID $(cat "${LOG_DIR}/litellm_${CUSTOM_MODEL_NAME}.pid")"
4150
}
4251

4352
function litellm_stop(){

src/menu.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
#!/bin/bash
22

3+
############################################################
4+
# menu.sh - Main interactive menu for LiteLLM Service
5+
# Presents options for model management, proxy control, and integrations.
6+
############################################################
7+
38
source "$(dirname "$0")/common.sh"
49
source "$(dirname "$0")/model.sh"
510
source "$(dirname "$0")/litellm.sh"
611
source "$(dirname "$0")/cursor.sh"
712

13+
# Display the main menu and handle user selection
814
function main_menu() {
915
while true; do
1016
clear
@@ -26,7 +32,7 @@ function main_menu() {
2632
echo "================================="
2733
read -p "Select an option: " choice
2834

29-
case $choice in
35+
case "$choice" in
3036
1) model_select ;;
3137
2) model_create ;;
3238
3) model_test ;;

0 commit comments

Comments
 (0)