diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml new file mode 100644 index 000000000..2bbd52c53 --- /dev/null +++ b/.github/workflows/pre-commit.yml @@ -0,0 +1,45 @@ +name: Pre-commit + +on: + pull_request: + push: + branches: [main] + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + pre-commit: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + + - name: Set up Python + uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0 + with: + python-version: '3.11' + cache: pip + cache-dependency-path: | + **/requirements*.txt + .pre-commit-config.yaml + + - uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd # v3.0.1 + env: + SKIP: no-commit-to-branch + RUFF_OUTPUT_FORMAT: github + + - name: Verify if there are any diff files after pre-commit + run: | + git diff --exit-code || (echo "There are uncommitted changes, run pre-commit locally and commit again" && exit 1) + + - name: Verify if there are any new files after pre-commit + run: | + unstaged_files=$(git ls-files --others --exclude-standard) + if [ -n "$unstaged_files" ]; then + echo "There are uncommitted new files, run pre-commit locally and commit again" + echo "$unstaged_files" + exit 1 + fi diff --git a/.github/workflows/redhat-distro-container-build.yml b/.github/workflows/redhat-distro-container-build.yml index 002e940eb..a207319b4 100644 --- a/.github/workflows/redhat-distro-container-build.yml +++ b/.github/workflows/redhat-distro-container-build.yml @@ -50,7 +50,7 @@ jobs: uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0 with: context: . - file: redhat-distribution/Containerfile + file: distribution/Containerfile platforms: ${{ matrix.platform }} push: ${{ github.event_name == 'push' }} tags: ${{ env.IMAGE_NAME }}:${{ github.sha }},${{ env.IMAGE_NAME }}:${{ env.BRANCH }}-latest diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 000000000..4e59f91ec --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,49 @@ +exclude: 'build/' + +default_language_version: + python: python3.12 + +repos: +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v5.0.0 # Latest stable version + hooks: + - id: check-merge-conflict + args: ['--assume-in-merge'] + - id: trailing-whitespace + exclude: '\.py$' # Exclude Python files as Ruff already handles them + - id: check-added-large-files + args: ['--maxkb=1000'] + - id: end-of-file-fixer + exclude: '^(.*\.svg)$' + - id: no-commit-to-branch + - id: check-yaml + args: ["--unsafe"] + - id: detect-private-key + - id: requirements-txt-fixer + - id: mixed-line-ending + args: [--fix=lf] # Forces to replace line ending by LF (line feed) + - id: check-executables-have-shebangs + - id: check-json + - id: check-shebang-scripts-are-executable + - id: check-symlinks + - id: check-toml + +- repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.9.4 + hooks: + - id: ruff + args: [ --fix ] + - id: ruff-format + +- repo: local + hooks: + - id: pkg-gen + name: Distribution Build + entry: ./distribution/build.py + language: python + pass_filenames: false + require_serial: true + always_run: true + files: ^distribution/.*$ + additional_dependencies: + - llama-stack==0.2.18 diff --git a/redhat-distribution/Containerfile b/distribution/Containerfile similarity index 76% rename from redhat-distribution/Containerfile rename to distribution/Containerfile index e2cde2c36..3aa47fbc1 100644 --- a/redhat-distribution/Containerfile +++ b/distribution/Containerfile @@ -1,5 +1,5 @@ # WARNING: This file is auto-generated. Do not modify it manually. -# Generated by: redhat-distribution/build.py +# Generated by: distribution/build.py FROM registry.access.redhat.com/ubi9/python-312@sha256:95ec8d3ee9f875da011639213fd254256c29bc58861ac0b11f290a291fa04435 WORKDIR /opt/app-root @@ -17,7 +17,7 @@ RUN pip install \ llama_stack_provider_lmeval==0.1.7 \ llama_stack_provider_trustyai_fms==0.1.2 \ matplotlib \ - mcp \ + mcp>=1.8.1 \ nltk \ numpy \ openai \ @@ -40,9 +40,9 @@ RUN pip install \ uvicorn RUN pip install --index-url https://download.pytorch.org/whl/cpu torch torchvision RUN pip install --no-deps sentence-transformers -RUN pip install --no-cache llama-stack==0.2.14 +RUN pip install --no-cache llama-stack==0.2.18 RUN mkdir -p ${HOME}/.llama/providers.d ${HOME}/.cache -COPY redhat-distribution/run.yaml ${APP_ROOT}/run.yaml -COPY redhat-distribution/providers.d/ ${HOME}/.llama/providers.d/ +COPY distribution/run.yaml ${APP_ROOT}/run.yaml +COPY distribution/providers.d/ ${HOME}/.llama/providers.d/ -ENTRYPOINT ["python", "-m", "llama_stack.distribution.server.server", "--config", "/opt/app-root/run.yaml"] +ENTRYPOINT ["python", "-m", "llama_stack.core.server.server", "/opt/app-root/run.yaml"] diff --git a/redhat-distribution/Containerfile.in b/distribution/Containerfile.in similarity index 51% rename from redhat-distribution/Containerfile.in rename to distribution/Containerfile.in index d3305c032..139dbf259 100644 --- a/redhat-distribution/Containerfile.in +++ b/distribution/Containerfile.in @@ -3,9 +3,9 @@ WORKDIR /opt/app-root RUN pip install sqlalchemy # somehow sqlalchemy[asyncio] is not sufficient {dependencies} -RUN pip install --no-cache llama-stack==0.2.14 +RUN pip install --no-cache llama-stack==0.2.18 RUN mkdir -p ${{HOME}}/.llama/providers.d ${{HOME}}/.cache -COPY redhat-distribution/run.yaml ${{APP_ROOT}}/run.yaml -COPY redhat-distribution/providers.d/ ${{HOME}}/.llama/providers.d/ +COPY distribution/run.yaml ${{APP_ROOT}}/run.yaml +COPY distribution/providers.d/ ${{HOME}}/.llama/providers.d/ -ENTRYPOINT ["python", "-m", "llama_stack.distribution.server.server", "--config", "/opt/app-root/run.yaml"] +ENTRYPOINT ["python", "-m", "llama_stack.core.server.server", "/opt/app-root/run.yaml"] diff --git a/redhat-distribution/README.md b/distribution/README.md similarity index 85% rename from redhat-distribution/README.md rename to distribution/README.md index 742c01673..3498e6a5d 100644 --- a/redhat-distribution/README.md +++ b/distribution/README.md @@ -15,7 +15,7 @@ The Containerfile is auto-generated from a template. To generate it: 1. Make sure you have the `llama` CLI tool installed 2. Run the build script from root of this git repo: ```bash - ./redhat-distribution/build.py + ./distribution/build.py ``` This will: @@ -25,7 +25,7 @@ This will: ## Editing the Containerfile -The Containerfile is auto-generated from a template. To edit it, you can modify the template in `redhat-distribution/Containerfile.in` and run the build script again. +The Containerfile is auto-generated from a template. To edit it, you can modify the template in `distribution/Containerfile.in` and run the build script again. NEVER edit the generated `Containerfile` manually. ## Building the Container Image @@ -34,7 +34,7 @@ Once the Containerfile is generated, you can build the image using either Podman ### Using Podman build image for x86_64 ```bash -podman build --platform linux/amd64 -f redhat-distribution/Containerfile -t rh . +podman build --platform linux/amd64 -f distribution/Containerfile -t rh . ``` ## Notes diff --git a/redhat-distribution/build.py b/distribution/build.py similarity index 86% rename from redhat-distribution/build.py rename to distribution/build.py index 85675b5ea..362fd6f3c 100755 --- a/redhat-distribution/build.py +++ b/distribution/build.py @@ -5,7 +5,7 @@ # This source code is licensed under the terms described in the LICENSE file in # the root directory of this source tree. -# Usage: ./redhat-distribution/build.py +# Usage: ./distribution/build.py import shutil import subprocess @@ -13,7 +13,7 @@ from pathlib import Path BASE_REQUIREMENTS = [ - "llama-stack==0.2.14", + "llama-stack==0.2.18", ] @@ -59,9 +59,11 @@ def check_llama_stack_version(): def get_dependencies(): """Execute the llama stack build command and capture dependencies.""" - cmd = "llama stack build --config redhat-distribution/build.yaml --print-deps-only" + cmd = "llama stack build --config distribution/build.yaml --print-deps-only" try: - result = subprocess.run(cmd, shell=True, capture_output=True, text=True, check=True) + result = subprocess.run( + cmd, shell=True, capture_output=True, text=True, check=True + ) # Categorize and sort different types of pip install commands standard_deps = [] torch_deps = [] @@ -74,7 +76,9 @@ def get_dependencies(): parts = line.replace("uv ", "RUN ", 1).split(" ", 3) if len(parts) >= 4: # We have packages to sort cmd_parts = parts[:3] # "RUN pip install" - packages = sorted(set(parts[3].split())) # Sort the package names and remove duplicates + packages = sorted( + set(parts[3].split()) + ) # Sort the package names and remove duplicates # Determine command type and format accordingly if "--index-url" in line: @@ -104,13 +108,14 @@ def get_dependencies(): except subprocess.CalledProcessError as e: print(f"Error executing command: {e}") print(f"Command output: {e.output}") + print(f"Command stderr: {e.stderr}") sys.exit(1) def generate_containerfile(dependencies): """Generate Containerfile from template with dependencies.""" - template_path = Path("redhat-distribution/Containerfile.in") - output_path = Path("redhat-distribution/Containerfile") + template_path = Path("distribution/Containerfile.in") + output_path = Path("distribution/Containerfile") if not template_path.exists(): print(f"Error: Template file {template_path} not found") @@ -121,10 +126,12 @@ def generate_containerfile(dependencies): template_content = f.read() # Add warning message at the top - warning = "# WARNING: This file is auto-generated. Do not modify it manually.\n# Generated by: redhat-distribution/build.py\n\n" + warning = "# WARNING: This file is auto-generated. Do not modify it manually.\n# Generated by: distribution/build.py\n\n" # Process template using string formatting - containerfile_content = warning + template_content.format(dependencies=dependencies.rstrip()) + containerfile_content = warning + template_content.format( + dependencies=dependencies.rstrip() + ) # Write output with open(output_path, "w") as f: diff --git a/distribution/build.yaml b/distribution/build.yaml new file mode 100644 index 000000000..fc465882a --- /dev/null +++ b/distribution/build.yaml @@ -0,0 +1,36 @@ +version: 2 +distribution_spec: + description: Red Hat distribution of Llama Stack + providers: + inference: + - provider_type: remote::vllm + - provider_type: inline::sentence-transformers + vector_io: + - provider_type: inline::milvus + safety: + - provider_type: remote::trustyai_fms + agents: + - provider_type: inline::meta-reference + eval: + - provider_type: remote::trustyai_lmeval + datasetio: + - provider_type: remote::huggingface + - provider_type: inline::localfs + scoring: + - provider_type: inline::basic + - provider_type: inline::llm-as-judge + - provider_type: inline::braintrust + telemetry: + - provider_type: inline::meta-reference + tool_runtime: + - provider_type: remote::brave-search + - provider_type: remote::tavily-search + - provider_type: inline::rag-runtime + - provider_type: remote::model-context-protocol + container_image: registry.redhat.io/ubi9/python-311:9.6-1749631027 +additional_pip_packages: +- aiosqlite +- sqlalchemy[asyncio] +image_type: container +image_name: llama-stack-rh +external_providers_dir: distribution/providers.d diff --git a/redhat-distribution/providers.d/remote/eval/trustyai_lmeval.yaml b/distribution/providers.d/remote/eval/trustyai_lmeval.yaml similarity index 100% rename from redhat-distribution/providers.d/remote/eval/trustyai_lmeval.yaml rename to distribution/providers.d/remote/eval/trustyai_lmeval.yaml diff --git a/redhat-distribution/providers.d/remote/safety/trustyai_fms.yaml b/distribution/providers.d/remote/safety/trustyai_fms.yaml similarity index 100% rename from redhat-distribution/providers.d/remote/safety/trustyai_fms.yaml rename to distribution/providers.d/remote/safety/trustyai_fms.yaml diff --git a/redhat-distribution/run.yaml b/distribution/run.yaml similarity index 100% rename from redhat-distribution/run.yaml rename to distribution/run.yaml diff --git a/redhat-distribution/build.yaml b/redhat-distribution/build.yaml deleted file mode 100644 index 663fb002f..000000000 --- a/redhat-distribution/build.yaml +++ /dev/null @@ -1,36 +0,0 @@ -version: '2' -distribution_spec: - description: Red Hat distribution of Llama Stack - providers: - inference: - - remote::vllm - - inline::sentence-transformers - vector_io: - - inline::milvus - safety: - - remote::trustyai_fms - agents: - - inline::meta-reference - eval: - - remote::trustyai_lmeval - datasetio: - - remote::huggingface - - inline::localfs - scoring: - - inline::basic - - inline::llm-as-judge - - inline::braintrust - telemetry: - - inline::meta-reference - tool_runtime: - - remote::brave-search - - remote::tavily-search - - inline::rag-runtime - - remote::model-context-protocol - container_image: registry.redhat.io/ubi9/python-311:9.6-1749631027 -additional_pip_packages: -- aiosqlite -- sqlalchemy[asyncio] -image_type: container -image_name: llama-stack-rh -external_providers_dir: redhat-distribution/providers.d