Skip to content

Commit

Permalink
Initial commit (generated by Sicarator)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromeassouline committed Mar 28, 2024
0 parents commit fcdb830
Show file tree
Hide file tree
Showing 43 changed files with 5,554 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .dvc/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/config.local
/tmp
/cache
4 changes: 4 additions & 0 deletions .dvc/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[core]
remote = origin
['remote "origin"']
url = gs://llm-eval-annotator-dvc-remote
10 changes: 10 additions & 0 deletions .dvcignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Add patterns of files dvc should ignore, which could improve
# the performance. Learn more at
# https://dvc.org/doc/user-guide/dvcignore

# Python
*.pyc
__pycache__

# MacOS
.DS_Store
29 changes: 29 additions & 0 deletions .github/workflows/actions/install_dependencies/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: "Install Dependencies"
description: "Action to build the project dependencies from the main versions"
inputs:
python_version:
required: true
type: string
default: "3.11.6"
poetry_version:
required: true
type: string
default: "1.7.0"

runs:
using: composite
steps:
- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: ${{ inputs.poetry_version }}
virtualenvs-create: true
virtualenvs-in-project: false
installer-parallel: true
- uses: actions/setup-python@v4
with:
python-version: ${{ inputs.python_version }}
cache: "poetry"
- name: Install Dependencies
run: poetry install --no-root
shell: bash
66 changes: 66 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Tests

on:
push:
branches: [main]
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.head_ref || github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

jobs:
setup:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ./.github/workflows/actions/install_dependencies

checks:
needs: setup
runs-on: ubuntu-latest
name: ${{ matrix.quality-command }}
strategy:
matrix:
quality-command:
- format-check
- lint-check
- type-check
steps:
- uses: actions/checkout@v3
- uses: ./.github/workflows/actions/install_dependencies
- name: run ${{ matrix.quality-command }}
run: make ${{ matrix.quality-command }}

test:
needs: setup
runs-on: ubuntu-latest
name: test
steps:
- uses: actions/checkout@v3
- uses: ./.github/workflows/actions/install_dependencies
- name: run test
run: make test
# Run even if make test fails for coverage reports
# TODO: select a better xml results displayer
- name: Archive test results coverage results
uses: actions/upload-artifact@v3
if: always()
with:
name: test_results
path: tests-results.xml
- name: Archive code coverage results
uses: actions/upload-artifact@v3
if: always()
with:
name: code-coverage-report
path: htmlcov/

all_checks_passed:
# Used to easily force requirements checks in GitHub
needs:
- checks
- test
runs-on: ubuntu-latest
steps:
- run: echo "All checks passed"
19 changes: 19 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]

# unit tests / coverage reports
/tests-results.xml
/.coverage
/coverage.xml
/htmlcov/

# pyenv
/.python-version

# IDE
.idea/
.vscode/

# macOS
.DS_Store
53 changes: 53 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
default_install_hook_types:
# Mandatory to install both pre-commit and pre-push hooks (see https://pre-commit.com/#top_level-default_install_hook_types)
# Add new hook types here to ensure automatic installation when running `pre-commit install`
- pre-commit
- pre-push
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-json
- id: check-added-large-files

- repo: local
hooks:
- id: format-fix
name: Formatting (ruff)
entry: ruff format
language: system
types: [python]
stages: [commit]
- id: lint-check
name: Linting (ruff)
entry: ruff check
language: system
types: [python]
stages: [commit]
- id: type-check
name: Type checking (mypy)
entry: make type-check
pass_filenames: false
language: system
types: [python]
stages: [commit]
- id: test
name: Unit testing (pytest)
entry: make test
pass_filenames: false
language: system
types: [python]
stages: [push]
- id: dvc-pre-push
name: DVC pre-push
entry: dvc
args:
- git-hook
- pre-push
require_serial: true
verbose: true
language: system
stages: [push]
20 changes: 20 additions & 0 deletions .yo-rc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"generator-sicarator": {
"promptValues": {
"authorName": "Jerome",
"authorEmail": "jerome.assouline@sicara.com",
"ci": ".github",
"includeApi": true,
"apiInfrastructure": null,
"includeDvc": true,
"dvcRemoteType": "gs",
"includeStreamlit": true,
"includeDvcStreamlitUtils": true,
"includeDvcStreamlitExample": true
},
"projectName": "llm-eval-annotator",
"projectSlug": "llm-eval-annotator",
"projectDescription": "Project to test tools to evaluate and annotate LLM responses",
"dvcRemoteBucketName": "llm-eval-annotator-dvc-remote"
}
}
50 changes: 50 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Docker multi-stage building, as recommended by https://fastapi.tiangolo.com/deployment/docker/#docker-image-with-poetry
FROM python:3.11.6-slim-buster as curl-stage

# Install curl ; remove apt cache to reduce image size
RUN apt-get -y update && apt-get -y install curl && rm -rf /var/lib/apt/lists/*


FROM curl-stage as poetry-requirements-stage

WORKDIR /tmp

ENV HOME /root
ENV PATH=${PATH}:$HOME/.local/bin

# Install poetry
RUN curl -sSL https://install.python-poetry.org | POETRY_VERSION=1.7.0 python3 -

# Export requirements.txt
COPY ./pyproject.toml ./poetry.lock* /tmp/
RUN poetry export -f requirements.txt --output requirements.txt --without-hashes --no-interaction --no-cache --only=main


FROM curl-stage

WORKDIR /code

ENV \
# Prevent Python from buffering stdout and stderr and loosing some logs (equivalent to python -u option)
PYTHONUNBUFFERED=1 \
# Prevent Pip from timing out when installing heavy dependencies
PIP_DEFAULT_TIMEOUT=600 \
# Prevent Pip from creating a cache directory to reduce image size
PIP_NO_CACHE_DIR=1

# Install dependencies with pip from exported requirements.txt
COPY --from=poetry-requirements-stage /tmp/requirements.txt /code/requirements.txt
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt

# Copy API files
COPY src/api ./src/api

# Add and set a non-root user
RUN useradd appuser
USER appuser

# Start FastAPI
CMD uvicorn src.api.main:app --host 0.0.0.0 --port 80

# Healthcheck
HEALTHCHECK --interval=10s --timeout=1s --retries=3 CMD curl --fail http://localhost/health || exit 1
45 changes: 45 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
########################################################################################################################
# Project installation
########################################################################################################################

install:
pyenv virtualenv --force 3.11.6 llm-eval-annotator
pyenv local llm-eval-annotator
# Running poetry install inside a Make command requires a VIRTUAL_ENV variable
VIRTUAL_ENV=$$(pyenv prefix) poetry install --no-root --sync

########################################################################################################################
# Quality checks
########################################################################################################################

test:
poetry run pytest tests --cov src --cov-report term --cov-report=html --cov-report xml --junit-xml=tests-results.xml

format-check:
poetry run ruff format --check src tests

format-fix:
poetry run ruff format src tests

lint-check:
poetry run ruff check src tests

lint-fix:
poetry run ruff check src tests --fix

type-check:
poetry run mypy src

########################################################################################################################
# Api
########################################################################################################################

start-api:
docker compose up -d

########################################################################################################################
# Streamlit
########################################################################################################################

start-streamlit-app:
poetry run streamlit run "src/streamlit_app/🏠_Home_page.py"
Loading

0 comments on commit fcdb830

Please sign in to comment.