Skip to content

Setup LLM regression framework for simple univariate models #1

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

Merged
merged 5 commits into from
May 15, 2024
Merged
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
30 changes: 30 additions & 0 deletions .github/workflows/python-package-cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Deploy Python package

on:
release:
types: [published]

jobs:
build-and-deploy:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.12"]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install Nox
run: |
python -m pip install --upgrade pip
python -m pip install --upgrade setuptools
python -m pip install "nox==2023.4.22"
- name: Build wheel and push to PyPI
env:
PYPI_USR: ${{ secrets.PYPI_USR }}
PYPI_PWD: ${{ secrets.PYPI_PWD }}
run: |
nox -s build_and_deploy
33 changes: 33 additions & 0 deletions .github/workflows/python-package-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Python package

on:
pull_request:
branches: [ "main" ]

jobs:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.12"]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install Nox
run: |
python -m pip install --upgrade pip
python -m pip install --upgrade setuptools
python -m pip install "nox==2023.4.22"
- name: Run code formatting checks
run: |
nox -s check_code_formatting-${{ matrix.python-version }}
- name: Run static type checking
run: |
nox -s check_types-${{ matrix.python-version }}
- name: Run tests
run: |
nox -s run_tests-${{ matrix.python-version }}
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Misc
TODO.md
.vscode/

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down Expand Up @@ -49,6 +53,7 @@ coverage.xml
*.py,cover
.hypothesis/
.pytest_cache/
.ruff_cache
cover/

# Translations
Expand Down
82 changes: 80 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,80 @@
# llm-regression
Exploring the classical regression capabilities of LLMs.
# llm_regression

This is the repository for the llm_regression Python package.

## Developer Setup

