File size: 2,348 Bytes
86042ad
35d653a
86042ad
 
48e767e
 
86042ad
35d653a
 
 
 
86042ad
48e767e
 
 
 
35d653a
86042ad
 
48e767e
 
35d653a
 
48e767e
86042ad
48e767e
 
 
 
 
 
86042ad
 
48e767e
 
 
 
 
 
 
 
 
 
 
 
 
86042ad
 
48e767e
 
 
 
 
 
 
 
86042ad
 
 
48e767e
 
 
 
 
 
35d653a
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
#!/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}"