llm-api-backend / start.sh
cygon
intial commit
48e767e
#!/bin/bash
set -e
echo "πŸš€ Starting LLM API Backend..."
echo "πŸ“ Working directory: $(pwd)"
echo "πŸ”’ Node version: $(node --version)"
# Change to backend directory
cd /app/backend
# Verify Encore CLI is available
if ! command -v encore &> /dev/null; then
echo "❌ ERROR: Encore CLI not found in PATH"
echo "Available binaries:"
ls -la /usr/local/bin/ | grep encore || echo "No encore binary found"
ls -la /root/.encore/bin/ 2>/dev/null | grep encore || echo "No encore binary in home"
exit 1
fi
echo "βœ… Encore CLI found: $(which encore)"
echo "πŸ“¦ Encore version: $(encore version)"
# Configure secrets from environment variables
echo "πŸ” Configuring secrets from environment..."
if [ -z "$LLMProvider" ]; then
echo "⚠️ Warning: LLMProvider not set. Please configure in Space settings."
echo " Add: LLMProvider = 'huggingface' or 'ollama'"
else
echo "βœ… LLMProvider: $LLMProvider"
encore secret set --type=local LLMProvider "$LLMProvider" 2>/dev/null || echo " Note: Secret may already be set"
fi
if [ "$LLMProvider" = "huggingface" ]; then
if [ -z "$HuggingFaceAPIKey" ]; then
echo "❌ ERROR: HuggingFaceAPIKey required for Hugging Face provider"
exit 1
else
echo "βœ… HuggingFaceAPIKey configured"
encore secret set --type=local HuggingFaceAPIKey "$HuggingFaceAPIKey" 2>/dev/null || echo " Note: Secret may already be set"
fi
if [ -n "$DefaultModel" ]; then
echo "βœ… DefaultModel: $DefaultModel"
encore secret set --type=local DefaultModel "$DefaultModel" 2>/dev/null || echo " Note: Secret may already be set"
fi
fi
if [ "$LLMProvider" = "ollama" ]; then
if [ -z "$OllamaBaseURL" ]; then
echo "⚠️ Warning: OllamaBaseURL not set for Ollama provider"
echo " Add: OllamaBaseURL = 'http://localhost:11434'"
else
echo "βœ… OllamaBaseURL: $OllamaBaseURL"
encore secret set --type=local OllamaBaseURL "$OllamaBaseURL" 2>/dev/null || echo " Note: Secret may already be set"
fi
fi
# Start the application
echo ""
echo "✨ Starting Encore application on port ${PORT:-7860}..."
echo "πŸ“‘ Health endpoint: http://localhost:${PORT:-7860}/health"
echo "πŸ’¬ Chat endpoint: http://localhost:${PORT:-7860}/chat"
echo ""
exec encore run --port="${PORT:-7860}"