MCPcopy Create free account
hub / github.com/microsoft/TypeChat / TypeChatProgramValidator

Class TypeChatProgramValidator

python/examples/math/program.py:102–116  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

100
101
102class 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

Callers 2

__init__Method · 0.90
mainFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…