Skip to content

Feat/use uv instead of poetry #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/feat-request.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ assignees: callmesora

## Motivation

## Solutions
## Solutions
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/fix-request.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ assignees: callmesora

## Steps to Reproduce

## Additional Context
## Additional Context
2 changes: 1 addition & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@

# Impacts

# Notes
# Notes
4 changes: 2 additions & 2 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ description: Setup for project workflows
runs:
using: composite
steps:
- run: pipx install invoke poetry
- run: pipx install invoke uv
shell: bash
- uses: actions/setup-python@v5
with:
python-version: 3.12
cache: poetry
cache: uv
11 changes: 5 additions & 6 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup
- run: poetry install --with checks
- run: poetry run invoke checks.format
- run: poetry run invoke checks.code
- run: poetry run invoke checks.type
- run: poetry run invoke checks.security
- run: uv sync --group checks
- run: uv run invoke checks.format
- run: uv run invoke checks.code
- run: uv run invoke checks.type
- run: uv run invoke checks.security
# TODO: Add tests once figuring out how to mock mlflow and qdrant

8 changes: 4 additions & 4 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup
- run: poetry install --with docs
- run: poetry run invoke docs
- run: uv sync --group docs
- run: uv run invoke docs
- uses: JamesIves/github-pages-deploy-action@v4
with:
folder: docs/
Expand All @@ -28,8 +28,8 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup
- run: poetry install --with dev
- run: poetry run invoke packages
- run: uv sync --group dev
- run: uv run invoke packages
- uses: docker/login-action@v3
with:
registry: ghcr.io
Expand Down
9 changes: 5 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ repos:
- id: end-of-file-fixer
- id: mixed-line-ending
- id: trailing-whitespace
- repo: https://github.com/python-poetry/poetry
rev: 1.8.3
- repo: https://github.com/astral-sh/uv-pre-commit
# uv version.
rev: 0.5.8
hooks:
- id: poetry-check
- id: uv-lock
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.5.0
hooks:
Expand All @@ -30,4 +31,4 @@ repos:
hooks:
- id: commitizen
- id: commitizen-branch
stages: [push]
stages: [pre-push]
2 changes: 1 addition & 1 deletion CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,4 @@ enforcement ladder](https://github.com/mozilla/diversity).

For answers to common questions about this code of conduct, see the FAQ at
https://www.contributor-covenant.org/faq. Translations are available at
https://www.contributor-covenant.org/translations.
https://www.contributor-covenant.org/translations.
2 changes: 1 addition & 1 deletion LICENCE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
111 changes: 39 additions & 72 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,58 +23,30 @@ This package is a variation / fork of these resources but specicially tailored f

# Table of Contents

- [LLMOps Python Package](#mlops-python-package)
- [LLMOps Python Pacakge](#llmops-python-pacakge)
- [Table of Contents](#table-of-contents)
- [Architecture](#architecture)
- [RAG Evaluation](#rag-evaluation)
- [Model Registry](#model-registry)
- [Guardrails](#guardrails)
- [Endpoint Deployment](#endpoint-deployment)
- [Model Monitoring](#model-monitoring)
- [LLMOps Design Pattern](#llmops-design-pattern)
- [Install](#install)
- [Prerequisites](#prerequisites)
- [Credentials for LLM](#credentials-for-llm)
- [Installation](#installation)
- [Next Steps](#next-steps)
- [Usage](#usage)
- [Configuration](#configuration)
- [Execution](#execution)
- [Pipelines](#pipelines)
- [Generate Rag Dataset](#generate-rag-dataset)
- [Feature Engineering](#feature-engineering)
- [Deployment](#deployment)
- [Monitoring](#monitoring)
- [Automation](#automation)
- [Workflows](#workflows)
- [Tools](#tools)
- [Automation](#automation-1)
- [Commits: Commitizen](#commits-commitizen)
- [Git Hooks: Pre-Commit](#git-hooks-pre-commit)
- [Tasks: PyInvoke](#tasks-pyinvoke)
- [CI/CD](#cicd)
- [Runner: GitHub Actions](#runner-github-actions)
- [CLI](#cli)
- [Parser: Argparse](#parser-argparse)
- [Logging: Loguru](#logging-loguru)
- [Code](#code)
- [Coverage: Coverage](#coverage-coverage)
- [Editor: VS Code](#editor-vs-code)
- [Formatting: Ruff](#formatting-ruff)
- [Quality: Ruff](#quality-ruff)
- [Security: Bandit](#security-bandit)
- [Testing: Pytest](#testing-pytest)
- [Typing: Mypy](#typing-mypy)
- [Versioning: Git](#versioning-git)
- [Configs](#configs)
- [Format: YAML](#format-yaml)
- [Parser: OmegaConf](#parser-omegaconf)
- [Reader: Cloudpathlib](#reader-cloudpathlib)
- [Validator: Pydantic](#validator-pydantic)
- [Model](#model)
- [Format: Mlflow Model](#format-mlflow-model)
- [Registry: Mlflow Registry](#registry-mlflow-registry)
- [Tracking: Mlflow Tracking](#tracking-mlflow-tracking)
- [Package](#package)
- [Evolution: Changelog](#evolution-changelog)
- [Format: Wheel](#format-wheel)
- [Manager: Poetry](#manager-poetry)
- [Runtime: Docker](#runtime-docker)
- [Programming](#programming)
- [Language: Python](#language-python)
- [Version: Pyenv](#version-pyenv)
- [Observability](#observability)
- [Monitoring : Mlflow Evaluate](#monitoring--mlflow-evaluate)
- [Infrastructure: Mlflow System Metrics](#infrastructure-mlflow-system-metrics)
- [Model Serving](#endpoint)
- [Serving Endpoint: Litserve](#serving-endpoint)
- [Tips](#tips)
- [Design Patterns](#design-patterns)
- [Directed-Acyclic Graph](#directed-acyclic-graph)
Expand All @@ -96,6 +68,7 @@ This package is a variation / fork of these resources but specicially tailored f
- [VS Code](#vs-code)
- [Code Workspace](#code-workspace)
- [GitHub Copilot](#github-copilot)
- [VSCode VIM](#vscode-vim)
- [Resources](#resources)
- [Python](#python)
- [AI/ML/MLOps](#aimlmlops)
Expand Down Expand Up @@ -154,17 +127,16 @@ This section details the requirements, actions, and next steps to kickstart your

## Prerequisites

- [Python>=3.10](https://www.python.org/downloads/): to benefit from [the latest features and performance improvements](https://docs.python.org/3/whatsnew/3.12.html)
- [Poetry>=1.8.2](https://python-poetry.org/): to initialize the project [virtual environment](https://docs.python.org/3/library/venv.html) and its dependencies
- [UV>=0.5.11](https://docs.astral.sh/uv/): to initialize the project [virtual environment](https://docs.python.org/3/library/venv.html) and its dependencies

Use the package manager [Poetry](https://python-poetry.org/):
Use the package manager [UV](https://docs.astral.sh/uv/):

## Credentials for LLM

To access Bedrock, OpenAI, or any other LLM provider, you need to set up your credentials. These credentials will allow the package to authenticate and interact with the respective services.
In this code template we used Bedrock but feel free to change it to your needs.

Example for AWS
Example for AWS

**Environment Variables**:
```bash
Expand All @@ -174,7 +146,7 @@ Example for AWS
```


- You can easily replace `ChatBedrock` with `ChatOllama` or any other provider.
- You can easily replace `ChatBedrock` with `ChatOllama` or any other provider.


## Installation
Expand All @@ -186,10 +158,10 @@ $ git clone -
# with https
$ git clone -
```
2. [Run the project installation with poetry](https://python-poetry.org/docs/)
2. [Run the project installation with UV](https://docs.astral.sh/uv/)
```bash
$ cd llmops-python-package/
$ poetry install
$ uv sync --all-groups
```
3. Adapt the code base to your desire

Expand Down Expand Up @@ -225,17 +197,17 @@ job:
This config file instructs the program to start a `DeploymentJob` with respective parameters
You can find all the parameters of your program in the `src/[package]/pipelines/*.py` files.

You can also print the full schema supported by this package using `poetry run llmops --schema`.
You can also print the full schema supported by this package using `uv run llmops --schema`.

## Execution

The project code can be executed with poetry during your development, this is the order recommended:
The project code can be executed with UV during your development, this is the order recommended:

```bash
$ poetry run llmops-project confs/generate_rag_dataset.yaml # Run once to generate rag dataset
$ poetry run llmops-project confs/feature_eng.yaml # Creates Vector DB and Injests documents
$ poetry run llmops-project confs/deployment.yaml # Deploys model on model registry
$ poetry run llmops-project confs/monitoring.yaml # Monitors Model Inferences "every week"
$ uv run llmops-project confs/generate_rag_dataset.yaml # Run once to generate rag dataset
$ uv run llmops-project confs/feature_eng.yaml # Creates Vector DB and Injests documents
$ uv run llmops-project confs/deployment.yaml # Deploys model on model registry
$ uv run llmops-project confs/monitoring.yaml # Monitors Model Inferences "every week"
```

To deploy the serving endpoint you can use the following automation:
Expand All @@ -252,13 +224,13 @@ This project is organized under a manager pattern, each manager is responsible f
### Generate Rag Dataset
This pipeline generates a rag QA dataset under `/data/datasets/``

### Feature Engineering
### Feature Engineering
This pipeline creates a Vector Database instance collection and ingests documents onto it in the form of vectors.
![Vector Database](static/vector_db.png)

### Deployment
### Deployment
This pipeline:
- registers a model using Mlflow
- registers a model using Mlflow
- promote the model to `champion`alias
- validates model input /output and singatures
- sets tag "passed_tests" on mlflow registry to True/False depending if model passed tests
Expand All @@ -283,8 +255,8 @@ These metrics are also saved with a display in case you want to load it in a das
In production, you can build, ship, and run the project as a Python package:

```bash
poetry build
poetry publish # optional
uv build
uv publish # optional
python -m pip install [package]
[package] confs/deployment.yaml
```
Expand Down Expand Up @@ -326,7 +298,7 @@ $ inv --list
- **checks.code** - Check the codes with ruff.
- **checks.coverage** - Check the coverage with coverage.
- **checks.format** - Check the formats with ruff.
- **checks.poetry** - Check poetry config files.
- **checks.uv** - Check uv config files.
- **checks.security** - Check the security with bandit.
- **checks.test** - Check the tests with pytest.
- **checks.type** - Check the types with mypy.
Expand All @@ -340,7 +312,7 @@ $ inv --list
- **cleans.mlruns** - Clean the mlruns folder.
- **cleans.mypy** - Clean the mypy tool.
- **cleans.outputs** - Clean the outputs folder.
- **cleans.poetry** - Clean poetry lock file.
- **cleans.uv** - Clean uv lock file.
- **cleans.pytest** - Clean the pytest tool.
- **cleans.projects** - Run all projects tasks.
- **cleans.python** - Clean python caches and bytecodes.
Expand All @@ -365,7 +337,7 @@ $ inv --list
- **formats.imports** - Format python imports with ruff.
- **formats.sources** - Format python sources with ruff.
- **installs.all (installs)** - Run all install tasks.
- **installs.poetry** - Install poetry packages.
- **installs.uv** - Install uv packages.
- **installs.pre-commit** - Install pre-commit hooks on git.
- **mlflow.all (mlflow)** - Run all mlflow tasks.
- **mlflow.doctor** - Run mlflow doctor to diagnose issues.
Expand Down Expand Up @@ -467,10 +439,10 @@ Using Python package for your AI/ML project has the following benefits:
- Install Python package as a library (e.g., like pandas)
- Expose script entry points to run a CLI or a GUI

To build a Python package with Poetry, you simply have to type in a terminal:
To build a Python package with UV, you simply have to type in a terminal:
```bash
# for all poetry project
poetry build
# for all uv project
uv build
# for this project only
inv packages
```
Expand Down Expand Up @@ -524,7 +496,7 @@ Semantic Versioning (SemVer) provides a simple schema to communicate code change
- *Minor* (Y): minor release with new features (i.e., provide new capabilities)
- *Patch* (Z): patch release to fix bugs (i.e., correct wrong behavior)

Poetry and this package leverage Semantic Versioning to let developers control the speed of adoption for new releases.
UV and this package leverage Semantic Versioning to let developers control the speed of adoption for new releases.

## [Testing Tricks](https://en.wikipedia.org/wiki/Software_testing)

Expand Down Expand Up @@ -596,8 +568,3 @@ This section provides resources for building packages for Python and AI/ML/MLOps

- https://github.com/josephmisiti/awesome-machine-learning
- https://github.com/visenger/awesome-mlops





4 changes: 2 additions & 2 deletions confs/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ job:
registry_model_name: "rag-chatbot-with-guardrails"
llm_confs: "/confs/rag_chain_config.yaml"
llm_model_code_path: "/src/llmops_project/models/chatbot_with_guardrails.py"
vector_store_path: "https://34beb054-2278-47fe-9731-cd7ed574320f.eu-west-2-0.aws.cloud.qdrant.io:6333" #"http://localhost:6333"
vector_store_path: "http://localhost:6333"
qa_dataset_path: "/data/datasets/rag_dataset.csv"
alias: "champion"

metric_tresholds:
flesch_kincaid_grade_level_mean: 5.1 # bigger than
ari_grade_level_mean: 4.1 # bigger than
ari_grade_level_mean: 4.1 # bigger than
6 changes: 3 additions & 3 deletions confs/feature_eng.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
job:
KIND: FeatureEngineeringJob
embedding_model: "amazon.titan-embed-text-v1"
vector_store_path: "http://localhost:6333"
embedding_model: "amazon.titan-embed-text-v1"
vector_store_path: "http://localhost:6333"
document_path: "/data/documents/"
collection_name: "hr-documents"
collection_name: "hr-documents"
1 change: 0 additions & 1 deletion confs/generate_rag_dataset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ job:
qa_dataset_path_csv: "data/datasets/rag_dataset.csv" # will save a QA dataset in csv and json
qa_dataset_path_json: "data/datasets/rag_dataset.json" # will save a QA dataset in csv and json
llm_model: "anthropic.claude-3-haiku-20240307-v1:0" # model_id to generate the QA dataset

1 change: 0 additions & 1 deletion confs/monitoring.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ job:

trace_experiment_name: "rag_chatbot_experiment"
monitoring_experiment_name: "monitoring"

4 changes: 2 additions & 2 deletions confs/rag_chain_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ guardrail_config:
- leadership
- management
- productivity

invalid:
- software programming
- religion
Expand All @@ -29,7 +29,7 @@ output_example:
sources:
- "example_source_1.pdf"
- "example_source_2.pdf"

llm_config:
llm_model: anthropic.claude-3-haiku-20240307-v1:0
llm_parameters:
Expand Down
Loading