diff --git a/.github/utils/generate_openapi_specs.py b/.github/utils/generate_openapi_specs.py index d4ae518b1..0479d4641 100755 --- a/.github/utils/generate_openapi_specs.py +++ b/.github/utils/generate_openapi_specs.py @@ -10,7 +10,7 @@ sys.path.append(".") from rest_api.utils import get_openapi_specs, get_app, get_pipelines # pylint: disable=wrong-import-position from haystack import __version__ # pylint: disable=wrong-import-position -REST_PATH = Path("./rest_api").absolute() +REST_PATH = Path("./rest_api/rest_api").absolute() PIPELINE_PATH = str(REST_PATH / "pipeline" / "pipeline_empty.haystack-pipeline.yml") APP_PATH = str(REST_PATH / "application.py") DOCS_PATH = Path("./docs") / "_src" / "api" / "openapi" diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 473a7d266..cfb32fa15 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -80,7 +80,7 @@ jobs: - name: Pylint run: | - pylint -ry -j 0 haystack/ rest_api/ ui/ + pylint -ry -j 0 haystack/ rest_api/rest_api ui/ - uses: act10ns/slack@v1 with: diff --git a/rest_api/__init__.py b/rest_api/README.md similarity index 100% rename from rest_api/__init__.py rename to rest_api/README.md diff --git a/rest_api/pyproject.toml b/rest_api/pyproject.toml new file mode 100644 index 000000000..b4e9895e9 --- /dev/null +++ b/rest_api/pyproject.toml @@ -0,0 +1,71 @@ +[build-system] +requires = ["hatchling"] +build-backend = "hatchling.build" + +[project] +name = "rest-api" +description = 'API server for Haystack (https://github.com/deepset-ai/haystack)' +readme = "README.md" +requires-python = ">=3.7" +license = "Apache-2.0" +keywords = [] +authors = [ + { name = "deepset.ai", email = "malte.pietsch@deepset.ai" }, +] +classifiers = [ + "Development Status :: 5 - Production/Stable", + "Intended Audience :: Science/Research", + "Topic :: Scientific/Engineering :: Artificial Intelligence", + "Operating System :: OS Independent", + "Programming Language :: Python", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: Implementation :: CPython", +] +dependencies = [ + "farm-haystack", + "fastapi<1", + "uvicorn<1", + "gunicorn<21", + "python-multipart<1", # optional FastAPI dependency for form data +] +dynamic = ["version"] + +[project.urls] +Documentation = "https://github.com/deepset-ai/haystack/tree/main/rest_api#readme" +Issues = "https://github.com/deepset-ai/haystack/issues" +Source = "https://github.com/deepset-ai/haystack/tree/main/rest_api" + +[tool.hatch.version] +path = "rest_api/__about__.py" + +[tool.hatch.build.targets.sdist] +[tool.hatch.build.targets.wheel] + +[tool.hatch.envs.default] +dependencies = [ + "pytest", + "pytest-cov", +] +[tool.hatch.envs.default.scripts] +cov = "pytest --cov-report=term-missing --cov-config=pyproject.toml --cov=rest_api --cov=tests" +no-cov = "cov --no-cov" + +[[tool.hatch.envs.test.matrix]] +python = ["37", "38", "39", "310"] + +[tool.coverage.run] +branch = true +parallel = true +omit = [ + "rest_api/__about__.py", +] + +[tool.coverage.report] +exclude_lines = [ + "no cov", + "if __name__ == .__main__.:", + "if TYPE_CHECKING:", +] diff --git a/rest_api/rest_api/__about__.py b/rest_api/rest_api/__about__.py new file mode 100644 index 000000000..1f3b2b7c7 --- /dev/null +++ b/rest_api/rest_api/__about__.py @@ -0,0 +1,10 @@ +import logging + +from pathlib import Path + + +__version__ = "0.0.0" +try: + __version__ = open(Path(__file__).parent.parent / "VERSION.txt", "r").read() +except Exception as e: + logging.exception("No VERSION.txt found!") diff --git a/rest_api/controller/errors/__init__.py b/rest_api/rest_api/__init__.py similarity index 100% rename from rest_api/controller/errors/__init__.py rename to rest_api/rest_api/__init__.py diff --git a/rest_api/application.py b/rest_api/rest_api/application.py similarity index 100% rename from rest_api/application.py rename to rest_api/rest_api/application.py diff --git a/rest_api/config.py b/rest_api/rest_api/config.py similarity index 100% rename from rest_api/config.py rename to rest_api/rest_api/config.py diff --git a/rest_api/controller/__init__.py b/rest_api/rest_api/controller/__init__.py similarity index 100% rename from rest_api/controller/__init__.py rename to rest_api/rest_api/controller/__init__.py diff --git a/rest_api/controller/document.py b/rest_api/rest_api/controller/document.py similarity index 100% rename from rest_api/controller/document.py rename to rest_api/rest_api/controller/document.py diff --git a/rest_api/rest_api/controller/errors/__init__.py b/rest_api/rest_api/controller/errors/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/rest_api/controller/errors/http_error.py b/rest_api/rest_api/controller/errors/http_error.py similarity index 100% rename from rest_api/controller/errors/http_error.py rename to rest_api/rest_api/controller/errors/http_error.py diff --git a/rest_api/controller/feedback.py b/rest_api/rest_api/controller/feedback.py similarity index 100% rename from rest_api/controller/feedback.py rename to rest_api/rest_api/controller/feedback.py diff --git a/rest_api/controller/file_upload.py b/rest_api/rest_api/controller/file_upload.py similarity index 100% rename from rest_api/controller/file_upload.py rename to rest_api/rest_api/controller/file_upload.py diff --git a/rest_api/controller/search.py b/rest_api/rest_api/controller/search.py similarity index 96% rename from rest_api/controller/search.py rename to rest_api/rest_api/controller/search.py index 893146560..70cc9f04c 100644 --- a/rest_api/controller/search.py +++ b/rest_api/rest_api/controller/search.py @@ -1,6 +1,6 @@ from typing import Dict, Any -import collections +from collections.abc import Mapping import logging import time import json @@ -72,7 +72,7 @@ def _process_request(pipeline, request) -> Dict[str, Any]: # format targeted node filters (e.g. "params": {"Retriever": {"filters": {"value"}}}) for key in params.keys(): - if isinstance(params[key], collections.Mapping) and "filters" in params[key].keys(): + if isinstance(params[key], Mapping) and "filters" in params[key].keys(): params[key]["filters"] = _format_filters(params[key]["filters"]) result = pipeline.run(query=request.query, params=params, debug=request.debug) diff --git a/rest_api/controller/utils.py b/rest_api/rest_api/controller/utils.py similarity index 100% rename from rest_api/controller/utils.py rename to rest_api/rest_api/controller/utils.py diff --git a/rest_api/pipeline/__init__.py b/rest_api/rest_api/pipeline/__init__.py similarity index 100% rename from rest_api/pipeline/__init__.py rename to rest_api/rest_api/pipeline/__init__.py diff --git a/rest_api/pipeline/custom_component.py b/rest_api/rest_api/pipeline/custom_component.py similarity index 100% rename from rest_api/pipeline/custom_component.py rename to rest_api/rest_api/pipeline/custom_component.py diff --git a/rest_api/pipeline/pipeline_empty.haystack-pipeline.yml b/rest_api/rest_api/pipeline/pipeline_empty.haystack-pipeline.yml similarity index 100% rename from rest_api/pipeline/pipeline_empty.haystack-pipeline.yml rename to rest_api/rest_api/pipeline/pipeline_empty.haystack-pipeline.yml diff --git a/rest_api/pipeline/pipelines.haystack-pipeline.yml b/rest_api/rest_api/pipeline/pipelines.haystack-pipeline.yml similarity index 100% rename from rest_api/pipeline/pipelines.haystack-pipeline.yml rename to rest_api/rest_api/pipeline/pipelines.haystack-pipeline.yml diff --git a/rest_api/pipeline/pipelines_dpr.haystack-pipeline.yml b/rest_api/rest_api/pipeline/pipelines_dpr.haystack-pipeline.yml similarity index 100% rename from rest_api/pipeline/pipelines_dpr.haystack-pipeline.yml rename to rest_api/rest_api/pipeline/pipelines_dpr.haystack-pipeline.yml diff --git a/rest_api/schema.py b/rest_api/rest_api/schema.py similarity index 100% rename from rest_api/schema.py rename to rest_api/rest_api/schema.py diff --git a/rest_api/utils.py b/rest_api/rest_api/utils.py similarity index 100% rename from rest_api/utils.py rename to rest_api/rest_api/utils.py diff --git a/rest_api/setup.py b/rest_api/setup.py deleted file mode 100644 index f643219bf..000000000 --- a/rest_api/setup.py +++ /dev/null @@ -1,45 +0,0 @@ -import logging -from pathlib import Path - -from setuptools import setup, find_packages - - -VERSION = "0.0.0" -try: - VERSION = open(Path(__file__).parent.parent / "VERSION.txt", "r").read() -except Exception as e: - logging.exception("No VERSION.txt found!") - - -setup( - name="farm-haystack-rest-api", - version=VERSION, - description="Demo REST API server for Haystack (https://github.com/deepset-ai/haystack)", - author="deepset.ai", - author_email="malte.pietsch@deepset.ai", - url=" https://github.com/deepset-ai/haystack/tree/main/rest_api", - classifiers=[ - "Development Status :: 5 - Production/Stable", - "Intended Audience :: Science/Research", - "Topic :: Scientific/Engineering :: Artificial Intelligence", - "Operating System :: OS Independent", - "Programming Language :: Python", - "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", - "Programming Language :: Python :: 3.9", - "Programming Language :: Python :: 3.10", - ], - packages=find_packages(), - python_requires=">=3.7, <4", - install_requires=[ - # The link below cannot be translated properly into setup.cfg - # because it looks into the parent folder. - # TODO check if this is still a limitation later on - f"farm-haystack @ file://localhost/{Path(__file__).parent.parent}#egg=farm-haystack", - "fastapi<1", - "uvicorn<1", - "gunicorn<21", - "python-multipart<1", # optional FastAPI dependency for form data - ], -)