Skip to content

Commit

Permalink
expose more configuration for the UI (#68)
Browse files Browse the repository at this point in the history
Expose configuration for the UI
  • Loading branch information
eyurtsev authored Mar 21, 2024
1 parent 7e61dca commit 6f3d898
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 14 deletions.
6 changes: 3 additions & 3 deletions backend/extraction/parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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()
Expand Down
24 changes: 18 additions & 6 deletions backend/server/api/configurables.py
Original file line number Diff line number Diff line change
@@ -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: List[str]
supported_mimetypes: List[str]
max_file_size_mb: int


@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,
}
14 changes: 9 additions & 5 deletions backend/tests/unit_tests/api/test_api_configurables.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 6f3d898

Please sign in to comment.