Repository: meta-llama/llama-stack
File: llama_stack/core/datatypes.py (Python)

Code before:


class QualifiedModel(BaseModel):
    """A qualified model identifier, consisting of a provider ID and a model ID."""

    provider_id: str
    model_id: str


class VectorStoresConfig(BaseModel):
    """Configuration for vector stores in the stack."""

    default_provider_id: str | None = Field(
        default=None,
        description="ID of the vector_io provider to use as default when multiple providers are available and none is specified.",
    )
    default_embedding_model: QualifiedModel | None = Field(
        default=None,
        description="Default embedding model configuration for vector stores.",
    )


class QuotaPeriod(StrEnum):
    DAY = "day"


class QuotaConfig(BaseModel):
    kvstore: KVStoreReference = Field(description="Config for KV store backend (SQLite only for now)")
    anonymous_max_requests: int = Field(default=100, description="Max requests for unauthenticated clients per period")
    authenticated_max_requests: int = Field(
        default=1000, description="Max requests for authenticated clients per period"
    )
    period: QuotaPeriod = Field(default=QuotaPeriod.DAY, description="Quota period to set")


class CORSConfig(BaseModel):
    allow_origins: list[str] = Field(default_factory=list)
    allow_origin_regex: str | None = Field(default=None)
    allow_methods: list[str] = Field(default=["OPTIONS"])
    allow_headers: list[str] = Field(default_factory=list)
    allow_credentials: bool = Field(default=False)
    expose_headers: list[str] = Field(default_factory=list)
    max_age: int = Field(default=600, ge=0)

    @model_validator(mode="after")
    def validate_credentials_config(self) -> Self:
        if self.allow_credentials and (self.allow_origins == ["*"] or "*" in self.allow_origins):
            raise ValueError("Cannot use wildcard origins with credentials enabled")
        return self



Review comment (suggestion):
is there a reason we didn't follow the pattern from #3818? 

```python
class QualifiedModel(BaseModel):
    """A qualified model identifier, consisting of a provider ID and a model ID."""

    provider_id: str
    model_id: str

class VectorStoresConfig(BaseModel):
    """Configuration for vector stores in the stack."""

    default_provider_id: str | None = Field(
        default=None,
        description="ID of the vector_io provider to use as default when multiple providers are available and none is specified.",
    )
    default_embedding_model: QualifiedModel | None = Field(
        default=None,
        description="Default embedding model configuration for vector stores.",
    )
```

Code after:


class QualifiedModel(BaseModel):
    """A qualified model identifier, consisting of a provider ID and a model ID."""

    provider_id: str
    model_id: str


class VectorStoresConfig(BaseModel):
    """Configuration for vector stores in the stack."""

    default_provider_id: str | None = Field(
        default=None,
        description="ID of the vector_io provider to use as default when multiple providers are available and none is specified.",
    )
    default_embedding_model: QualifiedModel | None = Field(
        default=None,
        description="Default embedding model configuration for vector stores.",
    )


class SafetyConfig(BaseModel):
    """Configuration for default moderations model."""

    default_shield_id: str | None = Field(
        default=None,
        description="ID of the shield to use for when `model` is not specified in the `moderations` API request.",
    )


class QuotaPeriod(StrEnum):
    DAY = "day"


class QuotaConfig(BaseModel):
    kvstore: KVStoreReference = Field(description="Config for KV store backend (SQLite only for now)")
    anonymous_max_requests: int = Field(default=100, description="Max requests for unauthenticated clients per period")
    authenticated_max_requests: int = Field(
        default=1000, description="Max requests for authenticated clients per period"
    )
    period: QuotaPeriod = Field(default=QuotaPeriod.DAY, description="Quota period to set")


class CORSConfig(BaseModel):
    allow_origins: list[str] = Field(default_factory=list)
    allow_origin_regex: str | None = Field(default=None)
    allow_methods: list[str] = Field(default=["OPTIONS"])
    allow_headers: list[str] = Field(default_factory=list)
    allow_credentials: bool = Field(default=False)
    expose_headers: list[str] = Field(default_factory=list)