mirror of
https://github.com/meta-llama/llama-stack.git
synced 2025-07-27 06:28:50 +00:00
update: add validation on non-string type
Signed-off-by: Wen Zhou <wenzhou@redhat.com>
This commit is contained in:
parent
8563c76f88
commit
0b051c037b
2 changed files with 26 additions and 4 deletions
|
@ -26,9 +26,10 @@ class ProviderInfo(BaseModel):
|
||||||
def validate_metrics_url(cls, v):
|
def validate_metrics_url(cls, v):
|
||||||
if v is None:
|
if v is None:
|
||||||
return None
|
return None
|
||||||
if isinstance(v, str):
|
if not isinstance(v, str):
|
||||||
HttpUrl(v)
|
raise ValueError("metrics must be a string URL or None")
|
||||||
return v
|
HttpUrl(v)
|
||||||
|
return v
|
||||||
|
|
||||||
|
|
||||||
class ListProvidersResponse(BaseModel):
|
class ListProvidersResponse(BaseModel):
|
||||||
|
|
|
@ -50,7 +50,7 @@ class TestProviderMetrics:
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_provider_with_invalid_metrics_in_config(self):
|
async def test_provider_with_invalid_metrics_in_config(self):
|
||||||
"""Test that invalid metrics in config fails when access /providers."""
|
"""Test invalid metrics in config fails when access /providers."""
|
||||||
run_config = StackRunConfig(
|
run_config = StackRunConfig(
|
||||||
image_name="test_image",
|
image_name="test_image",
|
||||||
providers={
|
providers={
|
||||||
|
@ -69,6 +69,27 @@ class TestProviderMetrics:
|
||||||
with pytest.raises(ValidationError):
|
with pytest.raises(ValidationError):
|
||||||
await provider_impl.list_providers()
|
await provider_impl.list_providers()
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_provider_with_invalid_metrics_in_config2(self):
|
||||||
|
"""Test invalid metrics2 in config fails when access /providers."""
|
||||||
|
run_config = StackRunConfig(
|
||||||
|
image_name="test_image",
|
||||||
|
providers={
|
||||||
|
"inference": [
|
||||||
|
Provider(
|
||||||
|
provider_id="test_provider",
|
||||||
|
provider_type="test_type",
|
||||||
|
config={"url": "http://localhost:8000", "metrics": 123},
|
||||||
|
)
|
||||||
|
]
|
||||||
|
},
|
||||||
|
)
|
||||||
|
provider_config = ProviderImplConfig(run_config=run_config)
|
||||||
|
provider_impl = ProviderImpl(provider_config, {})
|
||||||
|
|
||||||
|
with pytest.raises(ValidationError):
|
||||||
|
await provider_impl.list_providers()
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_provider_without_metrics_in_config(self):
|
async def test_provider_without_metrics_in_config(self):
|
||||||
"""Test provider without metrics in config returns None."""
|
"""Test provider without metrics in config returns None."""
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue