From 58aabe7a0f01fc6d7f973462ec02434bd0c6e6e0 Mon Sep 17 00:00:00 2001 From: Panos Vagenas <35837085+vagenas@users.noreply.github.com> Date: Fri, 16 Jun 2023 15:02:39 +0200 Subject: [PATCH] fix: define Model API optional type defaults (#103) Signed-off-by: Panos Vagenas <35837085+vagenas@users.noreply.github.com> --- deepsearch/model/base/controller.py | 3 +- deepsearch/model/base/types.py | 8 +++--- .../examples/dummy_nlp_annotator/model.py | 3 +- .../examples/dummy_qa_generator/model.py | 4 +-- .../simple_geo_nlp_annotator/model.py | 3 +- deepsearch/model/kinds/nlp/model.py | 3 +- deepsearch/model/kinds/nlp/types.py | 8 +++--- deepsearch/model/kinds/qagen/model.py | 5 ++-- poetry.lock | 28 +++++++++---------- pyproject.toml | 4 +-- 10 files changed, 37 insertions(+), 32 deletions(-) diff --git a/deepsearch/model/base/controller.py b/deepsearch/model/base/controller.py index e7346382..080e2d59 100644 --- a/deepsearch/model/base/controller.py +++ b/deepsearch/model/base/controller.py @@ -1,7 +1,8 @@ from abc import ABC, abstractmethod from typing import Optional -from deepsearch.model.base.model import BaseDSModel, BaseModelConfig +from deepsearch.model.base.model import BaseDSModel +from deepsearch.model.base.types import BaseModelConfig from deepsearch.model.server.inference_types import ControllerInput, ControllerOutput diff --git a/deepsearch/model/base/types.py b/deepsearch/model/base/types.py index 86a234d0..edb89b6f 100644 --- a/deepsearch/model/base/types.py +++ b/deepsearch/model/base/types.py @@ -45,7 +45,7 @@ class BaseModelConfig(StrictModel): kind: Kind name: str version: str - url: Optional[str] - author: Optional[str] - description: Optional[str] - expected_compute_time: Optional[PositiveFloat] + url: Optional[str] = None + author: Optional[str] = None + description: Optional[str] = None + expected_compute_time: Optional[PositiveFloat] = None diff --git a/deepsearch/model/examples/dummy_nlp_annotator/model.py b/deepsearch/model/examples/dummy_nlp_annotator/model.py index 2f5622c3..92f37147 100644 --- a/deepsearch/model/examples/dummy_nlp_annotator/model.py +++ b/deepsearch/model/examples/dummy_nlp_annotator/model.py @@ -3,13 +3,14 @@ from fastapi import HTTPException, status from deepsearch.model.base.types import Kind -from deepsearch.model.kinds.nlp.model import BaseNLPModel, NLPConfig +from deepsearch.model.kinds.nlp.model import BaseNLPModel from deepsearch.model.kinds.nlp.types import ( AnnotateEntitiesOutput, AnnotatePropertiesOutput, AnnotateRelationshipsOutput, AnnotationLabels, EntityLabel, + NLPConfig, ) diff --git a/deepsearch/model/examples/dummy_qa_generator/model.py b/deepsearch/model/examples/dummy_qa_generator/model.py index e029d178..1259e054 100644 --- a/deepsearch/model/examples/dummy_qa_generator/model.py +++ b/deepsearch/model/examples/dummy_qa_generator/model.py @@ -1,8 +1,8 @@ from typing import List, Tuple from deepsearch.model.base.types import Kind -from deepsearch.model.kinds.qagen.model import BaseQAGenerator, QAGenConfig -from deepsearch.model.kinds.qagen.types import GenerateAnswersOutput +from deepsearch.model.kinds.qagen.model import BaseQAGenerator +from deepsearch.model.kinds.qagen.types import GenerateAnswersOutput, QAGenConfig class DummyQAGenerator(BaseQAGenerator): diff --git a/deepsearch/model/examples/simple_geo_nlp_annotator/model.py b/deepsearch/model/examples/simple_geo_nlp_annotator/model.py index 0b9daf22..47d04585 100644 --- a/deepsearch/model/examples/simple_geo_nlp_annotator/model.py +++ b/deepsearch/model/examples/simple_geo_nlp_annotator/model.py @@ -9,13 +9,14 @@ from fastapi import HTTPException, status from deepsearch.model.base.types import Kind -from deepsearch.model.kinds.nlp.model import BaseNLPModel, NLPConfig +from deepsearch.model.kinds.nlp.model import BaseNLPModel from deepsearch.model.kinds.nlp.types import ( AnnotateEntitiesOutput, AnnotatePropertiesOutput, AnnotateRelationshipsOutput, AnnotationLabels, EntityLabel, + NLPConfig, NLPType, PropertyLabel, RelationshipLabel, diff --git a/deepsearch/model/kinds/nlp/model.py b/deepsearch/model/kinds/nlp/model.py index b73c9e8a..08d846b0 100644 --- a/deepsearch/model/kinds/nlp/model.py +++ b/deepsearch/model/kinds/nlp/model.py @@ -2,7 +2,8 @@ from copy import deepcopy from typing import List, Optional -from deepsearch.model.base.model import BaseDSModel, BaseModelConfig +from deepsearch.model.base.model import BaseDSModel +from deepsearch.model.base.types import BaseModelConfig from deepsearch.model.kinds.nlp.types import ( AnnotateEntitiesOutput, AnnotatePropertiesOutput, diff --git a/deepsearch/model/kinds/nlp/types.py b/deepsearch/model/kinds/nlp/types.py index 0b94715d..ef1de63e 100644 --- a/deepsearch/model/kinds/nlp/types.py +++ b/deepsearch/model/kinds/nlp/types.py @@ -10,20 +10,20 @@ class NLPType(str, Enum): class FindEntitiesText(StrictModel): - entityNames: Optional[List[str]] + entityNames: Optional[List[str]] = None objectType: Literal[NLPType.text] texts: List[str] class FindPropertiesText(StrictModel): - propertyNames: Optional[List[str]] - entities: Optional[List[dict]] + propertyNames: Optional[List[str]] = None + entities: Optional[List[dict]] = None objectType: Literal[NLPType.text] texts: List[str] class FindRelationshipsText(StrictModel): - relationshipNames: Optional[List[str]] + relationshipNames: Optional[List[str]] = None entities: List[dict] objectType: Literal[NLPType.text] texts: List[str] diff --git a/deepsearch/model/kinds/qagen/model.py b/deepsearch/model/kinds/qagen/model.py index 4cc131b2..0818ebff 100644 --- a/deepsearch/model/kinds/qagen/model.py +++ b/deepsearch/model/kinds/qagen/model.py @@ -1,7 +1,8 @@ from abc import abstractmethod -from typing import List, Literal, Tuple +from typing import List, Tuple -from deepsearch.model.base.model import BaseDSModel, BaseModelConfig +from deepsearch.model.base.model import BaseDSModel +from deepsearch.model.base.types import BaseModelConfig from deepsearch.model.kinds.qagen.types import GenerateAnswersOutput, QAGenConfig diff --git a/poetry.lock b/poetry.lock index 9164ee8d..a9560aab 100644 --- a/poetry.lock +++ b/poetry.lock @@ -117,11 +117,11 @@ dev = ["Sphinx (==4.3.2)", "black (==22.3.0)", "build (==0.8.0)", "flake8 (==4.0 [[package]] name = "certifi" -version = "2021.10.8" +version = "2022.12.7" description = "Python package for providing Mozilla's CA Bundle." category = "main" optional = false -python-versions = "*" +python-versions = ">=3.6" [[package]] name = "cffi" @@ -269,7 +269,7 @@ tests = ["asttokens", "littleutils", "pytest", "rich"] [[package]] name = "fastapi" -version = "0.95.1" +version = "0.95.2" description = "FastAPI framework, high performance, easy to learn, fast to code, ready for production" category = "main" optional = true @@ -277,7 +277,7 @@ python-versions = ">=3.7" [package.dependencies] pydantic = ">=1.6.2,<1.7 || >1.7,<1.7.1 || >1.7.1,<1.7.2 || >1.7.2,<1.7.3 || >1.7.3,<1.8 || >1.8,<1.8.1 || >1.8.1,<2.0.0" -starlette = ">=0.26.1,<0.27.0" +starlette = ">=0.27.0,<0.28.0" [package.extras] all = ["email-validator (>=1.1.1)", "httpx (>=0.23.0)", "itsdangerous (>=1.1.0)", "jinja2 (>=2.11.2)", "orjson (>=3.2.1)", "python-multipart (>=0.0.5)", "pyyaml (>=5.3.1)", "ujson (>=4.0.1,!=4.0.2,!=4.1.0,!=4.2.0,!=4.3.0,!=5.0.0,!=5.1.0)", "uvicorn[standard] (>=0.12.0)"] @@ -1169,7 +1169,7 @@ tests = ["cython", "littleutils", "pygments", "pytest", "typeguard"] [[package]] name = "starlette" -version = "0.26.1" +version = "0.27.0" description = "The little ASGI library that shines." category = "main" optional = true @@ -1441,13 +1441,13 @@ docs = ["furo", "jaraco.packaging (>=9)", "jaraco.tidelift (>=1.4)", "rst.linker testing = ["flake8 (<5)", "func-timeout", "jaraco.functools", "jaraco.itertools", "more-itertools", "pytest (>=6)", "pytest-black (>=0.3.7)", "pytest-checkdocs (>=2.4)", "pytest-cov", "pytest-enabler (>=1.3)", "pytest-flake8", "pytest-mypy (>=0.9.1)"] [extras] -all = ["fastapi", "uvicorn", "anyio", "starlette"] -api = ["fastapi", "uvicorn", "anyio", "starlette"] +all = ["fastapi", "uvicorn", "anyio"] +api = ["fastapi", "uvicorn", "anyio"] [metadata] lock-version = "1.1" python-versions = "^3.8" -content-hash = "3168cfc28b033cc86b0ec4c24cce9d5f0037ea5a5fbeddbf65efba8e2a637d96" +content-hash = "b824da159b9811233641ec8ccf64d24952f8aa4818f8ae7e753b4691233e6066" [metadata.files] anyio = [ @@ -1493,8 +1493,8 @@ bleach = [ {file = "bleach-5.0.1.tar.gz", hash = "sha256:0d03255c47eb9bd2f26aa9bb7f2107732e7e8fe195ca2f64709fcf3b0a4a085c"}, ] certifi = [ - {file = "certifi-2021.10.8-py2.py3-none-any.whl", hash = "sha256:d62a0163eb4c2344ac042ab2bdf75399a71a2d8c7d47eac2e2ee91b9d6339569"}, - {file = "certifi-2021.10.8.tar.gz", hash = "sha256:78884e7c1d4b00ce3cea67b44566851c4343c120abd683433ce934a68ea58872"}, + {file = "certifi-2022.12.7-py3-none-any.whl", hash = "sha256:4ad3232f5e926d6718ec31cfc1fcadfde020920e278684144551c91769c7bc18"}, + {file = "certifi-2022.12.7.tar.gz", hash = "sha256:35824b4c3a97115964b408844d64aa14db1cc518f6562e8d7261699d1350a9e3"}, ] cffi = [ {file = "cffi-1.15.1-cp27-cp27m-macosx_10_9_x86_64.whl", hash = "sha256:a66d3508133af6e8548451b25058d5812812ec3798c886bf38ed24a98216fab2"}, @@ -1639,8 +1639,8 @@ executing = [ {file = "executing-1.2.0.tar.gz", hash = "sha256:19da64c18d2d851112f09c287f8d3dbbdf725ab0e569077efb6cdcbd3497c107"}, ] fastapi = [ - {file = "fastapi-0.95.1-py3-none-any.whl", hash = "sha256:a870d443e5405982e1667dfe372663abf10754f246866056336d7f01c21dab07"}, - {file = "fastapi-0.95.1.tar.gz", hash = "sha256:9569f0a381f8a457ec479d90fa01005cfddaae07546eb1f3fa035bc4797ae7d5"}, + {file = "fastapi-0.95.2-py3-none-any.whl", hash = "sha256:d374dbc4ef2ad9b803899bd3360d34c534adc574546e25314ab72c0c4411749f"}, + {file = "fastapi-0.95.2.tar.gz", hash = "sha256:4d9d3e8c71c73f11874bcf5e33626258d143252e329a01002f767306c64fb982"}, ] filelock = [ {file = "filelock-3.12.0-py3-none-any.whl", hash = "sha256:ad98852315c2ab702aeb628412cbf7e95b7ce8c3bf9565670b4eaecf1db370a9"}, @@ -2068,8 +2068,8 @@ stack-data = [ {file = "stack_data-0.6.2.tar.gz", hash = "sha256:32d2dd0376772d01b6cb9fc996f3c8b57a357089dec328ed4b6553d037eaf815"}, ] starlette = [ - {file = "starlette-0.26.1-py3-none-any.whl", hash = "sha256:e87fce5d7cbdde34b76f0ac69013fd9d190d581d80681493016666e6f96c6d5e"}, - {file = "starlette-0.26.1.tar.gz", hash = "sha256:41da799057ea8620e4667a3e69a5b1923ebd32b1819c8fa75634bbe8d8bea9bd"}, + {file = "starlette-0.27.0-py3-none-any.whl", hash = "sha256:918416370e846586541235ccd38a474c08b80443ed31c578a418e2209b3eef91"}, + {file = "starlette-0.27.0.tar.gz", hash = "sha256:6a6b0d042acb8d469a01eba54e9cda6cbd24ac602c4cd016723117d6a7e73b75"}, ] tabulate = [ {file = "tabulate-0.8.10-py3-none-any.whl", hash = "sha256:0ba055423dbaa164b9e456abe7920c5e8ed33fcc16f6d1b2f2d152c8e1e8b4fc"}, diff --git a/pyproject.toml b/pyproject.toml index 2f7e47a7..9d2e9e7d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -34,7 +34,7 @@ python = "^3.8" # Dependencies from generated packages urllib3 = "^1.26.8" six = "^1.16.0" -certifi = "^2021.10.8" +certifi = "^2022.12.07" python-dateutil = "^2.8.2" # Actual dependencies @@ -46,7 +46,7 @@ tabulate = "^0.8.9" pluggy = "^1.0.0" tqdm = "^4.64.0" -fastapi = { version = "^0.95.1", optional = true } +fastapi = { version = "^0.95.2", optional = true } uvicorn = { version = "^0.21.1", optional = true } anyio = { version = "^3.6.2", optional = true } starlette = { version = "^0.26.1", optional = true }