File size: 4,549 Bytes
0c3325c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# ─────────────────────────────────────────────────────────────────────────────
# OpenJev decision API — ZERO GPU (pure CPU)
#
# Official, unmodified openjev-server, pointed at llama.cpp (CPU GGUF) instead
# of vLLM:
#
#   1. builder  — compiles llama.cpp `llama-server` for CPU (no CUDA/HIP/Metal)
#                 and `pip install`s the official openjev-server package
#   2. runtime  — runs llama.cpp on CPU + openjev-server on $PORT (7860 on HF)
#
# Why this works: openjev-server's `vllm` backend is really "any OpenAI-
# compatible server that returns logprobs". It sends standard /chat/completions
# JSON (logprobs + top_logprobs + allowed_token_ids) and, when vLLM's
# `logprob_token_ids` extension is absent, falls back to matching the top-K
# logprobs by label text (see openjev_server/backends/vllm.py `_scores`).
# llama.cpp's OpenAI endpoint supports exactly that, so the official code path
# runs unmodified. --force is set because llama.cpp's chat template follows the
# GGUF so closely that the probe letter-mass check stays above the threshold.
#
# HF Spaces ingress  :7860  ->  openjev-server  (UI, /v1/systemone, /docs, ops)
# internal 127.0.0.1:8080   ->  llama.cpp (OpenAI-compatible, logprobs on)
# ─────────────────────────────────────────────────────────────────────────────

FROM python:3.12-slim AS builder
WORKDIR /build
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y --no-install-recommends \
        build-essential git cmake ninja-build curl ca-certificates \
    && rm -rf /var/lib/apt/lists/*

# ---- llama.cpp: CPU-only build (no CUDA/HIP/Metal flags anywhere) -----------
ARG LLAMA_CPP_REF=b4630
RUN git clone https://github.com/ggml-org/llama.cpp.git /llama.cpp \
    && cd /llama.cpp \
    && git checkout ${LLAMA_CPP_REF} \
    && git submodule update --init --depth 1 \
    && cmake -B build -DCMAKE_BUILD_TYPE=Release -DGGML_NATIVE=OFF -DGGML_CPU_ALL=ON \
    && cmake --build build --target llama-server -j"$(nproc)" \
    && cmake --install build --prefix /opt/llama

# ---- official openjev-server (unmodified, straight from the upstream repo) --
ARG OPENJEV_SERVER_REF=main
RUN git clone --depth 1 https://github.com/abhishekgahlot2/openjev-server.git /openjev-server \
    && cd /openjev-server \
    && git checkout ${OPENJEV_SERVER_REF} \
    && pip install --no-cache-dir . \
    && cp -r profiles /build/profiles

# ─────────────────────────────────────────────── runtime
FROM python:3.12-slim AS runtime
WORKDIR /app
ENV DEBIAN_FRONTEND=noninteractive \
    PYTHONUNBUFFERED=1 \
    PIP_NO_CACHE_DIR=1 \
    HF_HOME=/data/.cache/huggingface \
    OPENJEV_HOST=0.0.0.0 \
    OPENJEV_PORT=7860 \
    OPENJEV_BACKEND=vllm \
    OPENJEV_VLLM_URL=http://127.0.0.1:8080/v1 \
    OPENJEV_MODEL=openjev/openjev \
    OPENJEV_SERVED_MODEL_NAME=openjev \
    OPENJEV_PROFILE=openjev \
    OPENJEV_TOKEN="" \
    MODEL_REPO=openjev/openjev-GGUF \
    MODEL_FILE=OpenJev-Q4_K_M.gguf \
    TOKENIZER_REPO=openjev/openjev \
    LLAMA_THREADS="" \
    LLAMA_THREADS_BATCH="" \
    LLAMA_CTX=8192 \
    LLAMA_MAX_LOGPROBS=64 \
    LLAMA_PARALLEL=1 \
    LLAMA_PORT=8080

RUN apt-get update && apt-get install -y --no-install-recommends \
        curl ca-certificates libgomp1 \
    && rm -rf /var/lib/apt/lists/* \
    && useradd -m -u 1000 app \
    && mkdir -p /data /app/models \
    && curl -fsSL https://raw.githubusercontent.com/abhishekgahlot2/openjev-server/main/README.md -o /usr/share/OPENJEV-README.md

# llama.cpp runtime binaries
COPY --from=builder /opt/llama /opt/llama
ENV PATH="/opt/llama/bin:${PATH}"

# openjev-server (installed in builder)
COPY --from=builder /usr/local/lib/python3.12/site-packages /usr/local/lib/python3.12/site-packages
COPY --from=builder /usr/local/bin /usr/local/bin
COPY --from=builder /build/profiles /usr/local/lib/python3.12/site-packages/profiles

COPY entrypoint.sh ./
RUN chmod +x /app/entrypoint.sh \
    && chown -R app:app /data /app

USER app
EXPOSE 7860 8080
HEALTHCHECK --interval=30s --timeout=10s --start-period=900s --retries=3 \
    CMD curl -fsS http://127.0.0.1:7860/healthz || exit 1

ENTRYPOINT ["./entrypoint.sh"]