mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-08-24 02:57:13 +00:00
fix(wizard): parse ranked model selection entries
This commit is contained in:
@@ -262,7 +262,14 @@ class SpaceService:
|
|||||||
data = data.get('models', data.get('items', []))
|
data = data.get('models', data.get('items', []))
|
||||||
if not isinstance(data, list):
|
if not isinstance(data, list):
|
||||||
raise ValueError('Failed to get model selection: invalid response')
|
raise ValueError('Failed to get model selection: invalid response')
|
||||||
return [SpaceModelSelection.model_validate(model) for model in data]
|
|
||||||
|
models = []
|
||||||
|
for selection in data:
|
||||||
|
if isinstance(selection, dict) and isinstance(selection.get('model'), dict):
|
||||||
|
models.append(selection['model'])
|
||||||
|
else:
|
||||||
|
models.append(selection)
|
||||||
|
return [SpaceModelSelection.model_validate(model) for model in models]
|
||||||
|
|
||||||
async def get_recommended_chat_model(self, context: typing.Any) -> dict:
|
async def get_recommended_chat_model(self, context: typing.Any) -> dict:
|
||||||
"""Resolve Space's first ranked chat model to a local Workspace model."""
|
"""Resolve Space's first ranked chat model to a local Workspace model."""
|
||||||
|
|||||||
@@ -823,8 +823,8 @@ class TestSpaceServiceGetModels:
|
|||||||
class TestSpaceServiceGetModelSelection:
|
class TestSpaceServiceGetModelSelection:
|
||||||
"""Tests for availability-ranked model selection."""
|
"""Tests for availability-ranked model selection."""
|
||||||
|
|
||||||
@pytest.mark.parametrize('use_envelope', [False, True])
|
@pytest.mark.parametrize('response_shape', ['direct', 'models-envelope', 'availability-wrapper'])
|
||||||
async def test_preserves_selection_order_and_category_query(self, use_envelope):
|
async def test_preserves_selection_order_and_category_query(self, response_shape):
|
||||||
ap = SimpleNamespace(instance_config=SimpleNamespace(data={}))
|
ap = SimpleNamespace(instance_config=SimpleNamespace(data={}))
|
||||||
service = SpaceService(ap)
|
service = SpaceService(ap)
|
||||||
models = [
|
models = [
|
||||||
@@ -843,7 +843,16 @@ class TestSpaceServiceGetModelSelection:
|
|||||||
'status': 'active',
|
'status': 'active',
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
payload = {'code': 0, 'data': {'models': models} if use_envelope else models}
|
if response_shape == 'models-envelope':
|
||||||
|
data = {'models': models}
|
||||||
|
elif response_shape == 'availability-wrapper':
|
||||||
|
data = [
|
||||||
|
{'model': model, 'latency_ms': index + 10, 'http_code': 200}
|
||||||
|
for index, model in enumerate(models)
|
||||||
|
]
|
||||||
|
else:
|
||||||
|
data = models
|
||||||
|
payload = {'code': 0, 'data': data}
|
||||||
mock_response = MagicMock(status=200)
|
mock_response = MagicMock(status=200)
|
||||||
|
|
||||||
with (
|
with (
|
||||||
|
|||||||
Reference in New Issue
Block a user