Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add model API version check #84

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions deepsearch/model/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = "1.0.0"
16 changes: 15 additions & 1 deletion deepsearch/model/server/deepsearch_annotator_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from datetime import datetime
from typing import Coroutine, Dict, Union

import packaging.version
import uvicorn
from anyio import CapacityLimiter
from anyio.lowlevel import RunVar
Expand All @@ -17,6 +18,7 @@
from fastapi.responses import JSONResponse
from starlette import status

from deepsearch.model import __version__ as MODEL_API_VERSION
from deepsearch.model.base.base_annotator import BaseAnnotator
from deepsearch.model.server.request_schemas import AnnotateRequestModel

Expand All @@ -29,7 +31,7 @@ def __init__(self):
# Start the fast API app
self.app = FastAPI()
self.annotate_controller = self.AnnotateController(self.annotators_list)
_log = logging.getLogger(__name__)
print(f"Model API version: {MODEL_API_VERSION}")

@self.app.on_event("startup")
async def startup_event():
Expand Down Expand Up @@ -84,6 +86,8 @@ async def annotator_process(
# TODO pydantic models for return
request_body = request.dict()

validate_version(req_api_version=request_body.get("apiVersion", ""))

request_arrival_time = time.time()
failure_headers = {
"X-Request-Arrival-Time": str(request_arrival_time),
Expand Down Expand Up @@ -185,6 +189,16 @@ def annotate_process(
headers["X-request-id"] = str(request["id"])
return JSONResponse(content=result, headers=headers)

def validate_version(req_api_version: str) -> None:
supported_versions = [
f"api/v{packaging.version.parse(MODEL_API_VERSION).major}",
]
if req_api_version not in supported_versions:
raise HTTPException(
status_code=400,
detail=f"Unsupported API version '{req_api_version}'",
)

def register_annotator(
self, cls: BaseAnnotator, name: Union[str, None] = None
) -> None:
Expand Down