fix: deploy native llama-server sidecar from pre-built tarball (supports n_parallel, fixes fallback mode)
Browse filesFiles changed (2)
- Dockerfile+8-2
- start.sh+27-6
1234567FROM python:3.10-slim# No system-level binary installs needed — llama-cpp-python server is installed via pipWORKDIR /code12345678910111213FROM python:3.10-slim# Install curl and tar to download and extract pre-built native llama-serverRUN apt-get update && apt-get install -y curl tar && rm -rf /var/lib/apt/lists/*# Download native llama-server binary from official llama.cpp releasesRUN curl -L -s https://github.com/ggml-org/llama.cpp/releases/download/b9964/llama-b9964-bin-ubuntu-x64.tar.gz -o /tmp/llama.tar.gz \&& tar -xzf /tmp/llama.tar.gz -C /tmp \&& find /tmp -name 'llama-server' -type f | head -1 | xargs -I{} install -m 0755 {} /usr/local/bin/llama-server \&& rm -rf /tmp/llama.tar.gz /tmp/binWORKDIR /code
16 unmodified lines1718192021222324252627282913 unmodified lines43444546474816 unmodified linesecho "Model already exists at $MODEL_PATH"fi# 2. Set environment for the FastAPI app (uses llama-cpp-python directly, no sidecar needed)export MODEL_PATH="$MODEL_PATH"export LLM_MAX_TOKENS=2048export LLM_N_CTX=4096export LLM_N_THREADS=2# 3. Run ingest only if the collection is empty or new files existecho "Checking knowledge base..."CHROMA_COUNT=$(python -c "import sys13 unmodified linesecho "Knowledge base already indexed ($CHROMA_COUNT chunks). Skipping ingest."fi# 4. Start FastAPI server on port 7860 (Hugging Face default)echo "Starting FastAPI backend server on port 7860..."exec uvicorn app.main:app --host 0.0.0.0 --port 786016 unmodified lines1718192021222324252627282930313233343536373839404142434445464748495013 unmodified lines64656667686916 unmodified linesecho "Model already exists at $MODEL_PATH"fi# 2. Start native llama-server in the background (runs on CPU, port 8001)echo "Starting native llama-server on port 8001..."llama-server \--model "$MODEL_PATH" \--port 8001 \--host 127.0.0.1 \--ctx-size 6144 \--parallel 3 \--cont-batching \--threads 2 \--threads-batch 2 &# 3. Wait for the local llama.cpp server to be readyecho "Waiting for llama.cpp server to initialize..."until curl -s http://127.0.0.1:8001/v1/models > /dev/null; dosleep 2echo "Still waiting..."doneecho "llama.cpp server is ready!"# 4. Set environment variables to point FastAPI to the local llama.cpp serverexport OPENAI_BASE_URL="http://127.0.0.1:8001/v1"export LLM_BASE_URL="http://127.0.0.1:8001/v1"export MODEL_NAME="qwen2.5-3b-instruct-q4_k_m.gguf"export LLM_MODEL_NAME="qwen2.5-3b-instruct-q4_k_m.gguf"export LLM_MAX_TOKENS=2048# 5. Run ingest only if the collection is empty or new files existecho "Checking knowledge base..."CHROMA_COUNT=$(python -c "import sys13 unmodified linesecho "Knowledge base already indexed ($CHROMA_COUNT chunks). Skipping ingest."fi# 6. Start FastAPI server on port 7860 (Hugging Face default)echo "Starting FastAPI backend server on port 7860..."exec uvicorn app.main:app --host 0.0.0.0 --port 7860
Dockerfile+8-2
start.sh+27-6