microsoft / TypeChat

TypeChat is a library that makes it easy to build natural language interfaces using types.
https://microsoft.github.io/TypeChat/
MIT License
8.06k stars 378 forks source link

Raise when TypeScript schema construction produces errors. #202

Closed DanielRosenwasser closed 4 months ago

DanielRosenwasser commented 4 months ago

The current model for TypeChat in Python is to construct a TypeScript schema and use it regardless of if there are issues with the input. This is possible because the translation process was designed to produce an approximation of some TypeScript schema while producing a set of errors.

Surprisingly, our math demo takes advantage of this, providing a Python type which can't be translated into a TS schema. But this still works well enough for the demo!

So by default, failure to construct a schema will now always raise an error; however, TypeChatProgramTranslator now takes an experimental named _raise_on_schema_errors parameter which can be specified as False to opt out of this behavior.