Skip to content

Commit

Permalink
Backend OpenAI tests are added
Browse files Browse the repository at this point in the history
* base unit tests are added
* OpenAI unit tests are added
* Backend.submit with OpenaAI backend integration test is added

Other changes:
* `.env.example` is added as a source of a project configuration
* `README.md` now has project configuring and testing small guide
* `mypy` is configured in `pyproject.toml`
* `Makefile` is improved
* `polyfactory` package is INSTALLED for creating mock data models
  • Loading branch information
Dmytro Parfeniuk committed Jul 11, 2024
1 parent 4af96de commit f956055
Show file tree
Hide file tree
Showing 29 changed files with 674 additions and 277 deletions.
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# OpenAI compatible server address.
# If you are going to run the
OPENAI_BASE_URL=http://127.0.0.1:8080
OPENAI_API_KEY=invalid
10 changes: 7 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
install:
python -m pip install -r requirements.txt


.PHONY: install.dev
install.dev:
python -m pip install -e .[dev]


.PHONY: build
build:
python setup.py sdist bdist_wheel
Expand All @@ -15,8 +17,7 @@ build:
quality:
python -m ruff check src tests
python -m isort --check src tests
python -m flake8 src tests --max-line-length 88
python -m mypy src
python -m mypy


.PHONY: style
Expand All @@ -28,16 +29,19 @@ style:

.PHONY: test
test:
python -m pytest -s -vvv --cache-clear tests
python -m pytest tests


.PHONY: test.unit
test.unit:
python -m pytest tests/unit


.PHONY: test.integration
test.integration:
python -m pytest tests/integration


.PHONY: test.e2e
test.e2e:
python -m pytest tests/e2e
Expand Down
37 changes: 36 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,36 @@
# guidellm
# guidellm

# Project configuration

The project is configured with environment variables. Check the example in `.env.example`.

```sh
# Create .env file and update the configuration
cp .env.example .env

# Export all variables
set -o allexport; source .env; set +o allexport
```

## Environment Variables

| Variable | Default Value | Description |
| --------------- | --------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| OPENAI_BASE_URL | http://127.0.0.1:8080 | The host where the `openai` library will make requests to. For running integration tests it is required to have the external OpenAI compatible server running. |
| OPENAI_API_KEY | invalid | [OpenAI Platform](https://platform.openai.com/api-keys) to create a new API key. This value is not used for tests. |

## Running Tests

`pytest` package is used as a testing framework. All the tests are int he `tests/` folder.
`pytest` configuration is in the `pyproject.toml`.

The `Makefile` includes all the necessary commands that could be run from the project root.

```sh
# Using Makefile
make test # run all the tests
make test.integration # run only integration tests
make test.unit # run only unit tests
make test.e2e # run only E2E tests
```

1 change: 0 additions & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
TODO
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
TODO
TODO
52 changes: 41 additions & 11 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,30 +1,60 @@
[build-system]
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"
requires = ['setuptools', 'wheel']
build-backend = 'setuptools.build_meta'



[tool.black]
line-length = 88
target-version = ['py38']



[tool.isort]
profile = "black"
profile = 'black'


[tool.mypy]
files = "src/guidellm"

[tool.ruff]
exclude = ["build", "dist", "env", ".venv"]
exclude = ['build', 'dist', 'env', '.venv']
lint.select = ["E", "F", "W"]
line-length = 88


[tool.flake8]
max-line-length = 88

[tool.pytest.ini_options]
addopts = '-s -vvv --cache-clear'
asyncio_mode = 'auto'
markers = [
"smoke: quick tests to check basic functionality",
"sanity: detailed tests to ensure major functions work correctly",
"regression: tests to ensure that new changes do not break existing functionality"
'smoke: quick tests to check basic functionality',
'sanity: detailed tests to ensure major functions work correctly',
'regression: tests to ensure that new changes do not break existing functionality'
]
filterwarnings = [
'ignore::RuntimeWarning',
'ignore::UserWarning',
'ignore::DeprecationWarning',
]



[tool.mypy]
python_version = '3.8'
files = 'src/guidellm'
show_error_codes = true
namespace_packages = false
check_untyped_defs = true

warn_redundant_casts = true
warn_unused_ignores = true

# Silint "type import errors" as our 3rd-party libs does not have types
# Check: https://mypy.readthedocs.io/en/latest/config_file.html#import-discovery
follow_imports = 'silent'

[[tool.mypy.overrides]]
module = ['transformers.*']
ignore_missing_imports=true



54 changes: 28 additions & 26 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,50 +1,52 @@
from setuptools import setup, find_packages
from typing import Tuple

from setuptools import find_packages, setup


def _setup_long_description() -> Tuple[str, str]:
return open("README.md", "r", encoding="utf-8").read(), "text/markdown"


setup(
name='guidellm',
version='0.1.0',
author='Neuralmagic, Inc.',
description='Guidance platform for deploying and managing large language models.',
name="guidellm",
version="0.1.0",
author="Neuralmagic, Inc.",
description="Guidance platform for deploying and managing large language models.",
long_description=_setup_long_description()[0],
long_description_content_type=_setup_long_description()[1],
license="Apache",
url="https://github.com/neuralmagic/guidellm",
packages=find_packages(where='src'),
package_dir={'': 'src'},
packages=find_packages(where="src"),
package_dir={"": "src"},
include_package_data=True,
install_requires=[
'click',
'datasets',
'loguru',
'numpy',
'openai',
'requests',
'transformers',
"click",
"datasets",
"loguru",
"numpy",
"openai",
"requests",
"transformers",
],
extras_require={
'dev': [
'pytest',
'sphinx',
'ruff',
'mypy',
'black',
'isort',
'flake8',
'pre-commit',
"dev": [
"black",
"flake8",
"isort",
"mypy",
"polyfactory",
"pre-commit",
"pytest",
"ruff",
"sphinx",
],
},
entry_points={
'console_scripts': [
'guidellm=guidellm.main:main',
"console_scripts": [
"guidellm=guidellm.main:main",
],
},
python_requires=">=3.8.0",
python_requires=">=3.8.0,<4.0",
classifiers=[
"Development Status :: 5 - Production/Stable",
"Programming Language :: Python :: 3",
Expand Down
Empty file removed src/__init__.py
Empty file.
4 changes: 2 additions & 2 deletions src/guidellm/backend/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from .base import Backend, BackendTypes, GenerativeResponse
from .base import Backend, BackendEngine, GenerativeResponse
from .openai import OpenAIBackend

__all__ = [
"Backend",
"BackendTypes",
"BackendEngine",
"GenerativeResponse",
"OpenAIBackend",
]
Loading

0 comments on commit f956055

Please sign in to comment.