Skip to content

feat: implement Pydantic v2 validation and unit tests for alpha infer…#240

Open
DanFrolov wants to merge 2 commits intoOpenGradient:mainfrom
DanFrolov:refactor/add-pydantic-validation
Open

feat: implement Pydantic v2 validation and unit tests for alpha infer…#240
DanFrolov wants to merge 2 commits intoOpenGradient:mainfrom
DanFrolov:refactor/add-pydantic-validation

Conversation

@DanFrolov
Copy link
Copy Markdown

Overview

Currently, the SDK relies on static type hints for the Alpha.infer method. This PR introduces a runtime validation layer using Pydantic v2 to catch malformed data on the client side.

Changes

  • types.py: Added InferenceRequest schema with:
    • Regex validation for IPFS CIDs (Qm... or ba...).
    • Custom validator to ensure model_input is not empty.
    • model_config for Pydantic v2 compatibility.
  • alpha.py: Integrated InferenceRequest into the infer method.
  • tests/: Added test_inference_validation.py to verify validation logic.

Testing

Verified using pytest:

  • Confirmed invalid CIDs trigger ValidationError.
  • Confirmed empty input dictionaries trigger ValidationError.
  • Confirmed valid requests pass through correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant