e4dcfc49aa
Tests / Import Check (Python 3.13) (push) Has been cancelled
Tests / Import Check (Python 3.14) (push) Has been cancelled
Tests / Python Tests (Python 3.11) (push) Has been cancelled
Tests / Python Tests (Python 3.12) (push) Has been cancelled
Tests / Python Tests (Python 3.14) (push) Has been cancelled
Tests / Test Summary (push) Has been cancelled
Tests / Lint and Format (push) Has been cancelled
Tests / Web Node Tests (push) Has been cancelled
Tests / Import Check (Python 3.11) (push) Has been cancelled
Tests / Import Check (Python 3.12) (push) Has been cancelled
Tests / Python Tests (Python 3.13) (push) Has been cancelled
39 lines
1.2 KiB
Python
39 lines
1.2 KiB
Python
"""Validated request config for the math animator capability."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Any, Literal
|
|
|
|
from pydantic import BaseModel, ConfigDict, Field, ValidationError
|
|
|
|
|
|
class MathAnimatorRequestConfig(BaseModel):
|
|
model_config = ConfigDict(extra="forbid")
|
|
|
|
output_mode: Literal["video", "image"] = "video"
|
|
quality: Literal["low", "medium", "high"] = "medium"
|
|
style_hint: str = Field(default="", max_length=500)
|
|
|
|
|
|
def validate_math_animator_request_config(
|
|
raw_config: dict[str, Any] | None,
|
|
) -> MathAnimatorRequestConfig:
|
|
if raw_config is None:
|
|
return MathAnimatorRequestConfig()
|
|
if not isinstance(raw_config, dict):
|
|
raise ValueError("Math animator config must be an object.")
|
|
try:
|
|
return MathAnimatorRequestConfig.model_validate(raw_config)
|
|
except ValidationError as exc:
|
|
details = "; ".join(
|
|
f"{'.'.join(str(part) for part in error['loc'])}: {error['msg']}"
|
|
for error in exc.errors()
|
|
)
|
|
raise ValueError(f"Invalid math animator config: {details}") from exc
|
|
|
|
|
|
__all__ = [
|
|
"MathAnimatorRequestConfig",
|
|
"validate_math_animator_request_config",
|
|
]
|