Skip to content

Commit

Permalink
Merge branch 'main' into staging/deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
BeatrixCohere authored Aug 16, 2024
2 parents 0711cc9 + 98dc8ce commit f016e26
Show file tree
Hide file tree
Showing 145 changed files with 1,407 additions and 845 deletions.
43 changes: 29 additions & 14 deletions .github/workflows/backend_unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,48 @@ name: Backend unit tests
on:
push:
branches: [main]
pull_request:
paths-ignore:
- src/interfaces/**
pull_request: {}
merge_group: {}

jobs:
pytest:
permissions: write-all
# environment: development
runs-on: ubuntu-latest
env:
COHERE_API_KEY: fake-test-key
DATABASE_URL: ${{ secrets.DATABASE_URL }}
NEXT_PUBLIC_API_HOSTNAME: ${{ secrets.NEXT_PUBLIC_API_HOSTNAME }}

steps:
- name: Checkout repo
uses: actions/checkout@v3
- name: Setup Docker
run: docker compose up test_db -d
- name: Run unit tests
- uses: actions/setup-python@v5
with:
python-version: '3.11'
cache: 'pip'
- name: Install poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
virtualenvs-path: .venv
installer-parallel: true
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v4
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --with dev --no-interaction --no-root
- name: Setup test DB container
run: make test-db
- name: Test with pytest
if: github.actor != 'dependabot[bot]'
run: |
mkdir -p coverage
docker compose build --build-arg INSTALL_COMMUNITY_DEPS=true backend
docker compose run --name backend-container -v $(pwd)/coverage:/app/coverage backend poetry run pytest --cov=src/backend --cov-report=xml:/app/coverage/coverage.xml src/backend/tests/unit
make run-unit-tests
env:
PYTHONPATH: src
- name: Upload coverage reports to Codecov
uses: codecov/[email protected]
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: coverage/coverage.xml
file: coverage.xml
27 changes: 7 additions & 20 deletions .github/workflows/python-lint.yml
Original file line number Diff line number Diff line change
@@ -1,30 +1,17 @@
name: Format
name: Python Lint

on:
push:
branches: [main]
pull_request: {}

jobs:
format:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: psf/[email protected]
- uses: isort/isort-action@v1
- uses: actions/checkout@v4
- name: Run lint checks
uses: chartboost/ruff-action@v1
with:
isort-version: "5.12.0"
- uses: actions/setup-python@v4
with:
python-version: 3.11
- name: Upgrade pip
run: |
pip install --upgrade --user pip
- name: Install code quality packages
run: |
pip install poetry
poetry env use 3.11
poetry install --only=dev
- name: Remove unused standard library imports from non-`__init__.py` files
run:
poetry run autoflake --in-place --recursive --ignore-init-module-imports .
src: './src/'
version: 0.6.0
24 changes: 18 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ down:

.PHONY: run-unit-tests
run-unit-tests:
docker compose run --build backend poetry run pytest src/backend/tests/unit/$(file)
poetry run pytest src/backend/tests/unit --cov=src/backend --cov-report=xml

.PHONY: run-community-tests
run-community-tests:
Expand Down Expand Up @@ -59,9 +59,13 @@ reset-db:
docker compose down
docker volume rm cohere_toolkit_db

.PHONY: install
install:
poetry install --verbose --with dev

.PHONY: setup
setup:
poetry install --with setup --verbose
poetry install --with setup,dev --verbose
poetry run python3 src/backend/cli/main.py

.PHONY: setup-use-community
Expand All @@ -76,9 +80,11 @@ win-setup:

.PHONY: lint
lint:
poetry run autoflake --in-place --recursive --ignore-init-module-imports .
poetry run black .
poetry run isort .
poetry run ruff check

.PHONY: lint-fix
lint-fix:
poetry run ruff check --fix

.PHONY: first-run
first-run:
Expand Down Expand Up @@ -108,6 +114,12 @@ install-web:
build-web:
cd src/interfaces/coral_web && npm run build

.PHONY: test-db
test-db:
docker compose stop test_db
docker compose rm -f test_db
docker compose up test_db -d

.PHONY: dev-sync
dev-sync:
@docker compose up --build sync_worker sync_publisher flower -d
@docker compose up --build sync_worker sync_publisher flower -d
20 changes: 20 additions & 0 deletions docs/postman/Toolkit.postman_collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,26 @@
}
]
},
{
"name": "Tool Auth",
"item": [
{
"name": "Delete Tool Auth",
"request": {
"auth": {
"type": "bearer",
"bearer": {
"token": "{{auth_token}}"
}
},
"method": "DELETE",
"header": [],
"url": "http://localhost:8000/v1/tool/auth/{{tool_id}}"
},
"response": []
}
]
},
{
"name": "Health",
"protocolProfileBehavior": {
Expand Down
25 changes: 18 additions & 7 deletions docs/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,11 +252,16 @@ If you also need to install the community features, run:
poetry install --with community
```

To run linters, you can use `make lint` or separate commands:
The codebase is formatted and linted using [Ruff](https://docs.astral.sh/ruff/).

```bash
poetry run black .
poetry run isort .
To check for linter and formatter errors, run
```
make lint
```

To apply automatic fixes, run
```
make lint-fix
```

Run type checker:
Expand Down Expand Up @@ -296,13 +301,19 @@ This will delete the existing `db` container volumes, restart the containers and

### Testing the Toolkit

Run:
Install the Python dependencies:

```bash
make dev
make install
```

Spin up the Test DB required by the tests:

```bash
make test-db
```

To spin the `test_db` service for you. After, you can run:
Run the tests:

```bash
make run-tests
Expand Down
6 changes: 3 additions & 3 deletions helper_scripts/metrics_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ def agents():
def users():
print("running users")
# # List Users
res = requests.get(f"{base_url}/users", headers=headers)
response = requests.get(f"{base_url}/users", headers=headers)
print(response.status_code)
# # Get User
res = requests.get(f"{base_url}/users/{user_id}", headers=headers)
response = requests.get(f"{base_url}/users/{user_id}", headers=headers)
print(response.status_code)
# # Update User
res = requests.put(
response = requests.put(
f"{base_url}/users/{user_id}", headers=headers, json={"fullname": "new name"}
)
print(response.status_code)
Expand Down
Loading

0 comments on commit f016e26

Please sign in to comment.