From 5a3a819150ade42c09b6df852ccb9a2146e29c97 Mon Sep 17 00:00:00 2001 From: Marcel Klehr Date: Fri, 5 Jul 2024 21:15:03 +0200 Subject: [PATCH] fix: Use poetry and build on container start Signed-off-by: Marcel Klehr --- .github/workflows/appstore-build-publish.yml | 5 -- Dockerfile | 31 ++++-------- healthcheck.sh | 3 ++ init.sh | 7 +++ lib/chains.py | 2 +- pyproject.toml | 53 +++++++------------- requirements.txt | 8 --- 7 files changed, 40 insertions(+), 69 deletions(-) create mode 100755 healthcheck.sh create mode 100755 init.sh delete mode 100644 requirements.txt diff --git a/.github/workflows/appstore-build-publish.yml b/.github/workflows/appstore-build-publish.yml index 3089e4d..83c30f6 100644 --- a/.github/workflows/appstore-build-publish.yml +++ b/.github/workflows/appstore-build-publish.yml @@ -92,11 +92,6 @@ jobs: cd ${{ env.APP_NAME }} npm ci npm run build - - - name: Download files - run: | - cd ${{ env.APP_NAME }} - make download-models - name: Check Krankerl config id: krankerl diff --git a/Dockerfile b/Dockerfile index 3ad170e..649535b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,18 +1,11 @@ -FROM nvidia/cuda:12.4.1-runtime-ubuntu22.04 +FROM nvidia/cuda:12.2.2-runtime-ubuntu22.04 ENV DEBIAN_FRONTEND=noninteractive -RUN apt-get update -RUN apt-get install -y software-properties-common -RUN add-apt-repository -y ppa:deadsnakes/ppa -RUN apt-get update -RUN apt-get install -y --no-install-recommends python3.11 python3.11-venv python3-pip vim git pciutils -RUN update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.11 1 -RUN apt-get -y clean -RUN rm -rf /var/lib/apt/lists/* +RUN apt update +RUN apt install -y pipx build-essential +RUN pipx install poetry -ENV NVIDIA_VISIBLE_DEVICES all -ENV NVIDIA_DRIVER_CAPABILITIES compute ENV DEBIAN_FRONTEND=dialog ADD li[b] /app/lib @@ -20,15 +13,13 @@ ADD model[s] /app/models ADD default_confi[g] /app/default_config # Install requirements -COPY requirements.txt / -RUN python3.11 -m pip install --no-cache-dir --upgrade pip setuptools wheel -RUN python3.11 -m pip install llama-cpp-python --extra-index-url https://abetlen.github.io/llama-cpp-python/whl/cu124 -# RUN python3 -m pip install -vvv --no-cache-dir https://github.com/abetlen/llama-cpp-python/releases/download/v0.2.81-cu124/llama_cpp_python-0.2.81-cp311-cp311-linux_x86_64.whl -# https://github.com/abetlen/llama-cpp-python/releases/download/v0.2.81-cu122/llama_cpp_python-0.2.81-cp311-cp311-linux_x86_64.whl -RUN sed -i '/llama_cpp_python/d' requirements.txt -RUN python3.11 -m pip install --no-cache-dir --no-deps -r requirements.txt +COPY pyproject.toml /app +COPY poetry.lock /app +COPY init.sh /app +COPY healthcheck.sh /app -WORKDIR /app/lib -ENTRYPOINT ["python3", "main.py"] +WORKDIR /app +ENTRYPOINT ["bash", "init.sh"] LABEL org.opencontainers.image.source=https://github.com/nextcloud/llm2 +HEALTHCHECK --interval=2s --timeout=2s --retries=300 CMD /app/healthcheck.sh \ No newline at end of file diff --git a/healthcheck.sh b/healthcheck.sh new file mode 100755 index 0000000..4ab209d --- /dev/null +++ b/healthcheck.sh @@ -0,0 +1,3 @@ +#! /bin/bash + +exit 0 \ No newline at end of file diff --git a/init.sh b/init.sh new file mode 100755 index 0000000..656c172 --- /dev/null +++ b/init.sh @@ -0,0 +1,7 @@ +#! /bin/bash +PATH="/root/.local/bin/:$PATH" +CMAKE_ARGS="-DLLAMA_CUDA=on" +source $(poetry env info --path)/bin/activate +poetry install +cd lib +poetry run python3 main.py \ No newline at end of file diff --git a/lib/chains.py b/lib/chains.py index 423e6af..8c93250 100644 --- a/lib/chains.py +++ b/lib/chains.py @@ -5,7 +5,7 @@ from free_prompt import FreePromptChain from headline import HeadlineChain -from langchain.llms.llamacpp import LlamaCpp +from langchain_community.llms import LlamaCpp from langchain.chains import LLMChain from summarize import SummarizeChain from topics import TopicsChain diff --git a/pyproject.toml b/pyproject.toml index 7e1f410..5717c6f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,38 +1,21 @@ -[tool.black] -line-length = 120 -target-versions = ["py310"] -preview = true +[tool.poetry] +name = "llm2" +version = "1.2.4" +description = "" +authors = ["Marcel Klehr "] +license = "AGPL-3.0" +readme = "README.md" +package-mode = false -[tool.ruff] -line-length = 120 -target-version = "py310" -select = ["A", "B", "C", "D", "E", "F", "G", "I", "S", "SIM", "PIE", "Q", "RET", "RUF", "UP" , "W"] -extend-ignore = ["D101", "D102", "D103", "D105", "D107", "D203", "D213", "D401", "I001", "RUF100", "D400", "D415"] +[tool.poetry.dependencies] +python = "^3.10" +pydantic = "^2.8.2" +fastapi = "^0.111.0" +nc-py-api = {extras = ["app"], version = "^0.13.0"} +langchain = "^0.1.0" +llama-cpp-python = "0.2.76" -[tool.isort] -profile = "black" -[tool.pylint] -master.py-version = "3.10" -master.extension-pkg-allow-list = ["pydantic"] -design.max-attributes = 8 -design.max-locals = 16 -design.max-branches = 16 -design.max-returns = 8 -design.max-args = 7 -basic.good-names = [ - "a", "b", "c", "d", "e", "f", "i", "j", "k", "r", "v", - "ex", "_", "fp", "im", "nc", "ui", -] -reports.output-format = "colorized" -similarities.ignore-imports = "yes" -similarities.min-similarity-lines = 6 -messages_control.disable = [ - "missing-class-docstring", - "missing-function-docstring", - "line-too-long", - "too-few-public-methods", - "too-many-public-methods", - "global-statement", - "broad-exception-caught", -] +[build-system] +requires = ["poetry-core"] +build-backend = "poetry.core.masonry.api" \ No newline at end of file diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index cefd2e6..0000000 --- a/requirements.txt +++ /dev/null @@ -1,8 +0,0 @@ -nc_py_api[app]>=0.11.0 -transformers>=4.36.1 -accelerate -huggingface_hub -pydantic -langchain==0.1.12 -langchain-community -llama-cpp-python