File size: 3,547 Bytes
3de6346
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3dea3c0
3de6346
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env bash
set -e

# ── Colors ────────────────────────────────────────────────────────────────────
RED='\033[0;31m'; GREEN='\033[0;32m'; YELLOW='\033[1;33m'; NC='\033[0m'
info()  { echo -e "${GREEN}[setup]${NC} $*"; }
warn()  { echo -e "${YELLOW}[warn]${NC}  $*"; }
error() { echo -e "${RED}[error]${NC} $*"; exit 1; }

# ── Detect OS β€” Windows (Git Bash/MSYS) uses Scripts/, Unix uses bin/ ─────────
if [[ "$OSTYPE" == "msys" || "$OSTYPE" == "cygwin" || "$OSTYPE" == "win32" ]]; then
    VENV_ACTIVATE=".venv/Scripts/activate"
    ACTIVATE_HINT="source .venv/Scripts/activate"
else
    VENV_ACTIVATE=".venv/bin/activate"
    ACTIVATE_HINT="source .venv/bin/activate"
fi

# ── Prereq checks ─────────────────────────────────────────────────────────────
command -v python3 &>/dev/null || command -v python &>/dev/null || error "Python not found. Install Python 3.11+."
command -v node   &>/dev/null || error "node not found. Install Node.js 18+."
command -v npm    &>/dev/null || error "npm not found."

# Use whichever python command exists
PYTHON=$(command -v python3 2>/dev/null || command -v python)
PYTHON_VER=$("$PYTHON" -c "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')")
info "Python $PYTHON_VER detected"

# ── Backend ───────────────────────────────────────────────────────────────────
info "Setting up backend..."
cd backend

if [ ! -d ".venv" ]; then
    "$PYTHON" -m venv .venv
    info "Virtual environment created at backend/.venv"
fi

# shellcheck disable=SC1090
source "$VENV_ACTIVATE"

pip install --quiet --upgrade pip 2>/dev/null || true   # non-fatal on Windows
pip install --quiet litellm
pip install --quiet -r requirements.txt
info "Backend dependencies installed."

# ── .env ──────────────────────────────────────────────────────────────────────
if [ ! -f ".env" ]; then
    cat > .env <<'EOF'
# Required β€” get a free key at console.groq.com
GROQ_API_KEY=

# Required β€” get a free key at openrouter.ai/keys
OPENROUTER_API_KEY=
EOF
    warn ".env created β€” fill in your API keys before running the backend."
else
    info ".env already exists, skipping."
fi

deactivate
cd ..

# ── Frontend ──────────────────────────────────────────────────────────────────
info "Setting up frontend..."
cd frontend
npm install --silent
info "Frontend dependencies installed."
cd ..

# ── Done ──────────────────────────────────────────────────────────────────────
echo ""
echo -e "${GREEN}Setup complete.${NC}"
echo ""
echo "  Start backend:   cd backend && $ACTIVATE_HINT && uvicorn main:app --reload"
echo "  Start frontend:  cd frontend && npm run dev"
echo ""
warn "Make sure backend/.env has your GROQ_API_KEY and OPENROUTER_API_KEY set."