| # Start script for the lightweight LLM service | |
| # This script handles environment setup and service startup | |
| set -e | |
| echo "π Starting Lightweight LLM with MCP Integration..." | |
| # Print configuration | |
| echo "π Configuration:" | |
| echo " Model: ${MODEL_NAME:-microsoft/DialoGPT-small}" | |
| echo " Port: ${PORT:-7860}" | |
| echo " MCP Server: ${MCP_SERVER_URL:-Not configured}" | |
| echo " Max Tokens: ${MAX_NEW_TOKENS:-256}" | |
| # Health check function | |
| health_check() { | |
| local max_attempts=30 | |
| local attempt=1 | |
| echo "π Waiting for service to be ready..." | |
| while [ $attempt -le $max_attempts ]; do | |
| if curl -f http://localhost:${PORT:-7860}/health >/dev/null 2>&1; then | |
| echo "β Service is ready!" | |
| return 0 | |
| fi | |
| echo "β³ Attempt $attempt/$max_attempts - waiting 2 seconds..." | |
| sleep 2 | |
| attempt=$((attempt + 1)) | |
| done | |
| echo "β Service failed to start within expected time" | |
| return 1 | |
| } | |
| # Start the application in the background | |
| echo "π Starting FastAPI application..." | |
| python app.py & | |
| APP_PID=$! | |
| # Wait for the service to be ready | |
| if health_check; then | |
| echo "π Lightweight LLM service is running successfully!" | |
| echo "π‘ API Documentation: http://localhost:${PORT:-7860}/docs" | |
| echo "π₯ Health Check: http://localhost:${PORT:-7860}/health" | |
| echo "βΉοΈ Service Info: http://localhost:${PORT:-7860}/info" | |
| # Keep the script running | |
| wait $APP_PID | |
| else | |
| echo "π₯ Failed to start service" | |
| kill $APP_PID 2>/dev/null || true | |
| exit 1 | |
| fi | |