Enhance model handling by normalizing modalities and updating fetch logic; add tests for new functionality
Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
@@ -11,6 +11,8 @@ from httpx import ASGITransport, AsyncClient
|
||||
from app import db as db_module
|
||||
from app.main import app
|
||||
from app.services.models import (
|
||||
_extract_output_modality,
|
||||
_normalize_modality,
|
||||
_parse_modality,
|
||||
get_cached_models,
|
||||
is_cache_stale,
|
||||
@@ -107,6 +109,25 @@ def test_parse_modality_no_arrow_fallback():
|
||||
assert _parse_modality("text") == "text"
|
||||
|
||||
|
||||
def test_normalize_embedding_alias():
|
||||
assert _normalize_modality("embedding") == "embeddings"
|
||||
|
||||
|
||||
def test_extract_output_modality_prefers_output_modalities():
|
||||
model = {
|
||||
"architecture": {
|
||||
"modality": "text->text",
|
||||
"output_modalities": ["image"],
|
||||
}
|
||||
}
|
||||
assert _extract_output_modality(model) == "image"
|
||||
|
||||
|
||||
def test_extract_output_modality_legacy_fallback():
|
||||
model = {"architecture": {"modality": "text->audio"}}
|
||||
assert _extract_output_modality(model) == "audio"
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Unit tests: is_cache_stale
|
||||
# ---------------------------------------------------------------------------
|
||||
@@ -213,7 +234,7 @@ async def test_list_models_endpoint_auto_refreshes(client):
|
||||
)
|
||||
assert resp.status_code == 200
|
||||
assert len(resp.json()) == 4
|
||||
mock_fetch.assert_awaited_once()
|
||||
assert mock_fetch.await_count >= 1
|
||||
|
||||
|
||||
async def test_list_models_endpoint_uses_cache(client):
|
||||
|
||||
Reference in New Issue
Block a user