Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ jobs:
with:
persist-credentials: false

- name: Setup python 3.11
- name: Setup python 3.13
uses: actions/setup-python@42375524e23c412d93fb67b49958b491fce71c38 # v5
with:
python-version: '3.11'
python-version: '3.13'
cache: 'pip'
cache-dependency-path: |
requirements.txt
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ jobs:
with:
persist-credentials: false

- name: Setup python 3.11
- name: Setup python 3.13
uses: actions/setup-python@42375524e23c412d93fb67b49958b491fce71c38 # v5
with:
python-version: '3.11'
python-version: '3.13'

# The repair runner only depends on the standard library, so the heavy
# runtime requirements are deliberately not installed here.
Expand Down
91 changes: 62 additions & 29 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,16 @@
#
ARG UBUNTU_VERSION=24.04
ARG CUDA_VERSION=12.8.2
ARG LLAMA_CPP_PYTHON_VERSION=0.3.23
ARG LLAMA_CPP_PYTHON_VERSION=0.3.36
# torch comes from a per-flavour index, so requirements.txt's torch lines are
# dropped in the runtime stages. TORCH_VERSION matches requirements.txt; the cu128
# index has nothing newer than CUDA_TORCH_VERSION.
ARG TORCH_VERSION=2.14.1
ARG TORCHVISION_VERSION=0.29.1
ARG CUDA_TORCH_VERSION=2.11.0
ARG CUDA_TORCHVISION_VERSION=0.26.0
ARG CUDA_TORCH_INDEX=cu128
ARG ROCM_TORCH_INDEX=rocm7.14

ARG BASE_IMAGE=ubuntu:${UBUNTU_VERSION}
ARG CUDA_DEVEL_IMAGE=nvidia/cuda:${CUDA_VERSION}-devel-ubuntu${UBUNTU_VERSION}
Expand All @@ -27,18 +36,18 @@ ARG LLAMA_CPP_PYTHON_VERSION

