Skip to content

Commit

Permalink
☀ UV (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
hardbyte authored Sep 16, 2024
1 parent f95d421 commit a4dcb4c
Show file tree
Hide file tree
Showing 6 changed files with 498 additions and 747 deletions.
65 changes: 18 additions & 47 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,58 +20,29 @@ jobs:

steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
id: setup-python
with:
python-version: ${{ matrix.python }}
- name: Load cached Poetry installation
id: cached-poetry
uses: actions/cache@v3
with:
path: ~/.local # the path depends on the OS
key: poetry-1.8.3-1 # increment to reset cache

# The key configuration value here is `virtualenvs-in-project: true`: this creates the
# venv as a `.venv` in your testing directory, which allows the next step to easily
# cache it.
- name: Install Poetry
uses: snok/install-poetry@v1
#if: steps.cached-poetry.outputs.cache-hit != 'true'
with:
version: 1.8.3
virtualenvs-create: true
virtualenvs-in-project: true

- name: Load cached venv
id: cache-deps
uses: actions/cache@v3
- name: Install uv
id: setup-uv
uses: astral-sh/setup-uv@v2
with:
path: ~/.cache
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}

# Install dependencies. `--no-root` means "install all dependencies but not the project
# itself", which is what you want to avoid caching _your_ code. The `if` statement
# ensures this only runs on a cache miss.
- name: Install dependencies
run: |
poetry install --no-interaction --no-root
#if: steps.cache-deps.outputs.cache-hit != 'true'

# Now install _your_ project. This isn't necessary for many types of projects -- particularly
# things like Django apps don't need this. But it's a good idea since it fully-exercises the
# pyproject.toml and makes that if you add things like console-scripts at some point that
# they'll be installed and working.
- name: Install library
run: |
poetry install --no-interaction
version: "0.4.10"
enable-cache: true

# Run Tests.
#- run: |source $VENV
#poetry run pytest
- name: Install Python
id: setup-python
run: uv python install ${{ matrix.python }}

# Sync dependencies without dev dependencies
- name: Sync dependencies
run: uv sync --frozen --no-dev

# Install the project
- name: Install library
run: uv pip install --no-deps .

- name: Artifact creation
run: |
poetry build
run: uv build

- name: Save artifacts
uses: actions/upload-artifact@v4
with:
Expand Down
62 changes: 35 additions & 27 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,54 +13,62 @@ apt-get install -qyy \
ca-certificates
rm -rf /var/lib/apt/lists/*
EOT
# Install Poetry
ARG POETRY_VERSION=1.8.3
ENV POETRY_HOME=/opt/poetry
ENV VIRTUAL_ENV=/app/.venv
ENV POETRY_NO_INTERACTION=1
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
ENV POETRY_VIRTUALENVS_CREATE=false
ENV POETRY_VIRTUALENVS_IN_PROJECT=false

RUN pip install "poetry==${POETRY_VERSION}"
# Install UV
COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv

# Set environment variables
ENV UV_LINK_MODE=copy \
UV_COMPILE_BYTECODE=1 \
UV_PYTHON_DOWNLOADS=never \
UV_PYTHON=python3.12 \
UV_PROJECT_ENVIRONMENT=/app

# Set working directory
WORKDIR /app

# Copy pyproject.toml and poetry.lock to install dependencies
COPY pyproject.toml poetry.lock /app/
# Copy pyproject.toml and uv.lock to install dependencies
COPY pyproject.toml /_lock/
COPY uv.lock /_lock/

# Install dependencies without the application code
# Sync dependencies using UV, but don't install the project yet
RUN --mount=type=cache,target=/root/.cache \
python3 -m venv ${VIRTUAL_ENV} && \
poetry install --no-root
cd /_lock && \
uv sync --frozen --no-dev --no-install-project

# Copy the application code to install the app itself
# Copy the application code to the build stage
COPY . /app

# Install only the application (no dependencies)
# Install only the application (without dependencies)
RUN --mount=type=cache,target=/root/.cache \
poetry install --no-dev --no-interaction --no-ansi
uv pip install --no-deps /app

# Runtime Stage
FROM python:3.12

# Set environment variables for Python
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
ENV VIRTUAL_ENV=/app/.venv
ENV PATH="$VIRTUAL_ENV/bin:$PATH"

ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
VIRTUAL_ENV=/app/.venv \
PATH="/app/bin:$PATH"

# Set working directory
WORKDIR /app

# Copy only the necessary files from the build stage
# Copy the virtual environment and application code from the build stage
COPY --from=build /app/.venv /app/.venv
COPY --from=build /app /app
# Install runtime dependencies (no build tools or UV)
RUN <<EOT
apt-get update -qy
apt-get install -qyy \
-o APT::Install-Recommends=false \
-o APT::Install-Suggests=false \
python3.12 \
libpython3.12
apt-get clean
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
EOT

# Copy the virtual environment and application from the build stage
COPY --from=build /app /app

# Set the entrypoint to the qabot command line tool
ENTRYPOINT ["python", "-m", "qabot.cli"]
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Can query local and remote files (CSV, parquet)

## Installation

Install with [pipx](https://pypa.github.io/pipx/installation/):
Install with [pipx](https://pypa.github.io/pipx/installation/), `pip` etc:

```
pipx install qabot
Expand Down Expand Up @@ -214,14 +214,13 @@ Replace `your_openai_api_key` with your actual OpenAI API key.
## Ideas
- streaming mode to output results as they come in
- Streaming mode to output results as they come in
- token limits and better reporting of costs
- Supervisor agent - assess whether a query is "safe" to run, could ask for user confirmation to run anything that gets flagged.
- Often we can zero-shot the question and get a single query out - perhaps we try this before the MKL chain
- test each zeroshot agent individually
- Generate and pass back assumptions made to the user
- Add an optional "clarify" tool to the chain that asks the user to clarify the question
- Create a query checker tool that checks if the query looks valid and/or safe
- Inject AWS credentials into duckdb so we can access private resources in S3
- Automatic publishing to pypi. Look at https://blog.pypi.org/posts/2023-04-20-introducing-trusted-publishers/
- Inject AWS credentials into duckdb for access to private resources in S3
- Automatic publishing to pypi e.g. using [trusted publishers](https://blog.pypi.org/posts/2023-04-20-introducing-trusted-publishers/)
Loading

0 comments on commit a4dcb4c

Please sign in to comment.