prototype: use pyproject and uv to build distribution

Goals:

* remove the need of a custom tool to install a collection of python
  packages AKA `llama stack build`
* use the power of 'uv', which was designed to manage dependencies
* `llama stack build` can "probably" go away and be replaced with uv

Howto, with the pyproject, you can install an Ollama distribution in a
virtual env like so:

```
uv venv --python 3.10 ollama-distro
source ollama-distro/bin/activate
uv sync --extra ollama
llama stack run llama_stack/templates/ollama/run.yaml
```

Caveats:

* external provider, we could still use a build file or add
the known external providers to the pyproject?
* growth of the uv.lock?

We create a requirements.txt for convenience as some users are most
familiar with this format than looking at pyproject.

Signed-off-by: Sébastien Han <seb@redhat.com>
This commit is contained in:
Sébastien Han 2025-05-27 20:31:57 +02:00
parent 6832e8a658
commit b6ebbe1bc0
No known key found for this signature in database
13 changed files with 5579 additions and 679 deletions

View file

@ -5,6 +5,10 @@ inputs:
description: The Python version to use
required: false
default: "3.11"
install-ollama:
description: Install ollama
required: false
default: true
runs:
using: "composite"
steps:
@ -17,11 +21,13 @@ runs:
- name: Install dependencies
shell: bash
env:
INSTALL_OLLAMA: ${{ inputs.install-ollama }}
if: ${{ env.INSTALL_OLLAMA == 'true' }}
run: |
uv sync --all-groups
uv pip install ollama faiss-cpu
uv sync --all-groups --extra ollama
# always test against the latest version of the client
# TODO: this is not necessarily a good idea. we need to test against both published and latest
# to find out backwards compatibility issues.
uv pip install git+https://github.com/meta-llama/llama-stack-client-python.git@main
uv pip install -e .

View file

@ -33,9 +33,6 @@ jobs:
- name: Install dependencies
uses: ./.github/actions/setup-runner
- name: Build Llama Stack
run: |
llama stack build --template ollama --image-type venv
- name: Install minikube
if: ${{ matrix.auth-provider == 'kubernetes' }}

View file

@ -41,16 +41,12 @@ jobs:
- name: Setup ollama
uses: ./.github/actions/setup-ollama
- name: Build Llama Stack
run: |
uv run llama stack build --template ollama --image-type venv
- name: Start Llama Stack server in background
if: matrix.client-type == 'http'
env:
INFERENCE_MODEL: "meta-llama/Llama-3.2-3B-Instruct"
run: |
LLAMA_STACK_LOG_FILE=server.log nohup uv run llama stack run ./llama_stack/templates/ollama/run.yaml --image-type venv --env OLLAMA_URL="http://0.0.0.0:11434" &
LLAMA_STACK_LOG_FILE=server.log nohup uv run llama stack run ./llama_stack/templates/ollama/run.yaml --env OLLAMA_URL="http://0.0.0.0:11434" &
- name: Wait for Llama Stack server to be ready
if: matrix.client-type == 'http'

View file

@ -36,7 +36,7 @@ jobs:
- name: Generate Template List
id: set-matrix
run: |
templates=$(ls llama_stack/templates/*/*build.yaml | awk -F'/' '{print $(NF-1)}' | jq -R -s -c 'split("\n")[:-1]')
templates=$(ls llama_stack/templates/*/*build.yaml | grep -v "experimental-post-training" | awk -F'/' '{print $(NF-1)}' | jq -R -s -c 'split("\n")[:-1]')
echo "templates=$templates" >> "$GITHUB_OUTPUT"
build:
@ -54,16 +54,42 @@ jobs:
- name: Install dependencies
uses: ./.github/actions/setup-runner
with:
install-ollama: false
- name: Print build dependencies
- name: Print dependencies in the image
if: matrix.image-type == 'venv'
run: |
uv run llama stack build --template ${{ matrix.template }} --image-type ${{ matrix.image-type }} --image-name test --print-deps-only
uv pip list
- name: Run Llama Stack Build
- name: Run Llama Stack Build - VENV
if: matrix.image-type == 'venv'
run: |
# USE_COPY_NOT_MOUNT is set to true since mounting is not supported by docker buildx, we use COPY instead
# LLAMA_STACK_DIR is set to the current directory so we are building from the source
USE_COPY_NOT_MOUNT=true LLAMA_STACK_DIR=. uv run llama stack build --template ${{ matrix.template }} --image-type ${{ matrix.image-type }} --image-name test
uv sync --no-default-groups --extra ${{ matrix.template }}
# TODO
- name: Run Llama Stack Build - CONTAINER
if: matrix.image-type == 'container'
run: |
# TODO: use llama_stack/templates/Containerfile when we have a new release!
cat << 'EOF' > Containerfile
FROM registry.access.redhat.com/ubi9
WORKDIR /app
ARG TEMPLATE
RUN dnf -y update \
&& dnf install -y python3.11 python3.11-pip python3.11-wheel python3.11-setuptools python3.11-devel gcc make \
&& ln -s /bin/pip3.11 /bin/pip \
&& ln -s /bin/python3.11 /bin/python \
&& dnf clean all
RUN mkdir -p /.llama/providers.d /.cache
COPY . /app/llama-stack
RUN cd llama-stack && pip install --no-cache .[${TEMPLATE}]
RUN chmod -R g+rw /app /.llama /.cache
ENTRYPOINT ["python", "-m", "llama_stack.distribution.server.server", "--config", "/app/llama-stack/templates/${TEMPLATE}/run.yaml"]
EOF
docker build --build-arg TEMPLATE=${{ matrix.template }} -f Containerfile -t ${{ matrix.template }} .
- name: Print dependencies in the image
if: matrix.image-type == 'venv'

View file

@ -43,7 +43,7 @@ jobs:
- name: Build HTML
run: |
cd docs
uv run make html
uv run --group docs make html
- name: Trigger ReadTheDocs build
if: github.event_name != 'pull_request'