| 1 | # SPDX-License-Identifier: Apache-2.0 |
| 2 | # SPDX-FileCopyrightText: Copyright contributors to the vLLM project |
| 3 | |
| 4 | from fastapi import APIRouter, Depends, Request |
| 5 | from fastapi.responses import Response |
| 6 | |
| 7 | from vllm.entrypoints.serve.utils.api_utils import ( |
| 8 | load_aware_call, |
| 9 | validate_json_request, |
| 10 | with_cancellation, |
| 11 | ) |
| 12 | |
| 13 | from .protocol import ClassificationRequest |
| 14 | from .serving import ServingClassification |
| 15 | |
| 16 | router = APIRouter() |
| 17 | |
| 18 | |
| 19 | def classify(request: Request) -> ServingClassification: |
| 20 | handler = getattr(request.app.state, "serving_classification", None) |
| 21 | if handler is None: |
| 22 | raise NotImplementedError("The model does not support Classification API") |
| 23 | return handler |
| 24 | |
| 25 | |
| 26 | @router.post("/classify", dependencies=[Depends(validate_json_request)]) |
| 27 | @with_cancellation |
| 28 | @load_aware_call |
| 29 | async def create_classify( |
| 30 | request: ClassificationRequest, raw_request: Request |
| 31 | ) -> Response: |
| 32 | handler = classify(raw_request) |
| 33 | return await handler(request, raw_request) |