fix: deploy native llama-server sidecar from pre-built tarball (supports n_parallel, fixes fallback mode)
Browse files- Dockerfile +8 -2
- start.sh +27 -6
Dockerfile
CHANGED
|
@@ -1,7 +1,13 @@
|
|
| 1 |
FROM python:3.10-slim
|
| 2 |
|
| 3 |
-
#
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
WORKDIR /code
|
| 7 |
|
|
|
|
| 1 |
FROM python:3.10-slim
|
| 2 |
|
| 3 |
+
# Install curl and tar to download and extract pre-built native llama-server
|
| 4 |
+
RUN apt-get update && apt-get install -y curl tar && rm -rf /var/lib/apt/lists/*
|
| 5 |
+
|
| 6 |
+
# Download native llama-server binary from official llama.cpp releases
|
| 7 |
+
RUN 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 \
|
| 8 |
+
&& tar -xzf /tmp/llama.tar.gz -C /tmp \
|
| 9 |
+
&& find /tmp -name 'llama-server' -type f | head -1 | xargs -I{} install -m 0755 {} /usr/local/bin/llama-server \
|
| 10 |
+
&& rm -rf /tmp/llama.tar.gz /tmp/bin
|
| 11 |
|
| 12 |
WORKDIR /code
|
| 13 |
|
start.sh
CHANGED
|
@@ -17,13 +17,34 @@ else
|
|
| 17 |
echo "Model already exists at $MODEL_PATH"
|
| 18 |
fi
|
| 19 |
|
| 20 |
-
# 2.
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
export LLM_MAX_TOKENS=2048
|
| 23 |
-
export LLM_N_CTX=4096
|
| 24 |
-
export LLM_N_THREADS=2
|
| 25 |
|
| 26 |
-
#
|
| 27 |
echo "Checking knowledge base..."
|
| 28 |
CHROMA_COUNT=$(python -c "
|
| 29 |
import sys
|
|
@@ -43,6 +64,6 @@ else
|
|
| 43 |
echo "Knowledge base already indexed ($CHROMA_COUNT chunks). Skipping ingest."
|
| 44 |
fi
|
| 45 |
|
| 46 |
-
#
|
| 47 |
echo "Starting FastAPI backend server on port 7860..."
|
| 48 |
exec uvicorn app.main:app --host 0.0.0.0 --port 7860
|
|
|
|
| 17 |
echo "Model already exists at $MODEL_PATH"
|
| 18 |
fi
|
| 19 |
|
| 20 |
+
# 2. Start native llama-server in the background (runs on CPU, port 8001)
|
| 21 |
+
echo "Starting native llama-server on port 8001..."
|
| 22 |
+
llama-server \
|
| 23 |
+
--model "$MODEL_PATH" \
|
| 24 |
+
--port 8001 \
|
| 25 |
+
--host 127.0.0.1 \
|
| 26 |
+
--ctx-size 6144 \
|
| 27 |
+
--parallel 3 \
|
| 28 |
+
--cont-batching \
|
| 29 |
+
--threads 2 \
|
| 30 |
+
--threads-batch 2 &
|
| 31 |
+
|
| 32 |
+
# 3. Wait for the local llama.cpp server to be ready
|
| 33 |
+
echo "Waiting for llama.cpp server to initialize..."
|
| 34 |
+
until curl -s http://127.0.0.1:8001/v1/models > /dev/null; do
|
| 35 |
+
sleep 2
|
| 36 |
+
echo "Still waiting..."
|
| 37 |
+
done
|
| 38 |
+
echo "llama.cpp server is ready!"
|
| 39 |
+
|
| 40 |
+
# 4. Set environment variables to point FastAPI to the local llama.cpp server
|
| 41 |
+
export OPENAI_BASE_URL="http://127.0.0.1:8001/v1"
|
| 42 |
+
export LLM_BASE_URL="http://127.0.0.1:8001/v1"
|
| 43 |
+
export MODEL_NAME="qwen2.5-3b-instruct-q4_k_m.gguf"
|
| 44 |
+
export LLM_MODEL_NAME="qwen2.5-3b-instruct-q4_k_m.gguf"
|
| 45 |
export LLM_MAX_TOKENS=2048
|
|
|
|
|
|
|
| 46 |
|
| 47 |
+
# 5. Run ingest only if the collection is empty or new files exist
|
| 48 |
echo "Checking knowledge base..."
|
| 49 |
CHROMA_COUNT=$(python -c "
|
| 50 |
import sys
|
|
|
|
| 64 |
echo "Knowledge base already indexed ($CHROMA_COUNT chunks). Skipping ingest."
|
| 65 |
fi
|
| 66 |
|
| 67 |
+
# 6. Start FastAPI server on port 7860 (Hugging Face default)
|
| 68 |
echo "Starting FastAPI backend server on port 7860..."
|
| 69 |
exec uvicorn app.main:app --host 0.0.0.0 --port 7860
|