Spaces:
Sleeping
Sleeping
Download adsp/core/survey/validators.py from thanhnv2323/humanize-text-python: direct link, hf CLI and curl.
- Browser
- Download file 1.32 kB
-
https://huggingface.co/spaces/thanhnv2323/humanize-text-python/resolve/main/adsp/core/survey/validators.py
- Command line
-
hf download hf://spaces/thanhnv2323/humanize-text-python/adsp/core/survey/validators.py
-
curl -L -o validators.py https://huggingface.co/spaces/thanhnv2323/humanize-text-python/resolve/main/adsp/core/survey/validators.py
1.32 kB
| """Validation helpers for survey simulation models.""" | |
| from __future__ import annotations | |
| from typing import Any, Iterable, List, Mapping | |
| from .models import ( | |
| PersonaConfig, | |
| RespondentGroup, | |
| RespondentProfile, | |
| SimulationResult, | |
| Survey, | |
| SurveyResponse, | |
| ) | |
| def _validate_model(model_cls: Any, payload: Any) -> Any: | |
| if hasattr(model_cls, "model_validate"): | |
| return model_cls.model_validate(payload) | |
| return model_cls(**payload) | |
| def validate_survey_definition(payload: Mapping[str, Any]) -> Survey: | |
| return _validate_model(Survey, dict(payload)) | |
| def validate_group_composition(composition: Iterable[Mapping[str, Any]]) -> List[PersonaConfig]: | |
| return [_validate_model(PersonaConfig, dict(item)) for item in composition] | |
| def validate_respondent_profile(payload: Mapping[str, Any]) -> RespondentProfile: | |
| return _validate_model(RespondentProfile, dict(payload)) | |
| def validate_group(payload: Mapping[str, Any]) -> RespondentGroup: | |
| return _validate_model(RespondentGroup, dict(payload)) | |
| def validate_survey_response(payload: Mapping[str, Any]) -> SurveyResponse: | |
| return _validate_model(SurveyResponse, dict(payload)) | |
| def validate_simulation_result(payload: Mapping[str, Any]) -> SimulationResult: | |
| return _validate_model(SimulationResult, dict(payload)) | |