Skip to content

#1 PDF Application on GitHub that lets you edit PDFs on any device anywhere

1000 B
Raw Blame
from __future__ import annotations

from typing import Annotated

from fastapi import APIRouter, Depends

from stirling.agents import DocumentClassifierAgent
from stirling.api.dependencies import get_document_classifier_agent
from stirling.api.linked_instance import LINKED_INSTANCE
from stirling.contracts import ClassifyDocumentRequest, ClassifyDocumentResponse

router = APIRouter(prefix="/api/v1/documents/classify", tags=["document-classifier"])


@router.post("", response_model=ClassifyDocumentResponse, openapi_extra=LINKED_INSTANCE)
async def classify_document(
    request: ClassifyDocumentRequest,
    agent: Annotated[DocumentClassifierAgent, Depends(get_document_classifier_agent)],
) -> ClassifyDocumentResponse:
    """Classify a document from its supplied page text against the allowed labels.

    The caller sends the bounded page window inline, so no per-user document
    storage is touched here — the request is self-contained.
    """
    return await agent.classify(request)