| 100 | |
| 101 | |
| 102 | class TypeChatProgramValidator(TypeChatValidator[JsonProgram]): |
| 103 | def __init__(self): |
| 104 | # TODO: This example should eventually be updated to use Python 3.12 type aliases |
| 105 | # Passing in `JsonProgram` for `py_type` would cause issues because |
| 106 | # Pydantic's `TypeAdapter` ends up trying to eagerly construct an |
| 107 | # anonymous recursive type. Even a NewType does not work here. |
| 108 | # For now, we just pass in `Any` in place of `JsonProgram`. |
| 109 | super().__init__(py_type=cast(type[JsonProgram], Any)) |
| 110 | |
| 111 | @override |
| 112 | def validate_object(self, obj: Any) -> Success[JsonProgram] | Failure: |
| 113 | if "@steps" in obj and isinstance(obj["@steps"], Sequence): |
| 114 | return Success(obj) |
| 115 | else: |
| 116 | return Failure("This is not a valid program. The program must have an array of @steps") |
| 117 | |
| 118 | |
| 119 | |