-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
30 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: 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, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |