diff --git a/backend/extraction/parsing.py b/backend/extraction/parsing.py index cf394ba..8b7b073 100644 --- a/backend/extraction/parsing.py +++ b/backend/extraction/parsing.py @@ -27,7 +27,7 @@ SUPPORTED_MIMETYPES = sorted(HANDLERS.keys()) -MAX_FILE_SIZE = 10 # in MB +MAX_FILE_SIZE_MB = 10 # in MB MAX_PAGES = 50 # for PDFs @@ -73,10 +73,10 @@ def convert_binary_input_to_blob(data: BinaryIO) -> Blob: """Convert ingestion input to blob.""" file_size_in_mb = _get_file_size_in_mb(data) - if file_size_in_mb > MAX_FILE_SIZE: + if file_size_in_mb > MAX_FILE_SIZE_MB: raise HTTPException( status_code=413, - detail=f"File size exceeds the maximum limit of {MAX_FILE_SIZE} MB.", + detail=f"File size exceeds the maximum limit of {MAX_FILE_SIZE_MB} MB.", ) file_data = data.read() diff --git a/backend/server/api/configurables.py b/backend/server/api/configurables.py index 39a164b..f4c6e8c 100644 --- a/backend/server/api/configurables.py +++ b/backend/server/api/configurables.py @@ -1,20 +1,32 @@ """Endpoint for listing available chat models for extraction.""" -from typing import Any, Dict +from typing import List from fastapi import APIRouter +from typing_extensions import Annotated, TypedDict +from extraction.parsing import MAX_FILE_SIZE_MB, SUPPORTED_MIMETYPES from server.models import SUPPORTED_MODELS router = APIRouter( - prefix="/configurables", - tags=["Available chat models"], + prefix="/configuration", + tags=["Configuration"], responses={404: {"description": "Not found"}}, ) +class ConfigurationResponse(TypedDict): + """Response for configuration.""" + + available_models: Annotated[List[str], "List of available models for extraction."] + supported_mimetypes: Annotated[List[str], "List of supported mimetypes."] + max_file_size_mb: Annotated[int, "Maximum file size in MB."] + + @router.get("") -def get_configurables() -> Dict[str, Any]: - """Endpoint to get all chat models.""" +def get() -> ConfigurationResponse: + """Endpoint to show server configuration.""" return { - "models": sorted(SUPPORTED_MODELS.keys()), + "available_models": sorted(SUPPORTED_MODELS), + "supported_mimetypes": SUPPORTED_MIMETYPES, + "max_file_size_mb": MAX_FILE_SIZE_MB, } diff --git a/backend/tests/unit_tests/api/test_api_configurables.py b/backend/tests/unit_tests/api/test_api_configurables.py index 8232ad2..7842292 100644 --- a/backend/tests/unit_tests/api/test_api_configurables.py +++ b/backend/tests/unit_tests/api/test_api_configurables.py @@ -1,15 +1,19 @@ from tests.db import get_async_client -async def test_configurables_api() -> None: +async def test_configuration_api() -> None: + """Test the configuration API.""" async with get_async_client() as client: - response = await client.get("/configurables") + response = await client.get("/configuration") assert response.status_code == 200 result = response.json() assert isinstance(result, dict) - - assert "models" in result - models = result["models"] + assert sorted(result) == [ + "available_models", + "max_file_size_mb", + "supported_mimetypes", + ] + models = result["available_models"] assert all(isinstance(model_name, str) for model_name in models) assert "gpt-3.5-turbo" in models assert len(models) >= 2