Skip to content

Commit 3fe6a90

Browse files
AlexIoannidesalexioannides
and
alexioannides
authored
Setup LLM regression framework for simple univariate models (#1)
* Initial commit * Demo fully operational * Prediction operational * Prototype code up-and-running * Modify noxfile Python config --------- Co-authored-by: alexioannides <[email protected]>
1 parent 343fe6a commit 3fe6a90

File tree

10 files changed

+460
-2
lines changed

10 files changed

+460
-2
lines changed
+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Deploy Python package
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
jobs:
8+
build-and-deploy:
9+
runs-on: ubuntu-latest
10+
strategy:
11+
fail-fast: false
12+
matrix:
13+
python-version: ["3.12"]
14+
steps:
15+
- uses: actions/checkout@v3
16+
- name: Set up Python ${{ matrix.python-version }}
17+
uses: actions/setup-python@v3
18+
with:
19+
python-version: ${{ matrix.python-version }}
20+
- name: Install Nox
21+
run: |
22+
python -m pip install --upgrade pip
23+
python -m pip install --upgrade setuptools
24+
python -m pip install "nox==2023.4.22"
25+
- name: Build wheel and push to PyPI
26+
env:
27+
PYPI_USR: ${{ secrets.PYPI_USR }}
28+
PYPI_PWD: ${{ secrets.PYPI_PWD }}
29+
run: |
30+
nox -s build_and_deploy
+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Python package
2+
3+
on:
4+
pull_request:
5+
branches: [ "main" ]
6+
7+
jobs:
8+
test:
9+
runs-on: ubuntu-latest
10+
strategy:
11+
fail-fast: false
12+
matrix:
13+
python-version: ["3.12"]
14+
steps:
15+
- uses: actions/checkout@v3
16+
- name: Set up Python ${{ matrix.python-version }}
17+
uses: actions/setup-python@v3
18+
with:
19+
python-version: ${{ matrix.python-version }}
20+
- name: Install Nox
21+
run: |
22+
python -m pip install --upgrade pip
23+
python -m pip install --upgrade setuptools
24+
python -m pip install "nox==2023.4.22"
25+
- name: Run code formatting checks
26+
run: |
27+
nox -s check_code_formatting-${{ matrix.python-version }}
28+
- name: Run static type checking
29+
run: |
30+
nox -s check_types-${{ matrix.python-version }}
31+
- name: Run tests
32+
run: |
33+
nox -s run_tests-${{ matrix.python-version }}

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Misc
2+
TODO.md
3+
.vscode/
4+
15
# Byte-compiled / optimized / DLL files
26
__pycache__/
37
*.py[cod]
@@ -49,6 +53,7 @@ coverage.xml
4953
*.py,cover
5054
.hypothesis/
5155
.pytest_cache/
56+
.ruff_cache
5257
cover/
5358

5459
# Translations

README.md

+80-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,80 @@
1-
# llm-regression
2-
Exploring the classical regression capabilities of LLMs.
1+
# llm_regression
2+
3+
This is the repository for the llm_regression Python package.
4+
5+
## Developer Setup
6+
7+
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:
8+
9+
```text
10+
$ pip install -e ".[dev]"
11+
```
12+
13+
### Developer Task Execution with Nox
14+
15+
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,
16+
17+
```text
18+
$ nox --list
19+
20+
Sessions defined in /Users/.../noxfile.py:
21+
22+
* run_tests-3.10 -> Run unit tests.
23+
- format_code-3.10 -> Lint code and re-format where necessary.
24+
* check_code_formatting-3.10 -> Check code for formatting errors.
25+
* check_types-3.10 -> Run static type checking.
26+
- build_and_deploy-3.10 -> Build wheel and deploy to PyPI.
27+
28+
sessions marked with * are selected, sessions marked with - are skipped.
29+
```
30+
31+
Single tasks can be executed easily - e.g.,
32+
33+
```text
34+
$ nox -s run_tests
35+
36+
nox > Running session run_tests-3.10
37+
nox > Creating virtual environment (virtualenv) using python3.10 in .nox/run_tests-3-10
38+
nox > python -m pip install '.[dev]'
39+
nox > pytest
40+
======================================== test session starts ========================================
41+
platform darwin -- Python 3.10.2, pytest-7.4.2, pluggy-1.3.0
42+
rootdir: /Users/.../llm_regression
43+
configfile: pyproject.toml
44+
testpaths: tests
45+
collected 1 item
46+
47+
tests/test_hello_world.py . [100%]
48+
49+
========================================== 1 passed in 0.00s =========================================
50+
nox > Session run_tests-3.10 was successful.
51+
```
52+
53+
### Building Packages and Deploying to PyPI
54+
55+
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:
56+
57+
```text
58+
PYPI_USR # PyPI username
59+
PYPI_PWD # PyPI password
60+
```
61+
62+
These may be specified in a `.env` file from which they will be loaded automatically - e.g.,
63+
64+
```text
65+
PYPI_USR=XXXX
66+
PYPI_PWD=XXXX
67+
```
68+
69+
Note: `.gitignore` will ensure that `.env`is not tracked by Git.
70+
71+
## CI/CD
72+
73+
This repo comes configured to run two [GitHub Actions](https://docs.github.com/en/actions) workflows:
74+
75+
- **Test Python Package (CI)**, defined in `.github/workflows/python-package-ci.yml`
76+
- **Deploy Python Package (CD)**, defined in `.github/workflows/python-package-cd.yml`
77+
78+
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.
79+
80+
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).

noxfile.py

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
"""Developer task automation."""
2+
import os
3+
4+
import nox
5+
6+
nox.options.sessions = [
7+
"check_code_formatting",
8+
"check_types",
9+
"run_tests",
10+
]
11+
12+
PYTHON = ["3.12"]
13+
14+
15+
@nox.session(python=PYTHON, reuse_venv=True)
16+
def run_tests(session: nox.Session):
17+
"""Run unit tests."""
18+
session.install(".[dev]")
19+
pytest_args = session.posargs if session.posargs else []
20+
session.run("pytest", *pytest_args)
21+
22+
23+
@nox.session(python=PYTHON, reuse_venv=True)
24+
def format_code(session: nox.Session):
25+
"""Lint code and re-format where necessary."""
26+
session.install(".[dev]")
27+
session.run("black", "--config=pyproject.toml", ".")
28+
session.run("ruff", "check", ".", "--config=pyproject.toml", "--fix")
29+
30+
31+
@nox.session(python=PYTHON, reuse_venv=True)
32+
def check_code_formatting(session: nox.Session):
33+
"""Check code for formatting errors."""
34+
session.install(".[dev]")
35+
session.run("black", "--config=pyproject.toml", "--check", ".")
36+
session.run("ruff", "check", ".", "--config=pyproject.toml")
37+
38+
39+
@nox.session(python=PYTHON, reuse_venv=True)
40+
def check_types(session: nox.Session):
41+
"""Run static type checking."""
42+
session.install(".[dev]")
43+
session.run("mypy")
44+
45+
46+
@nox.session(python=PYTHON, reuse_venv=True)
47+
def build_and_deploy(session: nox.Session):
48+
"""Build wheel and deploy to PyPI."""
49+
try:
50+
from dotenv import load_dotenv
51+
52+
load_dotenv()
53+
except ModuleNotFoundError:
54+
session.warn("Expecting PYPI_USR and PYPI_PWD in local environment variables.")
55+
56+
try:
57+
PYPI_USR = os.environ["PYPI_USR"]
58+
PYPI_PWD = os.environ["PYPI_PWD"]
59+
except KeyError as e:
60+
session.error(f"{str(e)} not found in local environment variables.")
61+
session.install(".[deploy]")
62+
session.run("rm", "-rf", "dist")
63+
session.run("python", "-m", "build")
64+
session.run("twine", "upload", "dist/*", "-u", PYPI_USR, "-p", PYPI_PWD)

pyproject.toml

+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
[project]
2+
name = "llm_regression"
3+
version = "0.1.0.dev0"
4+
description = "The llm_regression Python package."
5+
readme = "README.md"
6+
authors = [
7+
{ name="Alex Ioannides", email="[email protected]" },
8+
]
9+
dependencies = [
10+
"openai==1.30.*",
11+
"numpy==1.26.*",
12+
"pandas==2.2.*",
13+
"python-dotenv==1.0.*",
14+
"scikit-learn==1.4.*",
15+
"tqdm==4.66.*",
16+
]
17+
18+
[project.optional-dependencies]
19+
dev = [
20+
"black==23.9.1",
21+
"python-dotenv>=1.0.0",
22+
"icecream",
23+
"ipython",
24+
"mypy==1.5.1",
25+
"nox==2023.4.22",
26+
"pandas-stubs==2.2.2.240514",
27+
"pytest==7.4.2",
28+
"ruff==0.0.290",
29+
"types-pytz==2024.1.0.20240417",
30+
"types-tqdm==4.66.0.20240417",
31+
]
32+
deploy = [
33+
"build>=1.0.0",
34+
"pip>=23.2.0",
35+
"setuptools>=68.0.0",
36+
"twine>=4.0.0",
37+
"wheel>=0.41.0",
38+
]
39+
40+
[project.urls]
41+
"Homepage" = "https://github.com/AlexIoannides/llm-regression"
42+
"Bug Tracker" = "https://github.com/AlexIoannides/llm-regression/issues"
43+
44+
[build-system]
45+
requires = ["setuptools>=68.0"]
46+
build-backend = "setuptools.build_meta"
47+
48+
[tool.setuptools]
49+
include-package-data = true
50+
51+
[tool.setuptools.packages.find]
52+
where = ["src"]
53+
54+
[tool.black]
55+
line-length = 88
56+
57+
[tool.ruff]
58+
src = ["src"]
59+
target-version = "py310"
60+
line-length = 88
61+
select = [
62+
"D", # pydocstyle
63+
"E", # pycodestyle errors
64+
"F", # pyflakes
65+
"I", # isort
66+
"UP", # pyupgrade
67+
"W", # pycodestyle warnings
68+
]
69+
ignore = [
70+
"D203", # fix pydocstyle warning
71+
"D213", # fix pydocstyle warning
72+
]
73+
74+
[tool.ruff.per-file-ignores]
75+
"tests/*" = [
76+
"D103",
77+
]
78+
79+
[tool.pytest.ini_options]
80+
testpaths = ["tests"]
81+
82+
[tool.mypy]
83+
python_version = "3.12"
84+
files = [
85+
"src",
86+
"tests",
87+
"noxfile.py",
88+
]
89+
90+
[[tool.mypy.overrides]]
91+
module = [
92+
"sklearn.*",
93+
]
94+
ignore_missing_imports = true

src/llm_regression/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""The llm_regression package."""

0 commit comments

Comments
 (0)