Skip to content
This repository has been archived by the owner on Jul 18, 2024. It is now read-only.

Commit

Permalink
Add Pytests for API (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
YrrepNoj authored Jan 16, 2024
1 parent b50424c commit 0c6a042
Show file tree
Hide file tree
Showing 21 changed files with 547 additions and 402 deletions.
14 changes: 0 additions & 14 deletions .github/workflows/environment.yaml

This file was deleted.

21 changes: 21 additions & 0 deletions .github/workflows/pytest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: pytest
on: [pull_request]

jobs:
pytest:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version-file: 'pyproject.toml'

- name: Run Repeater
run: docker run -p 50051:50051 -d ghcr.io/defenseunicorns/leapfrogai/repeater:0.3.3

- run: make requirements-dev

- run: make test
env:
LFAI_RUN_REPEATER_TESTS: true
49 changes: 49 additions & 0 deletions .github/workflows/test-deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Test Package Deployment
on:
pull_request

jobs:
e2e-build:
runs-on: ubuntu-latest

steps:
- name: Checkout Repo
uses: actions/checkout@v4

- name: Install Zarf
uses: defenseunicorns/setup-zarf@main
with:
download-init-package: true

- name: Login to Registry1
uses: docker/login-action@v3
with:
registry: registry1.dso.mil
username: ${{ secrets.IRON_BANK_ROBOT_USERNAME }}
password: ${{ secrets.IRON_BANK_ROBOT_PASSWORD }}

- name: Build leapfrogai image
run: make docker-build VERSION=local

- name: Build leapfrogai zarf package
run: make zarf-build VERSION=local

- name: Setup K3D
uses: defenseunicorns/zarf/.github/actions/k3d@main

- name: Initialize zarf
run: zarf init --confirm

- name: Deploy LFAI Package
run: zarf package deploy zarf-package-leapfrogai-api-amd64*.tar.zst --confirm

- name: Debug Deployment
run: |
zarf package list
zarf connect list
10 changes: 7 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,17 @@ requirements-dev:
python -m pip install -r requirements-dev.txt

requirements:
pip-sync requirements.txt requirements-dev.txt
pip-sync requirements.txt

build-requirements:
pip-compile -o requirements.txt pyproject.toml

build-requirements-dev:
pip-compile --extra dev -o requirements-dev.txt pyproject.toml --allow-unsafe

.PHONY: test
test:
pytest **/*.py
python -m pytest . -v

dev:
uvicorn main:app --port 3000 --reload
Expand All @@ -28,4 +29,7 @@ docker-build:
docker build -t ghcr.io/defenseunicorns/leapfrogai/leapfrogai-api:${VERSION} .

docker-push:
docker push ghcr.io/defenseunicorns/leapfrogai/leapfrogai-api:${VERSION}
docker push ghcr.io/defenseunicorns/leapfrogai/leapfrogai-api:${VERSION}

zarf-build:
zarf package create . --confirm --set LFAI_API_VERSION=${VERSION}
10 changes: 5 additions & 5 deletions backends/openai/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class ChatCompletionRequest(BaseModel):
class ChatChoice(BaseModel):
index: int
message: ChatMessage
finish_reason: str
finish_reason: str | None = ""


class ChatStreamChoice(BaseModel):
Expand Down Expand Up @@ -140,10 +140,10 @@ class ModelResponse(BaseModel):
class CreateTranscriptionRequest(BaseModel):
file: UploadFile
model: str
language: str
prompt: str
response_format: str
temperature: float
language: str = ""
prompt: str = ""
response_format: str = ""
temperature: float = 1

@classmethod
def as_form(
Expand Down
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@ dependencies = [
requires-python = "==3.11.6"

[project.optional-dependencies]
dev = ["pip-tools", "pytest", "black", "isort", "selenium"]
dev = ["pip-tools", "pytest", "black", "isort", "httpx", "selenium"]

[tool.pip-tools]
generate-hashes = true

[tool.setuptools.packages.find]
exclude = ["chart"]

[tool.pytest.ini_options]
addopts = ["--import-mode=importlib"]
502 changes: 243 additions & 259 deletions requirements-dev.txt

Large diffs are not rendered by default.

8 changes: 1 addition & 7 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# This file is autogenerated by pip-compile with Python 3.9
# This file is autogenerated by pip-compile with Python 3.11
# by the following command:
#
# pip-compile --generate-hashes --output-file=requirements.txt pyproject.toml
Expand All @@ -19,10 +19,6 @@ click==8.1.7 \
--hash=sha256:ae74fb96c20a0277a1d615f1e4d73c8414f5a98db8b799a7931d1582f3390c28 \
--hash=sha256:ca9853ad459e787e2192211578cc907e7594e294c7ccc834310722b41b9ca6de
# via uvicorn
exceptiongroup==1.1.3 \
--hash=sha256:097acd85d473d75af5bb98e41b61ff7fe35efe6675e4f9370ec6ec5126d160e9 \
--hash=sha256:343280667a4585d195ca1cf9cef84a4e178c4b6cf2274caef9859782b567d5e3
# via anyio
fastapi==0.103.1 \
--hash=sha256:345844e6a82062f06a096684196aaf96c1198b25c06b72c1311b882aa2d8a35d \
--hash=sha256:5e5f17e826dbd9e9b5a5145976c5cd90bcaa61f2bf9a69aca423f2bcebe44d83
Expand Down Expand Up @@ -304,8 +300,6 @@ typing-extensions==4.7.1 \
# fastapi
# pydantic
# pydantic-core
# starlette
# uvicorn
uvicorn==0.23.2 \
--hash=sha256:1f9be6558f01239d4fdf22ef8126c39cb1ad0addf76c40e760549d2c2f43ab53 \
--hash=sha256:4d3cc12d7727ba72b64d12d3cc7743124074c0a69f7b201512fc50c3e3f1569a
Expand Down
7 changes: 0 additions & 7 deletions test/fixtures/config.yaml

This file was deleted.

13 changes: 0 additions & 13 deletions test/test_complete.py

This file was deleted.

39 changes: 0 additions & 39 deletions test/test_complete_stream.py

This file was deleted.

8 changes: 0 additions & 8 deletions test/test_simple_stream.py

This file was deleted.

16 changes: 0 additions & 16 deletions test/this_will_work.py

This file was deleted.

Empty file added tests/__init__.py
Empty file.
File renamed without changes.
3 changes: 3 additions & 0 deletions tests/fixtures/test-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
models:
- name: repeater
backend: localhost:50051
Loading

0 comments on commit 0c6a042

Please sign in to comment.