Skip to content

Commit

Permalink
Switch to UV from PDM (#40)
Browse files Browse the repository at this point in the history
* switch to uv from pdm

* uv pip install

* fix path for uv install

* run venv

* default .venv

* update readme and gha

* remove pdm from gha

* update gha script for py version and install

* init venv

* modify cache glob

* use uv natively, not in pip compatibility mode

* fix up the docker file to run with uv sync

* update the README for uv usage

---------

Co-authored-by: jwatson <[email protected]>
  • Loading branch information
ewilliams-cloudera and jkwatson authored Nov 22, 2024
1 parent 990008f commit ebbdf89
Show file tree
Hide file tree
Showing 10 changed files with 2,001 additions and 2,285 deletions.
5 changes: 4 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@ DB_URL=jdbc:h2:../databases/rag
# If using CAII, fill these in:
CAII_DOMAIN=
CAII_INFERENCE_ENDPOINT_NAME=
CAII_EMBEDDING_ENDPOINT_NAME=
CAII_EMBEDDING_ENDPOINT_NAME=

# set this to true if you have uv installed on your system, other wise don't include this
USE_SYSTEM_UV=true
26 changes: 10 additions & 16 deletions .github/workflows/llm_checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,37 +14,31 @@ jobs:
with:
ref: ${{ github.event.inputs.BRANCH }}

- name: Set up Python
uses: pdm-project/setup-pdm@v3
- name: Install uv
uses: astral-sh/setup-uv@v3
with:
python-version: '3.10'
cache: false

- name: Cache pdm cache folder
uses: actions/cache@v4
id: python_cache
with:
path: ./llm-service/.venv
key: pdm-venv-${{ hashFiles('./llm-service/pdm.lock') }}
enable-cache: true
cache-dependency-glob: "./llm-service/uv.lock"

- name: Install Python dependencies
if: steps.python_cache.outputs.cache-hit != 'true'
run: |
pdm install
uv python install 3.10
uv venv --python 3.10
uv sync
working-directory: llm-service

- name: Run ruff
run: |
pdm run ruff check app
uv run ruff check app
working-directory: llm-service

- name: Run mypy
run: |
pdm run mypy app
uv run mypy app
working-directory: llm-service

- name: Test with pytest
run: |
pdm run pytest -sxvvra
uv run pytest -sxvvra
working-directory: llm-service

11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,13 @@ the Node service locally, you can do so by following these steps:

#### Python Setup

- Install Python (via [pyenv](https://github.com/pyenv/pyenv), probably) (directly via brew, if you must)
- Install Python 3.10 (via [pyenv](https://github.com/pyenv/pyenv), probably) (directly via brew, if you must)
- `cd llm-service`
- Create a virtual environment (`python -m venv venv; source venv/bin/activate`)
- Install dependencies (`python -m pip install -r requirements.txt`)
- `fastapi dev`
- ends up running on port 8000
- Install `uv`.
- We recommend installing via `brew install uv`, but you can also install it directly in your python environment if you prefer.
- `uv sync` - this creates a `uv` virtual environment in `.venv` and installs the dependencies
- `uv fastapi dev`
- the python-based service ends up running on port 8000

#### Java Setup

Expand Down
14 changes: 9 additions & 5 deletions llm-service/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
FROM docker-private.infra.cloudera.com/cloudera_base/hardened/cloudera-python:3.10
RUN pip install pdm
RUN pip install uv
COPY ./pyproject.toml /app/
COPY ./pdm.lock /app/
COPY ./uv.lock /app/
WORKDIR /app
RUN pdm install
RUN uv sync

COPY ./app /app
WORKDIR /app
COPY ./scripts /scripts
ENV PATH="/app/.venv/bin:$PATH"

# Reset the entrypoint, don't invoke `uv`
ENTRYPOINT []

CMD [ "pdm", "run", "fastapi", "run", "--host", "0.0.0.0" ]
CMD [ "fastapi", "run", "--host", "0.0.0.0" ]
2,247 changes: 0 additions & 2,247 deletions llm-service/pdm.lock

This file was deleted.

4 changes: 2 additions & 2 deletions llm-service/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[project]
name = "llm-service"
version = "0.1.0"
description = "Default template for PDM package"
description = "Default template for UV package"
authors = [
{name = "Conrado Silva Miranda", email = "[email protected]"},
]
Expand All @@ -11,7 +11,7 @@ dependencies = [
"fastapi==0.111.0",
"pydantic==2.8.2",
"pydantic-settings==2.3.4",
"boto3>=1.35.66",
"boto3>=1.35.68",
"llama-index-embeddings-bedrock==0.2.1",
"llama-index-llms-bedrock==0.1.13",
"llama-index-llms-openai==0.1.31",
Expand Down
1,958 changes: 1,958 additions & 0 deletions llm-service/uv.lock

Large diffs are not rendered by default.

14 changes: 8 additions & 6 deletions local-dev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,15 @@ mkdir -p databases
docker run --name qdrant_dev --rm -d -p 6333:6333 -p 6334:6334 -v $(pwd)/databases/qdrant_storage:/qdrant/storage:z qdrant/qdrant

cd llm-service
python3.10 -m venv venv
source venv/bin/activate
python -m pip install pdm
pdm install
pdm run pytest -sxvvra
if [ -z "$USE_SYSTEM_UV" ]; then
python3.10 -m venv venv
source venv/bin/activate
python -m pip install uv
fi
uv sync
uv run pytest -sxvvra

pdm run fastapi dev &
uv run fastapi dev &

# start up the jarva
cd ../backend
Expand Down
5 changes: 3 additions & 2 deletions scripts/refresh_project.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ cd ui/express
npm install

cd ../../llm-service
pip install pdm
pdm install -v
pip install uv

uv sync

cd ..
mkdir -p artifacts
Expand Down
2 changes: 1 addition & 1 deletion scripts/startup_app.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ qdrant/qdrant &

# start Python backend
cd llm-service
pdm run fastapi run --host 127.0.0.1 --port 8081 &
uv run fastapi run --host 127.0.0.1 --port 8081 &

# start up the jarva
cd ..
Expand Down

0 comments on commit ebbdf89

Please sign in to comment.