-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdev.sh
More file actions
executable file
·103 lines (86 loc) · 2.81 KB
/
dev.sh
File metadata and controls
executable file
·103 lines (86 loc) · 2.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/bin/bash
# Store the base directory path
BASE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Function to check if directory exists
check_directory() {
if [ ! -d "$1" ]; then
echo -e "${RED}Error: Directory $1 does not exist!${NC}"
exit 1
fi
}
# Function to find available port starting from base_port
find_available_port() {
local base_port=$1
local port=$base_port
while lsof -i:$port >/dev/null 2>&1; do
port=$((port + 1))
done
echo $port
}
# Function to kill background processes on script exit
cleanup() {
echo -e "\n${YELLOW}Shutting down processes...${NC}"
jobs -p | xargs -r kill -15
exit 0
}
# Set up cleanup trap
trap cleanup EXIT INT TERM
# Check if Python is installed
if ! command -v python &> /dev/null; then
echo -e "${RED}Error: Python is not installed!${NC}"
exit 1
fi
# Check for virtual environment
VENV_DIR="$BASE_DIR/react-agent"
if [ ! -d "$VENV_DIR" ]; then
echo -e "${YELLOW}Creating virtual environment...${NC}"
python -m venv "$VENV_DIR"
fi
# Activate virtual environment
echo -e "${GREEN}Activating virtual environment...${NC}"
source "$VENV_DIR/bin/activate"
# Check if .env file exists
ENV_FILE="$BASE_DIR/.env"
if [ ! -f "$ENV_FILE" ]; then
echo -e "${RED}Error: .env file not found!${NC}"
echo -e "Please create a .env file with the following variables:"
echo -e "WATSONX_API_KEY=your_api_key"
echo -e "WATSONX_URL=your_url"
echo -e "WATSONX_PROJECT_ID=your_project_id"
echo -e "EMBEDDING_MODEL_ID=your_embedding_model"
echo -e "LLM_MODEL_ID=your_llm_model"
echo -e "QUERY_MODEL_ID=your_query_model"
exit 1
fi
# Find available port for the backend
BACKEND_PORT=$(find_available_port 8000)
# Add or update PORT in .env file without removing other variables
if grep -q "^PORT=" "$ENV_FILE"; then
# If PORT exists, update it
sed -i.bak "s/^PORT=.*/PORT=$BACKEND_PORT/" "$ENV_FILE" && rm "$ENV_FILE.bak"
else
# If PORT doesn't exist, append it
echo "PORT=$BACKEND_PORT" >> "$ENV_FILE"
fi
# Set up Python path to include project root and src
export PYTHONPATH="$BASE_DIR:$PYTHONPATH"
# # Check for required Python packages
# echo -e "${GREEN}Checking dependencies...${NC}"
# pip install -r requirements.txt >/dev/null 2>&1 || {
# echo -e "${RED}Error installing dependencies!${NC}"
# exit 1
# }
# Start the FastAPI backend
echo -e "${GREEN}Starting FastAPI backend...${NC}"
echo -e "Backend will be available at: ${GREEN}http://localhost:$BACKEND_PORT${NC}"
echo -e "${YELLOW}Press Ctrl+C to stop the process${NC}"
# Run from the api directory
cd "$BASE_DIR/api"
python -m uvicorn main:app --reload --port $BACKEND_PORT --workers 1 --app-dir "$BASE_DIR/api"
# Wait for the process
wait