diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml new file mode 100644 index 0000000..eaa09eb --- /dev/null +++ b/.github/workflows/main.yaml @@ -0,0 +1,138 @@ +name: main + +on: + push: + branches: [main] + pull_request: + branches: [main] + +jobs: + check-branch: + if: ${{ github.event_name == 'pull_request' }} + runs-on: ubuntu-latest + timeout-minutes: 10 + concurrency: + group: check-pr-${{ github.ref }} + cancel-in-progress: true + + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Check if the PR's branch is updated + uses: osl-incubator/gh-check-pr-is-updated@1.0.0 + with: + remote_branch: origin/main + pr_sha: ${{ github.event.pull_request.head.sha }} + + tests: + needs: check-branch + timeout-minutes: 10 + strategy: + matrix: + python_version: + - "3.8.1" + - "3.9" + - "3.10" + - "3.11" + - "3.12" + os: + - "ubuntu" + - "macos" + # - "windows" + runs-on: ${{ matrix.os }}-latest + concurrency: + group: ci-tests-${{ matrix.os }}-${{ matrix.python_version }}-${{ github.ref }} + cancel-in-progress: true + + defaults: + run: + shell: bash -l {0} + + steps: + - uses: actions/checkout@v3 + + - name: Install MacOS extra tools and add extra setup + if: ${{ matrix.os == 'macos' }} + run: | + sudo mkdir -p /tmp + sudo chmod 777 /tmp + + brew install gnu-sed + echo 'export PATH="/usr/local/opt/gnu-sed/libexec/gnubin:$PATH"' >> ~/.bashrc + echo 'export PATH="/usr/local/opt/gnu-sed/libexec/gnubin:$PATH"' >> ~/.bash_profile + + - name: Prepare conda environment (windows) + if: ${{ matrix.os == 'windows' }} + run: | + $env:Path += ";C:\Program Files\Git\usr\bin" + sed -i s/python\ 3\.8\.1/python\ ${{ matrix.python_version }}/ conda/dev.yaml + cat conda/dev.yaml + + - name: Prepare conda environment + if: ${{ matrix.os != 'windows' }} + run: | + sed -i s/python\ 3\.8\.1/python\ ${{ matrix.python_version }}/ conda/dev.yaml + cat conda/dev.yaml + + - uses: conda-incubator/setup-miniconda@v3 + with: + miniconda-version: "latest" + environment-file: conda/dev.yaml + channels: conda-forge,nodefaults + activate-environment: anamnesisai + auto-update-conda: true + conda-solver: libmamba + + - name: Install dependencies + run: poetry install + + - name: Run unit tests + run: makim tests.unittest + + - name: Test jupyter notebooks + run: makim tests.notebooks + + linter-and-docs: + needs: check-branch + runs-on: ubuntu-latest + timeout-minutes: 10 + + defaults: + run: + shell: bash -l {0} + + concurrency: + group: ci-linter-docs-${{ matrix.os }}-${{ matrix.python_version }}-${{ github.ref }} + cancel-in-progress: true + + steps: + - uses: actions/checkout@v3 + + - uses: conda-incubator/setup-miniconda@v3 + with: + miniconda-version: "latest" + environment-file: conda/dev.yaml + channels: conda-forge,nodefaults + activate-environment: anamnesisai + auto-update-conda: true + conda-solver: libmamba + + - name: Install dependencies + run: | + poetry config virtualenvs.create false + poetry install + + - name: Test documentation generation + run: makim docs.build + + - name: Run style checks + if: success() || failure() + run: | + pre-commit install + makim tests.linter + + - name: Setup tmate session + if: "${{ failure() && (contains(github.event.pull_request.labels.*.name, 'ci:enable-debugging')) }}" + uses: mxschmitt/action-tmate@v3 diff --git a/.makim.yaml b/.makim.yaml new file mode 100644 index 0000000..69ee960 --- /dev/null +++ b/.makim.yaml @@ -0,0 +1,86 @@ +version: 1.0 +groups: + clean: + targets: + tmp: + help: remove build artifacts, compiled files, and cache + shell: bash + run: | + find . -name '*.egg-info' -exec rm -rf {} + + find . -name '*.egg' -exec rm -f {} + + find . -name '*.pyc' -exec rm -f {} + + find . -name '*.pyo' -exec rm -f {} + + find . -name '__pycache__' -exec rm -rf {} + + find . -name '*~' -exec rm -f {} + + rm -rf build/ + rm -rf dist/ + rm -rf .eggs/ + rm -f .coverage + rm -rf htmlcov/ + rm -rf .pytest_cache + + tests: + targets: + linter: + help: run linter tools + run: | + pre-commit install + pre-commit run --all-files + + unittest: + help: run tests + args: + path: + help: Specify the location of the tests + type: string + default: "" + params: + help: Specify parameters to be used for tests + type: string + default: "-vv" + run: pytest {{ args.path }} {{ args.params }} + + notebooks: + help: test jupyter notebooks + run: pytest -vv --nbmake docs/tutorials + + ci: + help: run the sames tests executed on CI + dependencies: + - target: tests.unittest + - target: tests.notebooks + - target: tests.linter + + docs: + targets: + build: + help: build documentation + run: mkdocs build --config-file mkdocs.yaml + + preview: + help: preview documentation page locally + run: mkdocs serve --watch docs --config-file mkdocs.yaml + + release: + vars: + app: | + npx --yes \ + -p semantic-release \ + -p conventional-changelog-conventionalcommits \ + -p "@semantic-release/commit-analyzer" \ + -p "@semantic-release/release-notes-generator" \ + -p "@semantic-release/changelog" \ + -p "@semantic-release/exec" \ + -p "@semantic-release/github" \ + -p "@semantic-release/git" \ + -p "semantic-release-replace-plugin" \ + semantic-release + + targets: + ci: + help: run semantic release on CI + run: {{ vars.app }} --ci + + dry: + help: run semantic release in dry-run mode + run: {{ vars.app }} --dry-run diff --git a/src/anamnesisai/anamnesisai.py b/src/anamnesisai/anamnesisai.py index 0d2b2b7..0d6bdd2 100644 --- a/src/anamnesisai/anamnesisai.py +++ b/src/anamnesisai/anamnesisai.py @@ -1,4 +1,5 @@ + from langchain import OpenAI from langchain.utilities import SQLDatabase from langchain_experimental.sql import SQLDatabaseChain