ENV DEBIAN_FRONTEND=noninteractive
WORKDIR /build
ADD dockerfile_scripts/install_py11.sh dockerfile_scripts/install_py11.sh
RUN ./dockerfile_scripts/install_py11.sh
ADD dockerfile_scripts/install_py.sh dockerfile_scripts/install_py.sh
RUN ./dockerfile_scripts/install_py.sh
# gcc-14: Ubuntu 24.04 ships gcc-13 by default; gcc-14 is used for
# consistency across all builder stages and better C++23 support.
RUN apt-get install -y --no-install-recommends \
python3.11-dev \
python3.13-dev \
cmake build-essential ninja-build git \
gcc-14 g++-14 \
libgomp1 \
&& rm -rf /var/lib/apt/lists/*

RUN /usr/bin/python3.11 -m venv /opt/venv \
RUN /usr/bin/python3.13 -m venv /opt/venv \
&& /opt/venv/bin/python -m pip install --no-cache-dir --upgrade pip setuptools wheel

ENV CC=gcc-14 CXX=g++-14
Expand Down Expand Up @@ -73,16 +82,16 @@ ARG LLAMA_CPP_PYTHON_VERSION

ENV DEBIAN_FRONTEND=noninteractive
WORKDIR /build
ADD dockerfile_scripts/install_py11.sh dockerfile_scripts/install_py11.sh
RUN ./dockerfile_scripts/install_py11.sh
ADD dockerfile_scripts/install_py.sh dockerfile_scripts/install_py.sh
RUN ./dockerfile_scripts/install_py.sh
RUN apt-get install -y --no-install-recommends \
python3.11-dev \
python3.13-dev \
cmake build-essential ninja-build git \
gcc-14 g++-14 \
libgomp1 \
&& rm -rf /var/lib/apt/lists/*

RUN /usr/bin/python3.11 -m venv /opt/venv \
RUN /usr/bin/python3.13 -m venv /opt/venv \
&& /opt/venv/bin/python -m pip install --no-cache-dir --upgrade pip setuptools wheel

# Make the CUDA compat stub visible to the linker for both executables and shared libs
Expand Down Expand Up @@ -117,19 +126,19 @@ ARG LLAMA_CPP_PYTHON_VERSION

ENV DEBIAN_FRONTEND=noninteractive
WORKDIR /build
ADD dockerfile_scripts/install_py11.sh dockerfile_scripts/install_py11.sh
RUN ./dockerfile_scripts/install_py11.sh
ADD dockerfile_scripts/install_py.sh dockerfile_scripts/install_py.sh
RUN ./dockerfile_scripts/install_py.sh
# Vulkan headers + glslc (shader compiler) are build-time only
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
python3.11-dev \
python3.13-dev \
cmake build-essential ninja-build git \
gcc-14 g++-14 \
libgomp1 \
libvulkan-dev glslc spirv-headers \
&& rm -rf /var/lib/apt/lists/*

RUN /usr/bin/python3.11 -m venv /opt/venv \
RUN /usr/bin/python3.13 -m venv /opt/venv \
&& /opt/venv/bin/python -m pip install --no-cache-dir --upgrade pip setuptools wheel

ENV CC=gcc-14 CXX=g++-14
Expand All @@ -147,6 +156,8 @@ RUN /opt/venv/bin/python -m pip wheel \
# CPU / ARM runtime
# ============================================================
FROM ${BASE_IMAGE} AS runtime-cpu
ARG TORCH_VERSION
ARG TORCHVISION_VERSION

ARG CCB_DB_NAME=ccb
ARG CCB_DB_USER=ccbuser
Expand All @@ -161,28 +172,31 @@ WORKDIR /app

ADD dockerfile_scripts/install_deps.sh dockerfile_scripts/install_deps.sh
RUN ./dockerfile_scripts/install_deps.sh
ADD dockerfile_scripts/install_py11.sh dockerfile_scripts/install_py11.sh
RUN ./dockerfile_scripts/install_py11.sh
ADD dockerfile_scripts/install_py.sh dockerfile_scripts/install_py.sh
RUN ./dockerfile_scripts/install_py.sh
ADD dockerfile_scripts/pgsql dockerfile_scripts/pgsql
RUN ./dockerfile_scripts/pgsql/install.sh
ADD dockerfile_scripts/install_frpc.sh dockerfile_scripts/install_frpc.sh
RUN ./dockerfile_scripts/install_frpc.sh
RUN apt-get autoclean
RUN apt-get update \
&& apt-get upgrade -y \
&& apt-get autoclean \
&& rm -rf /var/lib/apt/lists/*
ADD dockerfile_scripts/entrypoint.sh dockerfile_scripts/entrypoint.sh

ENV DEBIAN_FRONTEND=dialog

# Install llama_cpp_python from the CPU builder wheel
COPY --from=llama-builder-cpu /wheels /wheels
RUN /usr/bin/python3.11 -m venv /opt/venv \
RUN /usr/bin/python3.13 -m venv /opt/venv \
&& /opt/venv/bin/python -m pip install --no-cache-dir --upgrade pip setuptools wheel \
&& /opt/venv/bin/python -m pip install --no-cache-dir --no-index --find-links=/wheels llama-cpp-python \
&& /opt/venv/bin/python -m pip install --no-cache-dir torch torchvision --index-url https://download.pytorch.org/whl/cpu \
&& /opt/venv/bin/python -m pip install --no-cache-dir "torch==${TORCH_VERSION}" "torchvision==${TORCHVISION_VERSION}" --index-url https://download.pytorch.org/whl/cpu \
&& rm -rf /wheels \
&& /opt/venv/bin/python -m pip cache purge

COPY requirements.txt .
RUN sed -i '/^llama_cpp_python/d' requirements.txt \
RUN sed -Ei '/^(llama_cpp_python|torch|torchvision)[[:space:]]*[><=~!]/d' requirements.txt \
&& /opt/venv/bin/python -m pip install --no-cache-dir -r requirements.txt \
&& /opt/venv/bin/python -m pip cache purge

Expand All @@ -201,6 +215,9 @@ ENTRYPOINT ["supervisord", "-c", "/etc/supervisor/supervisord.conf"]
# CUDA (NVIDIA GPU) runtime
# ============================================================
FROM ${CUDA_RUNTIME_IMAGE} AS runtime-cuda
ARG CUDA_TORCH_VERSION
ARG CUDA_TORCHVISION_VERSION
ARG CUDA_TORCH_INDEX

ARG CCB_DB_NAME=ccb
ARG CCB_DB_USER=ccbuser
Expand All @@ -217,13 +234,16 @@ WORKDIR /app

ADD dockerfile_scripts/install_deps.sh dockerfile_scripts/install_deps.sh
RUN ./dockerfile_scripts/install_deps.sh
ADD dockerfile_scripts/install_py11.sh dockerfile_scripts/install_py11.sh
RUN ./dockerfile_scripts/install_py11.sh
ADD dockerfile_scripts/install_py.sh dockerfile_scripts/install_py.sh
RUN ./dockerfile_scripts/install_py.sh
ADD dockerfile_scripts/pgsql dockerfile_scripts/pgsql
RUN ./dockerfile_scripts/pgsql/install.sh
ADD dockerfile_scripts/install_frpc.sh dockerfile_scripts/install_frpc.sh
RUN ./dockerfile_scripts/install_frpc.sh
RUN apt-get autoclean
RUN apt-get update \
&& apt-get upgrade -y \
&& apt-get autoclean \
&& rm -rf /var/lib/apt/lists/*
ADD dockerfile_scripts/entrypoint.sh dockerfile_scripts/entrypoint.sh

ENV DEBIAN_FRONTEND=dialog
Expand All @@ -234,14 +254,17 @@ RUN ln -s /usr/local/cuda/lib64/stubs/libcuda.so /usr/local/lib/libcuda.so \
ENV LD_LIBRARY_PATH="/usr/local/lib:/usr/local/cuda/lib64:/usr/local/cuda/lib64/stubs:${LD_LIBRARY_PATH}"

COPY --from=llama-builder-cuda /wheels /wheels
RUN /usr/bin/python3.11 -m venv /opt/venv \
# torch from PyPI bundles CUDA 13 libraries, which need a newer driver than the
# CUDA 12.8 base image targets, so it comes from CUDA_TORCH_INDEX instead
RUN /usr/bin/python3.13 -m venv /opt/venv \
&& /opt/venv/bin/python -m pip install --no-cache-dir --upgrade pip setuptools wheel \
&& /opt/venv/bin/python -m pip install --no-cache-dir --no-index --find-links=/wheels llama-cpp-python \
&& /opt/venv/bin/python -m pip install --no-cache-dir "torch==${CUDA_TORCH_VERSION}" "torchvision==${CUDA_TORCHVISION_VERSION}" --index-url "https://download.pytorch.org/whl/${CUDA_TORCH_INDEX}" \
&& rm -rf /wheels \
&& /opt/venv/bin/python -m pip cache purge

COPY requirements.txt .
RUN sed -i '/^llama_cpp_python/d' requirements.txt \
RUN sed -Ei '/^(llama_cpp_python|torch|torchvision)[[:space:]]*[><=~!]/d' requirements.txt \
&& /opt/venv/bin/python -m pip install --no-cache-dir -r requirements.txt \
&& /opt/venv/bin/python -m pip cache purge

Expand All @@ -263,6 +286,10 @@ ENTRYPOINT ["supervisord", "-c", "/etc/supervisor/supervisord.conf"]
# GCN, RDNA1/2/3 and newer AMD GPUs out of the box.
# ============================================================
FROM ${BASE_IMAGE} AS runtime-vulkan
ARG TARGETARCH
ARG TORCH_VERSION
ARG TORCHVISION_VERSION
ARG ROCM_TORCH_INDEX

ARG CCB_DB_NAME=ccb
ARG CCB_DB_USER=ccbuser
Expand All @@ -277,13 +304,16 @@ WORKDIR /app

ADD dockerfile_scripts/install_deps.sh dockerfile_scripts/install_deps.sh
RUN ./dockerfile_scripts/install_deps.sh
ADD dockerfile_scripts/install_py11.sh dockerfile_scripts/install_py11.sh
RUN ./dockerfile_scripts/install_py11.sh
ADD dockerfile_scripts/install_py.sh dockerfile_scripts/install_py.sh
RUN ./dockerfile_scripts/install_py.sh
ADD dockerfile_scripts/pgsql dockerfile_scripts/pgsql
RUN ./dockerfile_scripts/pgsql/install.sh
ADD dockerfile_scripts/install_frpc.sh dockerfile_scripts/install_frpc.sh
RUN ./dockerfile_scripts/install_frpc.sh
RUN apt-get autoclean
RUN apt-get update \
&& apt-get upgrade -y \
&& apt-get autoclean \
&& rm -rf /var/lib/apt/lists/*
ADD dockerfile_scripts/entrypoint.sh dockerfile_scripts/entrypoint.sh

# Install Vulkan runtime + AMD RADV open-source driver
Expand All @@ -296,14 +326,17 @@ ENV DEBIAN_FRONTEND=dialog

# Install llama_cpp_python from the Vulkan builder wheel
COPY --from=llama-builder-vulkan /wheels /wheels
RUN /usr/bin/python3.11 -m venv /opt/venv \
# ROCm torch is only published for x86_64; arm64 gets the CPU build
RUN if [ "$TARGETARCH" = "amd64" ]; then TORCH_INDEX="$ROCM_TORCH_INDEX"; else TORCH_INDEX=cpu; fi \
&& /usr/bin/python3.13 -m venv /opt/venv \
&& /opt/venv/bin/python -m pip install --no-cache-dir --upgrade pip setuptools wheel \
&& /opt/venv/bin/python -m pip install --no-cache-dir --no-index --find-links=/wheels llama-cpp-python \
&& /opt/venv/bin/python -m pip install --no-cache-dir "torch==${TORCH_VERSION}" "torchvision==${TORCHVISION_VERSION}" --index-url "https://download.pytorch.org/whl/${TORCH_INDEX}" \
&& rm -rf /wheels \
&& /opt/venv/bin/python -m pip cache purge

COPY requirements.txt .
RUN sed -i '/^llama_cpp_python/d' requirements.txt \
RUN sed -Ei '/^(llama_cpp_python|torch|torchvision)[[:space:]]*[><=~!]/d' requirements.txt \
&& /opt/venv/bin/python -m pip install --no-cache-dir -r requirements.txt \
&& /opt/venv/bin/python -m pip cache purge

Expand Down
2 changes: 1 addition & 1 deletion context_chat_backend/chain/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
import logging

from langchain.schema import Document
from langchain_core.documents import Document

from ..dyn_loader import VectorDBLoader
from ..vectordb.base import BaseVectorDB
Expand Down
2 changes: 1 addition & 1 deletion context_chat_backend/chain/ingest/doc_splitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
from functools import lru_cache

from langchain.text_splitter import MarkdownTextSplitter, RecursiveCharacterTextSplitter, TextSplitter
from langchain_text_splitters import MarkdownTextSplitter, RecursiveCharacterTextSplitter, TextSplitter


@lru_cache(maxsize=32)
Expand Down
2 changes: 1 addition & 1 deletion context_chat_backend/chain/ingest/injest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from time import perf_counter_ns

import niquests
from langchain.schema import Document
from langchain_core.documents import Document
from nc_py_api import AsyncNextcloudApp
from nc_py_api._exceptions import NextcloudException
from pydantic import ValidationError
Expand Down
2 changes: 1 addition & 1 deletion context_chat_backend/chain/one_shot.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
import logging

from langchain.llms.base import LLM
from langchain_core.language_models.llms import LLM

from ..dyn_loader import VectorDBLoader
from ..types import TConfig
Expand Down
4 changes: 2 additions & 2 deletions context_chat_backend/chain/query_proc.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import os
from sys import maxsize as SYS_MAXSIZE

from langchain.llms.base import LLM
from langchain.schema import Document
from langchain_core.documents import Document
from langchain_core.language_models.llms import LLM
from transformers import GPT2Tokenizer

from ..types import TConfig
Expand Down
2 changes: 1 addition & 1 deletion context_chat_backend/chain/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
from enum import Enum

from langchain.schema import Document
from langchain_core.documents import Document
from pydantic import BaseModel
from typing_extensions import TypedDict

Expand Down
2 changes: 1 addition & 1 deletion context_chat_backend/dyn_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from typing import Any

import torch
from langchain.llms.base import LLM
from langchain_core.language_models.llms import LLM

from .models.loader import init_model
from .network_em import NetworkEmbeddings
Expand Down
2 changes: 1 addition & 1 deletion context_chat_backend/models/hugging_face.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import logging
from os import getenv, path

from langchain_community.llms.huggingface_pipeline import HuggingFacePipeline
from langchain_huggingface import HuggingFacePipeline

logger = logging.getLogger('ccb.models')

Expand Down
4 changes: 2 additions & 2 deletions context_chat_backend/models/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
from collections.abc import Callable
from importlib import import_module

from langchain.llms.base import LLM
from langchain.schema.embeddings import Embeddings
from langchain_core.embeddings import Embeddings
from langchain_core.language_models.llms import LLM

_llm_models = ["nc_texttotext", "llama", "hugging_face", "ctransformer"]

Expand Down
2 changes: 1 addition & 1 deletion context_chat_backend/task_fetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from typing import Any

import niquests
from langchain.llms.base import LLM
from langchain_core.language_models.llms import LLM
from nc_py_api import NextcloudApp, NextcloudException
from niquests import JSONDecodeError, RequestException
from pydantic import ValidationError
Expand Down
7 changes: 3 additions & 4 deletions context_chat_backend/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,21 @@
from functools import partial, wraps
from multiprocessing.connection import Connection
from time import perf_counter_ns
from typing import Any, TypeGuard, TypeVar
from typing import Any, TypeGuard

from fastapi.responses import JSONResponse as FastAPIJSONResponse

from .types import AppRole, TConfig, TEmbeddingAuthApiKey, TEmbeddingAuthBasic, TEmbeddingConfig

T = TypeVar('T')
_logger = logging.getLogger('ccb.utils')
_MAX_STD_CAPTURE_CHARS = 64 * 1024


def not_none(value: T | None) -> TypeGuard[T]:
def not_none[T](value: T | None) -> TypeGuard[T]:
return value is not None


def value_of(value: T, default: T | None = None) -> T | None:
def value_of[T](value: T, default: T | None = None) -> T | None:
if value is None:
return default

Expand Down
6 changes: 3 additions & 3 deletions context_chat_backend/vectordb/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
from collections.abc import Mapping
from typing import Any

from langchain.schema import Document
from langchain.schema.embeddings import Embeddings
from langchain.schema.vectorstore import VectorStore
from langchain_core.documents import Document
from langchain_core.embeddings import Embeddings
from langchain_core.vectorstores import VectorStore

from ..chain.types import InDocument, ScopeType
from ..types import IndexingError, ReceivedFileItem, SourceItem
Expand Down
Loading
Loading