Spaces:
Sleeping
Sleeping
| @echo off | |
| setlocal enabledelayedexpansion | |
| echo ======================================== | |
| echo Starting IntegraChat Backend Server | |
| echo ======================================== | |
| echo. | |
| REM Get the directory where the batch file is located and move to project root | |
| cd /d "%~dp0" | |
| REM Validate project structure | |
| if not exist "backend" ( | |
| echo ERROR: backend directory not found! | |
| echo Please make sure you're running this from the project root. | |
| pause | |
| exit /b 1 | |
| ) | |
| if not exist "requirements.txt" ( | |
| echo ERROR: requirements.txt not found in project root! | |
| pause | |
| exit /b 1 | |
| ) | |
| REM Check if Python is available | |
| python --version >nul 2>&1 | |
| if errorlevel 1 ( | |
| echo ERROR: Python is not installed or not in PATH! | |
| echo Please install Python 3.10+ and add it to your PATH. | |
| pause | |
| exit /b 1 | |
| ) | |
| echo Python version: | |
| python --version | |
| echo. | |
| REM Create virtual environment if needed | |
| if not exist "venv\Scripts\activate.bat" ( | |
| echo Creating virtual environment... | |
| python -m venv venv | |
| if errorlevel 1 ( | |
| echo ERROR: Failed to create virtual environment! | |
| pause | |
| exit /b 1 | |
| ) | |
| ) | |
| REM Activate virtual environment | |
| echo Activating virtual environment... | |
| call venv\Scripts\activate.bat | |
| if errorlevel 1 ( | |
| echo ERROR: Failed to activate virtual environment! | |
| pause | |
| exit /b 1 | |
| ) | |
| echo. | |
| REM Install dependencies from root requirements.txt | |
| echo Installing/validating dependencies... | |
| pip install --upgrade pip >nul | |
| pip install -r requirements.txt | |
| if errorlevel 1 ( | |
| echo ERROR: Failed to install dependencies! | |
| pause | |
| exit /b 1 | |
| ) | |
| echo. | |
| REM Check if .env file exists in root | |
| if not exist ".env" ( | |
| echo Warning: .env file not found in project root! | |
| echo Please create .env from env.example if needed. | |
| echo. | |
| ) | |
| REM Prepare environment variables | |
| set PYTHONPATH=%cd% | |
| set "APP_PORT=8000" | |
| if not "%API_PORT%"=="" ( | |
| set "APP_PORT=%API_PORT%" | |
| ) | |
| set "VENV_PYTHON=%cd%\venv\Scripts\python.exe" | |
| if not exist "%VENV_PYTHON%" ( | |
| echo ERROR: Could not find python executable in venv! | |
| pause | |
| exit /b 1 | |
| ) | |
| REM Launch unified MCP server (in its own window so you can see logs) | |
| if not exist "backend\mcp_server\server.py" ( | |
| echo ERROR: backend\mcp_server\server.py not found! | |
| pause | |
| exit /b 1 | |
| ) | |
| REM Configure default MCP endpoints if not provided | |
| if "%MCP_PORT%"=="" ( | |
| set "MCP_PORT=8900" | |
| ) | |
| if "%RAG_MCP_URL%"=="" ( | |
| set "RAG_MCP_URL=http://localhost:%MCP_PORT%/rag" | |
| ) | |
| if "%WEB_MCP_URL%"=="" ( | |
| set "WEB_MCP_URL=http://localhost:%MCP_PORT%/web" | |
| ) | |
| if "%ADMIN_MCP_URL%"=="" ( | |
| set "ADMIN_MCP_URL=http://localhost:%MCP_PORT%/admin" | |
| ) | |
| echo. | |
| echo Launching unified MCP server (rag/web/admin)... | |
| start "Unified MCP" cmd /k ""%VENV_PYTHON%" -m backend.mcp_server.server" | |
| timeout /t 2 >nul | |
| echo Unified MCP server window opened (titled 'Unified MCP'). Close it manually to stop the MCP server. | |
| echo. | |
| REM Start the FastAPI server | |
| echo ======================================== | |
| echo Starting FastAPI server... | |
| echo Server will be available at: | |
| echo http://localhost:%APP_PORT% | |
| echo http://127.0.0.1:%APP_PORT% | |
| echo ======================================== | |
| echo. | |
| echo Press Ctrl+C to stop the server | |
| echo. | |
| python -m uvicorn backend.api.main:app --reload --host 0.0.0.0 --port %APP_PORT% | |
| if errorlevel 1 ( | |
| echo. | |
| echo ERROR: Failed to start the server! | |
| echo. | |
| echo Common issues: | |
| echo 1. Verify backend/api/main.py exists | |
| echo 2. Ensure dependencies installed correctly | |
| echo 3. Check if another process is using port %APP_PORT% | |
| echo. | |
| ) | |
| pause | |
| endlocal | |