Install the package as an [editable dependency](https://setuptools.pypa.io/en/latest/userguide/development_mode.html), together with all the developer tools required to format code, check types and run tests:

```text
$ pip install -e ".[dev]"
```

### Developer Task Execution with Nox

We use [Nox](https://nox.thea.codes/en/stable/) for scripting developer tasks, such as formatting code, checking types and running tests. These tasks are defined in `noxfile.py`, a list of which can be returned on the command line,

```text
$ nox --list

Sessions defined in /Users/.../noxfile.py:

* run_tests-3.10 -> Run unit tests.
- format_code-3.10 -> Lint code and re-format where necessary.
* check_code_formatting-3.10 -> Check code for formatting errors.
* check_types-3.10 -> Run static type checking.
- build_and_deploy-3.10 -> Build wheel and deploy to PyPI.

sessions marked with * are selected, sessions marked with - are skipped.
```

Single tasks can be executed easily - e.g.,

```text
$ nox -s run_tests

nox > Running session run_tests-3.10
nox > Creating virtual environment (virtualenv) using python3.10 in .nox/run_tests-3-10
nox > python -m pip install '.[dev]'
nox > pytest
======================================== test session starts ========================================
platform darwin -- Python 3.10.2, pytest-7.4.2, pluggy-1.3.0
rootdir: /Users/.../llm_regression
configfile: pyproject.toml
testpaths: tests
collected 1 item

tests/test_hello_world.py . [100%]

========================================== 1 passed in 0.00s =========================================
nox > Session run_tests-3.10 was successful.
```

### Building Packages and Deploying to PyPI

This is automated via the `nox -s build_and_deploy` command. In order to use this, the following environment variables will need to be made available to Python:

```text
PYPI_USR # PyPI username
PYPI_PWD # PyPI password
```

These may be specified in a `.env` file from which they will be loaded automatically - e.g.,

```text
PYPI_USR=XXXX
PYPI_PWD=XXXX
```

Note: `.gitignore` will ensure that `.env`is not tracked by Git.

## CI/CD

This repo comes configured to run two [GitHub Actions](https://docs.github.com/en/actions) workflows:

- **Test Python Package (CI)**, defined in `.github/workflows/python-package-ci.yml`
- **Deploy Python Package (CD)**, defined in `.github/workflows/python-package-cd.yml`

The CI workflow has been configured to run whenever a pull request to the `main` branch is created. The CD workflow has been configured to run whenever a [release](https://docs.github.com/en/repositories/releasing-projects-on-github/managing-releases-in-a-repository) is created on GitHub.

Note, the CD workflow will require `PYPI_USR` and `PYPI_PWD` to be added as [repository secrets](https://docs.github.com/en/actions/security-guides/using-secrets-in-github-actions).
64 changes: 64 additions & 0 deletions noxfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
"""Developer task automation."""
import os

import nox

nox.options.sessions = [
"check_code_formatting",
"check_types",
"run_tests",
]

PYTHON = ["3.12"]


@nox.session(python=PYTHON, reuse_venv=True)
def run_tests(session: nox.Session):
"""Run unit tests."""
session.install(".[dev]")
pytest_args = session.posargs if session.posargs else []
session.run("pytest", *pytest_args)


@nox.session(python=PYTHON, reuse_venv=True)
def format_code(session: nox.Session):
"""Lint code and re-format where necessary."""
session.install(".[dev]")
session.run("black", "--config=pyproject.toml", ".")
session.run("ruff", "check", ".", "--config=pyproject.toml", "--fix")


@nox.session(python=PYTHON, reuse_venv=True)
def check_code_formatting(session: nox.Session):
"""Check code for formatting errors."""
session.install(".[dev]")
session.run("black", "--config=pyproject.toml", "--check", ".")
session.run("ruff", "check", ".", "--config=pyproject.toml")


@nox.session(python=PYTHON, reuse_venv=True)
def check_types(session: nox.Session):
"""Run static type checking."""
session.install(".[dev]")
session.run("mypy")


@nox.session(python=PYTHON, reuse_venv=True)
def build_and_deploy(session: nox.Session):
"""Build wheel and deploy to PyPI."""
try:
from dotenv import load_dotenv

load_dotenv()
except ModuleNotFoundError:
session.warn("Expecting PYPI_USR and PYPI_PWD in local environment variables.")

try:
PYPI_USR = os.environ["PYPI_USR"]
PYPI_PWD = os.environ["PYPI_PWD"]
except KeyError as e:
session.error(f"{str(e)} not found in local environment variables.")
session.install(".[deploy]")
session.run("rm", "-rf", "dist")
session.run("python", "-m", "build")
session.run("twine", "upload", "dist/*", "-u", PYPI_USR, "-p", PYPI_PWD)
94 changes: 94 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
[project]
name = "llm_regression"
version = "0.1.0.dev0"
description = "The llm_regression Python package."
readme = "README.md"
authors = [
{ name="Alex Ioannides", email="[email protected]" },
]
dependencies = [
"openai==1.30.*",
"numpy==1.26.*",
"pandas==2.2.*",
"python-dotenv==1.0.*",
"scikit-learn==1.4.*",
"tqdm==4.66.*",
]

[project.optional-dependencies]
dev = [
"black==23.9.1",
"python-dotenv>=1.0.0",
"icecream",
"ipython",
"mypy==1.5.1",
"nox==2023.4.22",
"pandas-stubs==2.2.2.240514",
"pytest==7.4.2",
"ruff==0.0.290",
"types-pytz==2024.1.0.20240417",
"types-tqdm==4.66.0.20240417",
]
deploy = [
"build>=1.0.0",
"pip>=23.2.0",
"setuptools>=68.0.0",
"twine>=4.0.0",
"wheel>=0.41.0",
]

[project.urls]
"Homepage" = "https://github.com/AlexIoannides/llm-regression"
"Bug Tracker" = "https://github.com/AlexIoannides/llm-regression/issues"

[build-system]
requires = ["setuptools>=68.0"]
build-backend = "setuptools.build_meta"

[tool.setuptools]
include-package-data = true

[tool.setuptools.packages.find]
where = ["src"]

[tool.black]
line-length = 88

[tool.ruff]
src = ["src"]
target-version = "py310"
line-length = 88
select = [
"D", # pydocstyle
"E", # pycodestyle errors
"F", # pyflakes
"I", # isort
"UP", # pyupgrade
"W", # pycodestyle warnings
]
ignore = [
"D203", # fix pydocstyle warning
"D213", # fix pydocstyle warning
]

[tool.ruff.per-file-ignores]
"tests/*" = [
"D103",
]

[tool.pytest.ini_options]
testpaths = ["tests"]

[tool.mypy]
python_version = "3.12"
files = [
"src",
"tests",
"noxfile.py",
]

[[tool.mypy.overrides]]
module = [
"sklearn.*",
]
ignore_missing_imports = true
1 change: 1 addition & 0 deletions src/llm_regression/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""The llm_regression package."""
Loading
Loading