This commit is contained in:
Wen Zhou 2025-07-24 21:06:24 +02:00 committed by GitHub
commit beae27975b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 176 additions and 2 deletions

View file

@ -6,7 +6,8 @@
from typing import Any, Protocol, runtime_checkable
from pydantic import BaseModel
from pydantic import BaseModel, Field, HttpUrl, field_validator
from pydantic_core import PydanticCustomError
from llama_stack.providers.datatypes import HealthResponse
from llama_stack.schema_utils import json_schema_type, webmethod
@ -19,6 +20,22 @@ class ProviderInfo(BaseModel):
provider_type: str
config: dict[str, Any]
health: HealthResponse
metrics: str | None = Field(
default=None, description="Endpoint for metrics from providers. Must be a valid HTTP URL if provided."
)
@field_validator("metrics")
@classmethod
def validate_metrics_url(cls, v):
if v is None:
return None
if not isinstance(v, str):
raise ValueError("'metrics' must be a string URL or None")
try:
HttpUrl(v) # Validate the URL
return v
except (PydanticCustomError, ValueError) as e:
raise ValueError(f"'metrics' must be a valid HTTP or HTTPS URL: {str(e)}") from e
class ListProvidersResponse(BaseModel):

View file

@ -51,18 +51,22 @@ class ProviderImpl(Providers):
# Skip providers that are not enabled
if p.provider_id is None:
continue
# Filter out "metrics" to be shown in config duplicated
metrics_url = p.config.get("metrics")
config = {k: v for k, v in p.config.items() if k != "metrics"}
ret.append(
ProviderInfo(
api=api,
provider_id=p.provider_id,
provider_type=p.provider_type,
config=p.config,
config=config,
health=providers_health.get(api, {}).get(
p.provider_id,
HealthResponse(
status=HealthStatus.NOT_IMPLEMENTED, message="Provider does not implement health check"
),
),
metrics=metrics_url,
)
)